@trapi/query
Advanced tools
Comparing version 2.1.0 to 2.1.1
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021-2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021-2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021-2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -54,17 +54,20 @@ * For the full copyright and license information, | ||
let transformed = []; | ||
for (const alias in data) { | ||
if (!data.hasOwnProperty(alias) || typeof alias !== 'string') { | ||
const keys = Object.keys(data); | ||
for (let i = 0; i < keys.length; i++) { | ||
if (!(0, utils_1.hasOwnProperty)(data, keys[i]) || | ||
typeof keys[i] !== 'string') { | ||
continue; | ||
} | ||
const fieldsArr = buildArrayFieldsRepresentation(data[alias]); | ||
if (fieldsArr.length === 0) | ||
const fieldsArr = buildArrayFieldsRepresentation(data[keys[i]]); | ||
if (fieldsArr.length === 0) { | ||
continue; | ||
} | ||
let fields = []; | ||
for (let i = 0; i < fieldsArr.length; i++) { | ||
for (let j = 0; j < fieldsArr.length; j++) { | ||
let operator; | ||
switch (true) { | ||
case fieldsArr[i].substr(0, 1) === type_1.FieldOperator.INCLUDE: | ||
case fieldsArr[j].substring(0, 1) === type_1.FieldOperator.INCLUDE: | ||
operator = type_1.FieldOperator.INCLUDE; | ||
break; | ||
case fieldsArr[i].substr(0, 1) === type_1.FieldOperator.EXCLUDE: | ||
case fieldsArr[j].substring(0, 1) === type_1.FieldOperator.EXCLUDE: | ||
operator = type_1.FieldOperator.EXCLUDE; | ||
@@ -74,21 +77,33 @@ break; | ||
if (operator) | ||
fieldsArr[i] = fieldsArr[i].substr(1); | ||
fields.push(Object.assign({ key: fieldsArr[i] }, (operator ? { value: operator } : {}))); | ||
fieldsArr[j] = fieldsArr[j].substring(1); | ||
fields.push(Object.assign({ key: fieldsArr[j] }, (operator ? { value: operator } : {}))); | ||
} | ||
const allowedDomains = typeof allowedDomainFields !== 'undefined' ? Object.keys(allowedDomainFields) : []; | ||
const targetKey = allowedDomains.length === 1 ? allowedDomains[0] : alias; | ||
const allowedDomains = typeof allowedDomainFields !== 'undefined' ? | ||
Object.keys(allowedDomainFields) : | ||
[]; | ||
const targetKey = allowedDomains.length === 1 ? | ||
allowedDomains[0] : | ||
keys[i]; | ||
// is not default domain && includes are defined? | ||
if (alias !== type_1.DEFAULT_ALIAS_ID && | ||
alias !== options.defaultAlias && | ||
if (keys[i] !== type_1.DEFAULT_ALIAS_ID && | ||
keys[i] !== options.defaultAlias && | ||
typeof options.relations !== 'undefined') { | ||
const includesMatched = options.relations.filter((include) => include.value === alias); | ||
if (includesMatched.length === 0) { | ||
let index = -1; | ||
for (let j = 0; j < options.relations.length; j++) { | ||
if (options.relations[j].value === keys[i]) { | ||
index = j; | ||
break; | ||
} | ||
} | ||
if (index === -1) { | ||
continue; | ||
} | ||
} | ||
for (let j = 0; j < fields.length; j++) { | ||
const fullKey = `${keys[i]}.${fields[j].key}`; | ||
fields[j] = Object.assign(Object.assign(Object.assign({}, (targetKey && targetKey !== type_1.DEFAULT_ALIAS_ID ? { alias: targetKey } : {})), fields[j]), { key: (0, utils_1.hasOwnProperty)(options.aliasMapping, fullKey) ? | ||
options.aliasMapping[fullKey].split('.').pop() : | ||
fields[j].key }); | ||
} | ||
fields = fields | ||
.map((field) => { | ||
const fullKey = `${alias}.${field.key}`; | ||
return Object.assign(Object.assign(Object.assign({}, (targetKey && targetKey !== type_1.DEFAULT_ALIAS_ID ? { alias: targetKey } : {})), field), { key: options.aliasMapping.hasOwnProperty(fullKey) ? options.aliasMapping[fullKey].split('.').pop() : field.key }); | ||
}) | ||
.filter((field) => { | ||
@@ -105,8 +120,2 @@ if (typeof allowedDomainFields === 'undefined') { | ||
} | ||
const keys = Object.keys(transformed); | ||
if (keys.length === 1) { | ||
if (keys[0] === type_1.DEFAULT_ALIAS_ID) { | ||
return transformed[keys[0]]; | ||
} | ||
} | ||
return transformed; | ||
@@ -113,0 +122,0 @@ } |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2022. | ||
* Copyright (c) 2022-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +9,0 @@ exports.isFilterOperatorConfig = exports.determineFilterOperatorLabelsByValue = void 0; |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +9,0 @@ exports.parseQueryPagination = void 0; |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +9,0 @@ exports.buildQueryRelations = void 0; |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -24,3 +24,3 @@ * For the full copyright and license information, | ||
if (options.aliasMapping && | ||
options.aliasMapping.hasOwnProperty(value)) { | ||
(0, utils_1.hasOwnProperty)(options.aliasMapping, value)) { | ||
value = options.aliasMapping[value]; | ||
@@ -36,3 +36,3 @@ } | ||
if (options.aliasMapping && | ||
options.aliasMapping.hasOwnProperty(value)) { | ||
(0, utils_1.hasOwnProperty)(options.aliasMapping, value)) { | ||
value = options.aliasMapping[value]; | ||
@@ -79,3 +79,3 @@ } | ||
.map((item) => { | ||
if (options.aliasMapping.hasOwnProperty(item)) { | ||
if ((0, utils_1.hasOwnProperty)(options.aliasMapping, item)) { | ||
item = options.aliasMapping[item]; | ||
@@ -107,8 +107,17 @@ } | ||
return items | ||
.map((relation) => ({ | ||
key: relation.includes('.') ? relation.split('.').slice(-2).join('.') : (options.defaultAlias ? `${options.defaultAlias}.${relation}` : relation), | ||
value: relation.split('.').pop(), | ||
})); | ||
.map((relation) => { | ||
let key; | ||
if (relation.includes('.')) { | ||
key = relation.split('.').slice(-2).join('.'); | ||
} | ||
else { | ||
key = options.defaultAlias ? `${options.defaultAlias}.${relation}` : relation; | ||
} | ||
return { | ||
key, | ||
value: relation.split('.').pop(), | ||
}; | ||
}); | ||
} | ||
exports.parseQueryRelations = parseQueryRelations; | ||
//# sourceMappingURL=parse.js.map |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +9,0 @@ exports.buildQuerySort = void 0; |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -41,18 +41,19 @@ * For the full copyright and license information, | ||
let parts = []; | ||
if (prototype === '[object String]') { | ||
if (typeof data === 'string') { | ||
parts = data.split(','); | ||
} | ||
if (prototype === '[object Array]') { | ||
if (Array.isArray(data)) { | ||
parts = data.filter((item) => typeof item === 'string'); | ||
} | ||
if (prototype === '[object Object]') { | ||
const ob = data; | ||
for (const key in ob) { | ||
if (typeof data === 'object') { | ||
const keys = Object.keys(data); | ||
for (let i = 0; i < keys.length; i++) { | ||
/* istanbul ignore next */ | ||
if (!ob.hasOwnProperty(key) || | ||
typeof key !== 'string' || | ||
typeof ob[key] !== 'string') | ||
if (!(0, utils_1.hasOwnProperty)(data, keys[i]) || | ||
typeof keys[i] !== 'string' || | ||
typeof data[keys[i]] !== 'string') | ||
continue; | ||
const fieldPrefix = ob[key].toLowerCase() === 'desc' ? '-' : ''; | ||
parts.push(fieldPrefix + key); | ||
const fieldPrefix = data[keys[i]] | ||
.toLowerCase() === 'desc' ? '-' : ''; | ||
parts.push(fieldPrefix + keys[i]); | ||
} | ||
@@ -63,8 +64,8 @@ } | ||
let direction = type_1.SortDirection.ASC; | ||
if (parts[i].substr(0, 1) === '-') { | ||
if (parts[i].substring(0, 1) === '-') { | ||
direction = type_1.SortDirection.DESC; | ||
parts[i] = parts[i].substr(1); | ||
parts[i] = parts[i].substring(1); | ||
} | ||
let key = parts[i]; | ||
if (options.aliasMapping.hasOwnProperty(key)) { | ||
if ((0, utils_1.hasOwnProperty)(options.aliasMapping, key)) { | ||
key = options.aliasMapping[key]; | ||
@@ -83,11 +84,11 @@ } | ||
} | ||
const alias = typeof fieldDetails.path === 'undefined' && | ||
typeof fieldDetails.alias === 'undefined' ? | ||
(options.defaultAlias ? | ||
options.defaultAlias : | ||
undefined) : | ||
fieldDetails.alias; | ||
let { alias } = fieldDetails; | ||
if (typeof fieldDetails.path === 'undefined' && | ||
typeof fieldDetails.alias === 'undefined') { | ||
alias = options.defaultAlias; | ||
} | ||
items[keyWithAlias] = Object.assign(Object.assign({ key: fieldDetails.name }, (alias ? { alias } : {})), { value: direction }); | ||
} | ||
if (isMultiDimensionalArray(options.allowed)) { | ||
// eslint-disable-next-line no-labels,no-restricted-syntax | ||
outerLoop: for (let i = 0; i < options.allowed.length; i++) { | ||
@@ -97,8 +98,14 @@ const temp = []; | ||
const keyWithAlias = options.allowed[i][j]; | ||
const key = keyWithAlias.includes('.') ? keyWithAlias.split('.').pop() : keyWithAlias; | ||
if (items.hasOwnProperty(key) || items.hasOwnProperty(keyWithAlias)) { | ||
const item = items.hasOwnProperty(key) ? items[key] : items[keyWithAlias]; | ||
const key = keyWithAlias.includes('.') ? | ||
keyWithAlias.split('.').pop() : | ||
keyWithAlias; | ||
if ((0, utils_1.hasOwnProperty)(items, key) || | ||
(0, utils_1.hasOwnProperty)(items, keyWithAlias)) { | ||
const item = (0, utils_1.hasOwnProperty)(items, key) ? | ||
items[key] : | ||
items[keyWithAlias]; | ||
temp.push(item); | ||
} | ||
else { | ||
// eslint-disable-next-line no-labels | ||
continue outerLoop; | ||
@@ -105,0 +112,0 @@ } |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2022. | ||
* Copyright (c) 2022-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2022. | ||
* Copyright (c) 2022-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021-2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +9,0 @@ exports.getFieldDetails = void 0; |
"use strict"; | ||
/* | ||
* Copyright (c) 2021-2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021-2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2022. | ||
* Copyright (c) 2022-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
"use strict"; | ||
/* | ||
* Copyright (c) 2021-2021. | ||
* Copyright (c) 2021-2022. | ||
* Author Peter Placzek (tada5hi) | ||
@@ -5,0 +5,0 @@ * For the full copyright and license information, |
{ | ||
"name": "@trapi/query", | ||
"version": "2.1.0", | ||
"description": "An tiny library which provides utility types/functions for request and response query handling.", | ||
"version": "2.1.1", | ||
"description": "A tiny library which provides utility types/functions for request and response query handling.", | ||
"main": "./dist/index.js", | ||
@@ -57,6 +57,9 @@ "typings": "dist/index.d.ts", | ||
}, | ||
"dependencies": { | ||
"minimatch": "^5.0.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "d17ff94037efee8f2eac5bfab176da50de284d56" | ||
"gitHead": "502f3d8795041a84fbdac49851cc7b6166a92aa4" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
166544
1862
1
+ Addedminimatch@^5.0.1
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedminimatch@5.1.6(transitive)