json-fs-query 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/jsonFsQuery.js +520 -363
- 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 +5 -1
- package/dist/data/introspect/policies/foreignKeyExists.min.js +1 -1
- package/dist/data/introspect/policies/hasDependents.js +3 -1
- package/dist/data/introspect/policies/hasDependents.min.js +1 -1
- package/dist/data/introspect/policies/keyGenerate.js +16 -16
- package/dist/data/introspect/policies/keyUnique.js +5 -1
- package/dist/data/introspect/policies/keyUnique.min.js +1 -1
- 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 +2 -1
- package/dist/data/queries/deleteEntity.min.js +1 -1
- package/dist/data/queries/groupBy.js +21 -21
- package/dist/data/queries/insertEntity.js +2 -1
- package/dist/data/queries/insertEntity.min.js +1 -1
- 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 +3 -0
- package/dist/data/queries/updateEntity.js +14 -10
- package/dist/data/queries/updateEntity.min.js +1 -1
- package/dist/data/queries/where.d.ts +7 -6
- package/dist/data/queries/where.js +18 -6
- package/dist/data/queries/where.min.js +1 -1
- package/dist/data/utilities/compareAs.d.ts +20 -0
- package/dist/data/utilities/compareAs.js +58 -0
- package/dist/data/utilities/compareAs.min.js +1 -0
- 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/fieldType.d.ts +16 -0
- package/dist/data/utilities/fieldType.js +23 -0
- package/dist/data/utilities/fieldType.min.js +1 -0
- package/dist/data/utilities/getConditionIndexedList.js +2 -1
- package/dist/data/utilities/getConditionIndexedList.min.js +1 -1
- package/dist/data/utilities/getJoinIndexedList.js +75 -75
- package/dist/data/utilities/getMatchingIndexes.js +27 -27
- package/dist/data/utilities/matchIndexedJoins.js +3 -1
- package/dist/data/utilities/matchIndexedJoins.min.js +1 -1
- package/dist/data/utilities/mergeJoin.js +5 -1
- package/dist/data/utilities/mergeJoin.min.js +1 -1
- package/dist/data/utilities/parsers/findCommand.js +24 -24
- package/dist/data/utilities/parsers/findConditions.d.ts +15 -14
- 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.d.ts +14 -13
- package/dist/data/utilities/removeFromIndex.js +4 -2
- package/dist/data/utilities/removeFromIndex.min.js +1 -1
- 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 +26 -0
- package/dist/data/utilities/runQuery.min.js +1 -1
- package/dist/data/utilities/updateIndex.d.ts +17 -16
- package/dist/data/utilities/updateIndex.js +4 -2
- package/dist/data/utilities/updateIndex.min.js +1 -1
- package/dist/data/utilities/useJoinClause.js +8 -2
- package/dist/data/utilities/useJoinClause.min.js +1 -1
- package/dist/index.js +41 -41
- package/package.json +14 -5
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findLimit = void 0;
|
|
7
|
-
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
-
const limitMatch = /limit\s*(\d+)/i;
|
|
9
|
-
/**
|
|
10
|
-
* Extract the limit clauses from the query.
|
|
11
|
-
* @param parsed
|
|
12
|
-
* @param query
|
|
13
|
-
*/
|
|
14
|
-
const findLimit = (parsed, query) => {
|
|
15
|
-
const limitFound = query.match(limitMatch);
|
|
16
|
-
if (limitFound) {
|
|
17
|
-
parsed['limit'] = limitFound ? parseInt(limitFound[1]) : undefined;
|
|
18
|
-
return (0, _removeFromQuery.removeFromQuery)(limitFound[0], query);
|
|
19
|
-
}
|
|
20
|
-
return query;
|
|
21
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findLimit = void 0;
|
|
7
|
+
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
+
const limitMatch = /limit\s*(\d+)/i;
|
|
9
|
+
/**
|
|
10
|
+
* Extract the limit clauses from the query.
|
|
11
|
+
* @param parsed
|
|
12
|
+
* @param query
|
|
13
|
+
*/
|
|
14
|
+
const findLimit = (parsed, query) => {
|
|
15
|
+
const limitFound = query.match(limitMatch);
|
|
16
|
+
if (limitFound) {
|
|
17
|
+
parsed['limit'] = limitFound ? parseInt(limitFound[1]) : undefined;
|
|
18
|
+
return (0, _removeFromQuery.removeFromQuery)(limitFound[0], query);
|
|
19
|
+
}
|
|
20
|
+
return query;
|
|
21
|
+
};
|
|
22
22
|
exports.findLimit = findLimit;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findMergeJoins = void 0;
|
|
7
|
-
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
-
const mergeJoinMatch = /(and)?\s*merge\s+([a-z0-9_-]+\.[a-z0-9_-]+)\s+with\s+([a-z0-9_-]+\.[a-z0-9_-]+)/ig;
|
|
9
|
-
/**
|
|
10
|
-
* Extract merge-join clauses from the query.
|
|
11
|
-
* @param parsed
|
|
12
|
-
* @param query
|
|
13
|
-
*/
|
|
14
|
-
const findMergeJoins = (parsed, query) => {
|
|
15
|
-
const mergeJoinsFound = query.matchAll(mergeJoinMatch);
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
for (const mergeJoin of mergeJoinsFound) {
|
|
18
|
-
parsed['mergeJoins'].push({
|
|
19
|
-
propertyA: mergeJoin[2],
|
|
20
|
-
propertyB: mergeJoin[3]
|
|
21
|
-
});
|
|
22
|
-
query = (0, _removeFromQuery.removeFromQuery)(mergeJoin[0].trim(), query);
|
|
23
|
-
}
|
|
24
|
-
return query;
|
|
25
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findMergeJoins = void 0;
|
|
7
|
+
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
+
const mergeJoinMatch = /(and)?\s*merge\s+([a-z0-9_-]+\.[a-z0-9_-]+)\s+with\s+([a-z0-9_-]+\.[a-z0-9_-]+)/ig;
|
|
9
|
+
/**
|
|
10
|
+
* Extract merge-join clauses from the query.
|
|
11
|
+
* @param parsed
|
|
12
|
+
* @param query
|
|
13
|
+
*/
|
|
14
|
+
const findMergeJoins = (parsed, query) => {
|
|
15
|
+
const mergeJoinsFound = query.matchAll(mergeJoinMatch);
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
for (const mergeJoin of mergeJoinsFound) {
|
|
18
|
+
parsed['mergeJoins'].push({
|
|
19
|
+
propertyA: mergeJoin[2],
|
|
20
|
+
propertyB: mergeJoin[3]
|
|
21
|
+
});
|
|
22
|
+
query = (0, _removeFromQuery.removeFromQuery)(mergeJoin[0].trim(), query);
|
|
23
|
+
}
|
|
24
|
+
return query;
|
|
25
|
+
};
|
|
26
26
|
exports.findMergeJoins = findMergeJoins;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findOffset = void 0;
|
|
7
|
-
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
-
const offsetMatch = /offset\s*(\d+)/i;
|
|
9
|
-
/**
|
|
10
|
-
* Extract the offset clauses from the query.
|
|
11
|
-
* @param parsed
|
|
12
|
-
* @param query
|
|
13
|
-
*/
|
|
14
|
-
const findOffset = (parsed, query) => {
|
|
15
|
-
const offsetFound = query.match(offsetMatch);
|
|
16
|
-
if (offsetFound) {
|
|
17
|
-
parsed['offset'] = offsetFound ? parseInt(offsetFound[1]) : undefined;
|
|
18
|
-
return (0, _removeFromQuery.removeFromQuery)(offsetFound[0], query);
|
|
19
|
-
}
|
|
20
|
-
return query;
|
|
21
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findOffset = void 0;
|
|
7
|
+
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
+
const offsetMatch = /offset\s*(\d+)/i;
|
|
9
|
+
/**
|
|
10
|
+
* Extract the offset clauses from the query.
|
|
11
|
+
* @param parsed
|
|
12
|
+
* @param query
|
|
13
|
+
*/
|
|
14
|
+
const findOffset = (parsed, query) => {
|
|
15
|
+
const offsetFound = query.match(offsetMatch);
|
|
16
|
+
if (offsetFound) {
|
|
17
|
+
parsed['offset'] = offsetFound ? parseInt(offsetFound[1]) : undefined;
|
|
18
|
+
return (0, _removeFromQuery.removeFromQuery)(offsetFound[0], query);
|
|
19
|
+
}
|
|
20
|
+
return query;
|
|
21
|
+
};
|
|
22
22
|
exports.findOffset = findOffset;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findSelects = void 0;
|
|
7
|
-
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
-
const selectClausesMatch = /select\s+([a-z0-9=._-]+\s*(as\s+)?([a-z0-9_-]+)?)+\s*(,\s*[a-z0-9=._-]+\s*(as\s*[a-z0-9_-]+)?)*/i;
|
|
9
|
-
const selectClauseMatch = /(select)?\s*,?\s*([a-z0-9=._-]+)\s*(as\s+)?([a-z0-9_-]+)?/ig;
|
|
10
|
-
/**
|
|
11
|
-
* Extract select clauses from the query.
|
|
12
|
-
* @param parsed
|
|
13
|
-
* @param query
|
|
14
|
-
*/
|
|
15
|
-
const findSelects = (parsed, query) => {
|
|
16
|
-
const selectsFound = query.match(selectClausesMatch);
|
|
17
|
-
if (selectsFound) {
|
|
18
|
-
const selectClausesFound = selectsFound[0].matchAll(selectClauseMatch);
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
for (const selectClause of selectClausesFound) {
|
|
21
|
-
parsed['selectClauses'].push({
|
|
22
|
-
property: selectClause[2],
|
|
23
|
-
alias: selectClause[4]
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return (0, _removeFromQuery.removeFromQuery)(selectsFound[0], query);
|
|
27
|
-
}
|
|
28
|
-
return query;
|
|
29
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findSelects = void 0;
|
|
7
|
+
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
+
const selectClausesMatch = /select\s+([a-z0-9=._-]+\s*(as\s+)?([a-z0-9_-]+)?)+\s*(,\s*[a-z0-9=._-]+\s*(as\s*[a-z0-9_-]+)?)*/i;
|
|
9
|
+
const selectClauseMatch = /(select)?\s*,?\s*([a-z0-9=._-]+)\s*(as\s+)?([a-z0-9_-]+)?/ig;
|
|
10
|
+
/**
|
|
11
|
+
* Extract select clauses from the query.
|
|
12
|
+
* @param parsed
|
|
13
|
+
* @param query
|
|
14
|
+
*/
|
|
15
|
+
const findSelects = (parsed, query) => {
|
|
16
|
+
const selectsFound = query.match(selectClausesMatch);
|
|
17
|
+
if (selectsFound) {
|
|
18
|
+
const selectClausesFound = selectsFound[0].matchAll(selectClauseMatch);
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
for (const selectClause of selectClausesFound) {
|
|
21
|
+
parsed['selectClauses'].push({
|
|
22
|
+
property: selectClause[2],
|
|
23
|
+
alias: selectClause[4]
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return (0, _removeFromQuery.removeFromQuery)(selectsFound[0], query);
|
|
27
|
+
}
|
|
28
|
+
return query;
|
|
29
|
+
};
|
|
30
30
|
exports.findSelects = findSelects;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findSortClauses = void 0;
|
|
7
|
-
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
-
const sortMatch = /sort\s+([a-z0-9._-]+\s*(asc|desc)?)+\s*(,\s*[a-z0-9._-]+\s*(asc|desc)?)*/i;
|
|
9
|
-
const sortRuleMatch = /(sort)?\s*,?\s*([a-z0-9._-]+)\s*(asc|desc)?/ig;
|
|
10
|
-
/**
|
|
11
|
-
* Extract sort clauses from the query.
|
|
12
|
-
* @param parsed
|
|
13
|
-
* @param query
|
|
14
|
-
*/
|
|
15
|
-
const findSortClauses = (parsed, query) => {
|
|
16
|
-
const sortFound = query.match(sortMatch);
|
|
17
|
-
if (sortFound) {
|
|
18
|
-
const sortRulesFound = sortFound[0].matchAll(sortRuleMatch);
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
for (const sortClause of sortRulesFound) {
|
|
21
|
-
parsed['sortClauses'].push({
|
|
22
|
-
property: sortClause[2],
|
|
23
|
-
direction: sortClause[3] || 'asc'
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return (0, _removeFromQuery.removeFromQuery)(sortFound[0], query);
|
|
27
|
-
}
|
|
28
|
-
return query;
|
|
29
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findSortClauses = void 0;
|
|
7
|
+
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
+
const sortMatch = /sort\s+([a-z0-9._-]+\s*(asc|desc)?)+\s*(,\s*[a-z0-9._-]+\s*(asc|desc)?)*/i;
|
|
9
|
+
const sortRuleMatch = /(sort)?\s*,?\s*([a-z0-9._-]+)\s*(asc|desc)?/ig;
|
|
10
|
+
/**
|
|
11
|
+
* Extract sort clauses from the query.
|
|
12
|
+
* @param parsed
|
|
13
|
+
* @param query
|
|
14
|
+
*/
|
|
15
|
+
const findSortClauses = (parsed, query) => {
|
|
16
|
+
const sortFound = query.match(sortMatch);
|
|
17
|
+
if (sortFound) {
|
|
18
|
+
const sortRulesFound = sortFound[0].matchAll(sortRuleMatch);
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
for (const sortClause of sortRulesFound) {
|
|
21
|
+
parsed['sortClauses'].push({
|
|
22
|
+
property: sortClause[2],
|
|
23
|
+
direction: sortClause[3] || 'asc'
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return (0, _removeFromQuery.removeFromQuery)(sortFound[0], query);
|
|
27
|
+
}
|
|
28
|
+
return query;
|
|
29
|
+
};
|
|
30
30
|
exports.findSortClauses = findSortClauses;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findUpdateValues = void 0;
|
|
7
|
-
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
-
var _parseLiteralValue = require("./parseLiteralValue");
|
|
9
|
-
const literal = '(?:["\'][^"\']*[\'"]|[0-9]+|\\[.*?]|null|true|false)';
|
|
10
|
-
const setClauseMatch = new RegExp(`(set)\\s+([a-z0-9_-]+\\s*=\\s*${literal}(?:\\s*,\\s*[a-z0-9_-]+\\s*=\\s*${literal})*)`, 'i');
|
|
11
|
-
const assignmentMatch = /([a-z0-9_-]+)\s*=\s*(["'](.*?)['"]|([0-9]+)|(\[.*?])|(null)|(true)|(false))/ig;
|
|
12
|
-
/**
|
|
13
|
-
* Extract an update's "set field = value, field2 = value2" clause from the query. Uses a two-pass
|
|
14
|
-
* match, unlike the other parsers here: the set clause's own boundary is found first (so it can
|
|
15
|
-
* be removed from the query as a whole, and so the comma-separated list doesn't get confused with
|
|
16
|
-
* anything that follows, like a where clause), then each individual assignment is parsed out of
|
|
17
|
-
* that captured substring.
|
|
18
|
-
* @param parsed
|
|
19
|
-
* @param query
|
|
20
|
-
*/
|
|
21
|
-
const findUpdateValues = (parsed, query) => {
|
|
22
|
-
const clauseFound = query.match(setClauseMatch);
|
|
23
|
-
parsed['updateValues'] = {};
|
|
24
|
-
if (!clauseFound) {
|
|
25
|
-
return query;
|
|
26
|
-
}
|
|
27
|
-
const assignmentsFound = clauseFound[2].matchAll(assignmentMatch);
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
for (const assignment of assignmentsFound) {
|
|
30
|
-
parsed['updateValues'][assignment[1]] = (0, _parseLiteralValue.parseLiteralValue)(assignment, 3);
|
|
31
|
-
}
|
|
32
|
-
return (0, _removeFromQuery.removeFromQuery)(clauseFound[0], query);
|
|
33
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findUpdateValues = void 0;
|
|
7
|
+
var _removeFromQuery = require("./removeFromQuery");
|
|
8
|
+
var _parseLiteralValue = require("./parseLiteralValue");
|
|
9
|
+
const literal = '(?:["\'][^"\']*[\'"]|[0-9]+|\\[.*?]|null|true|false)';
|
|
10
|
+
const setClauseMatch = new RegExp(`(set)\\s+([a-z0-9_-]+\\s*=\\s*${literal}(?:\\s*,\\s*[a-z0-9_-]+\\s*=\\s*${literal})*)`, 'i');
|
|
11
|
+
const assignmentMatch = /([a-z0-9_-]+)\s*=\s*(["'](.*?)['"]|([0-9]+)|(\[.*?])|(null)|(true)|(false))/ig;
|
|
12
|
+
/**
|
|
13
|
+
* Extract an update's "set field = value, field2 = value2" clause from the query. Uses a two-pass
|
|
14
|
+
* match, unlike the other parsers here: the set clause's own boundary is found first (so it can
|
|
15
|
+
* be removed from the query as a whole, and so the comma-separated list doesn't get confused with
|
|
16
|
+
* anything that follows, like a where clause), then each individual assignment is parsed out of
|
|
17
|
+
* that captured substring.
|
|
18
|
+
* @param parsed
|
|
19
|
+
* @param query
|
|
20
|
+
*/
|
|
21
|
+
const findUpdateValues = (parsed, query) => {
|
|
22
|
+
const clauseFound = query.match(setClauseMatch);
|
|
23
|
+
parsed['updateValues'] = {};
|
|
24
|
+
if (!clauseFound) {
|
|
25
|
+
return query;
|
|
26
|
+
}
|
|
27
|
+
const assignmentsFound = clauseFound[2].matchAll(assignmentMatch);
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
for (const assignment of assignmentsFound) {
|
|
30
|
+
parsed['updateValues'][assignment[1]] = (0, _parseLiteralValue.parseLiteralValue)(assignment, 3);
|
|
31
|
+
}
|
|
32
|
+
return (0, _removeFromQuery.removeFromQuery)(clauseFound[0], query);
|
|
33
|
+
};
|
|
34
34
|
exports.findUpdateValues = findUpdateValues;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isEntityProperty = void 0;
|
|
7
|
-
const isEntityProperty = property => /^[a-z0-9_-]+\.([a-z0-9_-]+)$/i.test(property);
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isEntityProperty = void 0;
|
|
7
|
+
const isEntityProperty = property => /^[a-z0-9_-]+\.([a-z0-9_-]+)$/i.test(property);
|
|
8
8
|
exports.isEntityProperty = isEntityProperty;
|
|
@@ -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;
|