Comparing version 0.0.3 to 0.0.4
@@ -15,1 +15,2 @@ export declare enum Parameter { | ||
} | ||
export declare const DEFAULT_ALIAS_ID = "__DEFAULT__"; |
@@ -9,3 +9,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.URLParameter = exports.Parameter = void 0; | ||
exports.DEFAULT_ALIAS_ID = exports.URLParameter = exports.Parameter = void 0; | ||
// ----------------------------------------------------------- | ||
@@ -29,2 +29,4 @@ var Parameter; | ||
})(URLParameter = exports.URLParameter || (exports.URLParameter = {})); | ||
// ----------------------------------------------------------- | ||
exports.DEFAULT_ALIAS_ID = '__DEFAULT__'; | ||
//# sourceMappingURL=constants.js.map |
@@ -1,2 +0,1 @@ | ||
export declare const DEFAULT_ALIAS_ID = "__DEFAULT__"; | ||
export declare enum FieldOperator { | ||
@@ -3,0 +2,0 @@ INCLUDE = "+", |
@@ -9,4 +9,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FieldOperator = exports.DEFAULT_ALIAS_ID = void 0; | ||
exports.DEFAULT_ALIAS_ID = '__DEFAULT__'; | ||
exports.FieldOperator = void 0; | ||
var FieldOperator; | ||
@@ -13,0 +12,0 @@ (function (FieldOperator) { |
import { FieldsParseOptions, FieldsParseOutput } from './type'; | ||
export declare function replaceRecordKey(record: Record<string, any>, key: string, newKey: string): Record<string, any>; | ||
export declare function parseQueryFields(data: unknown, options?: FieldsParseOptions): FieldsParseOutput; |
@@ -9,37 +9,53 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseQueryFields = void 0; | ||
exports.parseQueryFields = exports.replaceRecordKey = void 0; | ||
const utils_1 = require("../../utils"); | ||
const constants_1 = require("./constants"); | ||
const utils_2 = require("./utils"); | ||
const constants_1 = require("../../constants"); | ||
// -------------------------------------------------- | ||
function isRelationIncluded(key, options) { | ||
// is not default domain && includes are defined? | ||
if (key !== constants_1.DEFAULT_ALIAS_ID && | ||
key !== options.defaultAlias && | ||
typeof options.relations !== 'undefined') { | ||
let index = -1; | ||
for (let j = 0; j < options.relations.length; j++) { | ||
if (options.relations[j].value === key) { | ||
index = j; | ||
break; | ||
} | ||
} | ||
if (index === -1) { | ||
return false; | ||
} | ||
function buildReverseRecord(record) { | ||
const keys = Object.keys(record); | ||
const output = {}; | ||
for (let i = 0; i < keys.length; i++) { | ||
output[record[keys[i]]] = keys[i]; | ||
} | ||
return true; | ||
return output; | ||
} | ||
function replaceRecordKey(record, key, newKey) { | ||
if ((0, utils_1.hasOwnProperty)(record, key)) { | ||
const value = record[key]; | ||
delete record[key]; | ||
record[newKey] = value; | ||
} | ||
return record; | ||
} | ||
exports.replaceRecordKey = replaceRecordKey; | ||
function parseQueryFields(data, options) { | ||
var _a; | ||
options !== null && options !== void 0 ? options : (options = {}); | ||
const defaultDomainFields = (0, utils_2.buildFieldDomainRecords)(options.default, options.defaultAlias); | ||
const defaultDomainKeys = Object.keys(defaultDomainFields); | ||
const allowedDomainFields = (0, utils_2.mergeFieldsDomainRecords)((0, utils_2.buildFieldDomainRecords)(options.allowed, options.defaultAlias), Object.assign({}, defaultDomainFields)); | ||
const allowedDomainKeys = Object.keys(allowedDomainFields); | ||
const defaultDomainFields = (0, utils_2.buildFieldDomainRecords)(options.default); | ||
const domainFields = (0, utils_2.mergeFieldsDomainRecords)((0, utils_2.buildFieldDomainRecords)(options.allowed), Object.assign({}, defaultDomainFields)); | ||
let domainKeys = Object.keys(domainFields); | ||
// If it is an empty array nothing is allowed | ||
if (allowedDomainKeys.length === 0) { | ||
if (domainKeys.length === 0) { | ||
return []; | ||
} | ||
(_a = options.aliasMapping) !== null && _a !== void 0 ? _a : (options.aliasMapping = {}); | ||
if (options.defaultAlias) { | ||
if ((0, utils_1.hasOwnProperty)(defaultDomainFields, constants_1.DEFAULT_ALIAS_ID)) { | ||
replaceRecordKey(defaultDomainFields, constants_1.DEFAULT_ALIAS_ID, options.defaultAlias); | ||
} | ||
if ((0, utils_1.hasOwnProperty)(domainFields, constants_1.DEFAULT_ALIAS_ID)) { | ||
replaceRecordKey(domainFields, constants_1.DEFAULT_ALIAS_ID, options.defaultAlias); | ||
} | ||
} | ||
domainKeys = Object.keys(domainFields); | ||
let defaultAlias; | ||
if (domainKeys.length === 1 && | ||
!options.defaultAlias) { | ||
// eslint-disable-next-line prefer-destructuring | ||
defaultAlias = domainKeys[0]; | ||
} | ||
else { | ||
defaultAlias = options.defaultAlias || constants_1.DEFAULT_ALIAS_ID; | ||
} | ||
options.defaultAlias = defaultAlias; | ||
const prototype = Object.prototype.toString.call(data); | ||
@@ -49,127 +65,69 @@ if (prototype !== '[object Object]' && | ||
prototype !== '[object String]') { | ||
return []; | ||
data = { [defaultAlias]: [] }; | ||
} | ||
if (prototype === '[object String]') { | ||
data = { [constants_1.DEFAULT_ALIAS_ID]: data }; | ||
data = { [defaultAlias]: data }; | ||
} | ||
if (prototype === '[object Array]') { | ||
data = { [constants_1.DEFAULT_ALIAS_ID]: data }; | ||
data = { [defaultAlias]: data }; | ||
} | ||
let transformed = []; | ||
const domainKeys = Object.keys(data); | ||
const processedDomainKeys = []; | ||
(_a = options.aliasMapping) !== null && _a !== void 0 ? _a : (options.aliasMapping = {}); | ||
const reverseAliasMapping = buildReverseRecord(options.aliasMapping); | ||
const output = []; | ||
for (let i = 0; i < domainKeys.length; i++) { | ||
if (!(0, utils_1.hasOwnProperty)(data, domainKeys[i]) || | ||
typeof domainKeys[i] !== 'string') { | ||
const domainKey = domainKeys[i]; | ||
if (!(0, utils_1.isAllowedByRelations)({ alias: domainKey }, options.relations, options.defaultAlias)) { | ||
continue; | ||
} | ||
let domainKey = domainKeys[i]; | ||
let output = []; | ||
const fields = (0, utils_2.parseFieldsInput)(data[domainKey]); | ||
domainKey = (0, utils_1.hasOwnProperty)(options.aliasMapping, domainKeys[i]) ? | ||
options.aliasMapping[domainKey] : | ||
domainKey; | ||
if (!isRelationIncluded(domainKey, options)) { | ||
continue; | ||
let fields = []; | ||
if ((0, utils_1.hasOwnProperty)(data, domainKey)) { | ||
fields = (0, utils_2.parseFieldsInput)(data[domainKey]); | ||
} | ||
if (domainKey === constants_1.DEFAULT_ALIAS_ID) { | ||
if (options.defaultAlias) { | ||
domainKey = options.defaultAlias; | ||
else if ((0, utils_1.hasOwnProperty)(reverseAliasMapping, domainKey)) { | ||
if ((0, utils_1.hasOwnProperty)(data, reverseAliasMapping[domainKey])) { | ||
fields = (0, utils_2.parseFieldsInput)(data[reverseAliasMapping[domainKey]]); | ||
} | ||
else { | ||
domainKey = allowedDomainKeys.length === 1 ? | ||
allowedDomainKeys[0] : | ||
domainKey; | ||
} | ||
} | ||
if (fields.length === 0 && | ||
!(0, utils_1.hasOwnProperty)(defaultDomainFields, domainKey)) { | ||
continue; | ||
} | ||
let transformed = { | ||
default: [], | ||
included: [], | ||
excluded: [], | ||
}; | ||
if (fields.length > 0) { | ||
const fieldsInputTransformed = (0, utils_2.transformFieldsInput)(fields); | ||
if (fieldsInputTransformed.default.length === 0 && | ||
(0, utils_1.hasOwnProperty)(defaultDomainFields, domainKey)) { | ||
fieldsInputTransformed.default = defaultDomainFields[domainKey]; | ||
for (let j = 0; j < fields.length; j++) { | ||
fields[j] = (0, utils_1.getNameByAliasMapping)((0, utils_1.buildFieldWithAlias)({ name: fields[j], alias: domainKey }), options.aliasMapping, true); | ||
} | ||
if (fieldsInputTransformed.default.length > 0) { | ||
fieldsInputTransformed.default = Array.from(new Set([...fieldsInputTransformed.default, ...fieldsInputTransformed.included])); | ||
for (let j = 0; j < fieldsInputTransformed.excluded.length; j++) { | ||
const index = fieldsInputTransformed.default.indexOf(fieldsInputTransformed.excluded[j]); | ||
if (index !== -1) { | ||
fieldsInputTransformed.default.splice(index, 1); | ||
} | ||
} | ||
fieldsInputTransformed.included = []; | ||
fieldsInputTransformed.excluded = []; | ||
} | ||
if (fieldsInputTransformed.default.length > 0) { | ||
for (let j = 0; j < fieldsInputTransformed.default.length; j++) { | ||
output.push({ | ||
key: fieldsInputTransformed.default[j], | ||
}); | ||
} | ||
} | ||
if (fieldsInputTransformed.included.length > 0) { | ||
for (let j = 0; j < fieldsInputTransformed.included.length; j++) { | ||
output.push({ | ||
key: fieldsInputTransformed.included[j], | ||
value: constants_1.FieldOperator.INCLUDE, | ||
}); | ||
} | ||
} | ||
if (fieldsInputTransformed.excluded.length > 0) { | ||
for (let j = 0; j < fieldsInputTransformed.excluded.length; j++) { | ||
output.push({ | ||
key: fieldsInputTransformed.excluded[j], | ||
value: constants_1.FieldOperator.EXCLUDE, | ||
}); | ||
} | ||
} | ||
fields = fields | ||
.filter((field) => domainFields[domainKey].indexOf((0, utils_2.removeFieldInputOperator)(field)) !== -1); | ||
transformed = (0, utils_2.transformFieldsInput)(fields); | ||
} | ||
else if (defaultDomainFields[domainKey].length > 0) { | ||
for (let j = 0; j < defaultDomainFields[domainKey].length; j++) { | ||
output.push({ | ||
key: defaultDomainFields[domainKey][j], | ||
}); | ||
if (transformed.default.length === 0) { | ||
if ((0, utils_1.hasOwnProperty)(defaultDomainFields, domainKey)) { | ||
transformed.default = defaultDomainFields[domainKey]; | ||
} | ||
} | ||
for (let j = 0; j < output.length; j++) { | ||
output[j].key = (0, utils_2.getFieldNamedByAliasMapping)(domainKey, output[j].key, options.aliasMapping); | ||
if (domainKey !== constants_1.DEFAULT_ALIAS_ID) { | ||
output[j].alias = domainKey; | ||
if (transformed.included.length === 0 && | ||
transformed.default.length === 0 && | ||
(0, utils_1.hasOwnProperty)(domainFields, domainKey)) { | ||
transformed.default = domainFields[domainKey]; | ||
} | ||
} | ||
if (typeof options.allowed !== 'undefined' || | ||
typeof options.default !== 'undefined') { | ||
output = output | ||
.filter((field) => (0, utils_1.hasOwnProperty)(allowedDomainFields, domainKey) && | ||
allowedDomainFields[domainKey].indexOf(field.key) !== -1); | ||
} | ||
if (output.length > 0) { | ||
processedDomainKeys.push(domainKey); | ||
transformed = [...transformed, ...output]; | ||
} | ||
} | ||
if (defaultDomainKeys.length > 0) { | ||
const missingDomainKeys = []; | ||
for (let i = 0; i < defaultDomainKeys.length; i++) { | ||
if (processedDomainKeys.indexOf(defaultDomainKeys[i]) === -1 && | ||
isRelationIncluded(defaultDomainKeys[i], options)) { | ||
missingDomainKeys.push(defaultDomainKeys[i]); | ||
transformed.default = Array.from(new Set([ | ||
...transformed.default, | ||
...transformed.included, | ||
])); | ||
for (let j = 0; j < transformed.excluded.length; j++) { | ||
const index = transformed.default.indexOf(transformed.excluded[j]); | ||
if (index !== -1) { | ||
transformed.default.splice(index, 1); | ||
} | ||
} | ||
if (missingDomainKeys.length > 0) { | ||
for (let i = 0; i < missingDomainKeys.length; i++) { | ||
for (let j = 0; j < defaultDomainFields[missingDomainKeys[i]].length; j++) { | ||
transformed.push(Object.assign(Object.assign({}, (missingDomainKeys[i] !== constants_1.DEFAULT_ALIAS_ID ? | ||
{ alias: missingDomainKeys[i] } : | ||
{})), { key: (0, utils_2.getFieldNamedByAliasMapping)(missingDomainKeys[i], defaultDomainFields[missingDomainKeys[i]][j], options.aliasMapping) })); | ||
} | ||
if (transformed.default.length > 0) { | ||
for (let j = 0; j < transformed.default.length; j++) { | ||
output.push(Object.assign({ key: transformed.default[j] }, (domainKey !== constants_1.DEFAULT_ALIAS_ID ? { alias: domainKey } : {}))); | ||
} | ||
} | ||
} | ||
return transformed; | ||
return output; | ||
} | ||
exports.parseQueryFields = parseQueryFields; | ||
//# sourceMappingURL=parse.js.map |
@@ -1,3 +0,2 @@ | ||
export declare function buildFieldDomainRecords(data?: Record<string, string[]> | string[], defaultAlias?: string): Record<string, string[]>; | ||
export declare function mergeFieldsDomainRecords(sourceA: Record<string, string[]>, sourceB: Record<string, string[]>, defaultAlias?: string): Record<string, string[]>; | ||
export declare function getFieldNamedByAliasMapping(domain: string, field: string, aliasMapping?: Record<string, string>): string; | ||
export declare function buildFieldDomainRecords(data?: Record<string, string[]> | string[]): Record<string, string[]>; | ||
export declare function mergeFieldsDomainRecords(sourceA: Record<string, string[]>, sourceB: Record<string, string[]>): Record<string, string[]>; |
@@ -9,6 +9,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFieldNamedByAliasMapping = exports.mergeFieldsDomainRecords = exports.buildFieldDomainRecords = void 0; | ||
const constants_1 = require("../constants"); | ||
exports.mergeFieldsDomainRecords = exports.buildFieldDomainRecords = void 0; | ||
const utils_1 = require("../../../utils"); | ||
function buildFieldDomainRecords(data, defaultAlias) { | ||
const constants_1 = require("../../../constants"); | ||
function buildFieldDomainRecords(data) { | ||
if (typeof data === 'undefined') { | ||
@@ -19,3 +19,3 @@ return {}; | ||
if (Array.isArray(data)) { | ||
domainFields[defaultAlias || constants_1.DEFAULT_ALIAS_ID] = data; | ||
domainFields[constants_1.DEFAULT_ALIAS_ID] = data; | ||
} | ||
@@ -28,3 +28,3 @@ else { | ||
exports.buildFieldDomainRecords = buildFieldDomainRecords; | ||
function mergeFieldsDomainRecords(sourceA, sourceB, defaultAlias) { | ||
function mergeFieldsDomainRecords(sourceA, sourceB) { | ||
const target = {}; | ||
@@ -50,7 +50,7 @@ let keys = Object.keys(sourceA); | ||
keys = Object.keys(target); | ||
const alias = defaultAlias || constants_1.DEFAULT_ALIAS_ID; | ||
if (keys.length >= 2 && | ||
(0, utils_1.hasOwnProperty)(target, alias) && | ||
target[alias].length === 0) { | ||
delete target[alias]; | ||
(0, utils_1.hasOwnProperty)(target, constants_1.DEFAULT_ALIAS_ID) && | ||
Array.isArray(target[constants_1.DEFAULT_ALIAS_ID]) && | ||
target[constants_1.DEFAULT_ALIAS_ID].length === 0) { | ||
delete target[constants_1.DEFAULT_ALIAS_ID]; | ||
} | ||
@@ -60,12 +60,2 @@ return target; | ||
exports.mergeFieldsDomainRecords = mergeFieldsDomainRecords; | ||
function getFieldNamedByAliasMapping(domain, field, aliasMapping) { | ||
if (typeof aliasMapping === 'undefined') { | ||
return field; | ||
} | ||
const key = `${domain}.${field}`; | ||
return (0, utils_1.hasOwnProperty)(aliasMapping, key) ? | ||
aliasMapping[key].split('.').pop() : | ||
field; | ||
} | ||
exports.getFieldNamedByAliasMapping = getFieldNamedByAliasMapping; | ||
//# sourceMappingURL=domain.js.map |
import { FieldsInputTransformed } from '../type'; | ||
export declare function removeFieldInputOperator(field: string): string; | ||
export declare function transformFieldsInput(fields: string[]): FieldsInputTransformed; | ||
export declare function parseFieldsInput(data: unknown): string[]; |
@@ -9,4 +9,11 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseFieldsInput = exports.transformFieldsInput = void 0; | ||
exports.parseFieldsInput = exports.transformFieldsInput = exports.removeFieldInputOperator = void 0; | ||
const constants_1 = require("../constants"); | ||
function removeFieldInputOperator(field) { | ||
return field.substring(0, 1) === constants_1.FieldOperator.INCLUDE || | ||
field.substring(0, 1) === constants_1.FieldOperator.EXCLUDE ? | ||
field.substring(1) : | ||
field; | ||
} | ||
exports.removeFieldInputOperator = removeFieldInputOperator; | ||
function transformFieldsInput(fields) { | ||
@@ -13,0 +20,0 @@ const output = { |
@@ -8,4 +8,8 @@ "use strict"; | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseQueryFilters = void 0; | ||
const minimatch_1 = __importDefault(require("minimatch")); | ||
const utils_1 = require("../../utils"); | ||
@@ -72,7 +76,5 @@ const utils_2 = require("./utils"); | ||
} | ||
if (Object.prototype.hasOwnProperty.call(options.aliasMapping, keys[i])) { | ||
keys[i] = options.aliasMapping[keys[i]]; | ||
} | ||
keys[i] = (0, utils_1.getNameByAliasMapping)(keys[i], options.aliasMapping); | ||
const fieldDetails = (0, utils_1.getFieldDetails)(keys[i]); | ||
if (!(0, utils_1.isFieldAllowedByRelations)(fieldDetails, options.relations, { defaultAlias: options.defaultAlias })) { | ||
if (!(0, utils_1.isAllowedByRelations)(fieldDetails, options.relations, options.defaultAlias)) { | ||
// eslint-disable-next-line no-continue | ||
@@ -83,4 +85,4 @@ continue; | ||
if (typeof options.allowed !== 'undefined' && | ||
options.allowed.indexOf(keys[i]) === -1 && | ||
options.allowed.indexOf(keyWithAlias) === -1) { | ||
// eslint-disable-next-line no-loop-func,@typescript-eslint/no-loop-func | ||
!options.allowed.some((allowed) => (0, minimatch_1.default)(keys[i], allowed) || (0, minimatch_1.default)(keyWithAlias, allowed))) { | ||
continue; | ||
@@ -87,0 +89,0 @@ } |
@@ -17,29 +17,16 @@ "use strict"; | ||
// -------------------------------------------------- | ||
function includeParents(data, options) { | ||
const ret = []; | ||
function includeParents(data) { | ||
for (let i = 0; i < data.length; i++) { | ||
const parts = data[i].split('.'); | ||
let value = parts.shift(); | ||
/* istanbul ignore next */ | ||
if (options.aliasMapping && | ||
(0, utils_1.hasOwnProperty)(options.aliasMapping, value)) { | ||
value = options.aliasMapping[value]; | ||
} | ||
if (ret.indexOf(value) === -1) { | ||
ret.push(value); | ||
} | ||
while (parts.length > 0) { | ||
const postValue = parts.shift(); | ||
value += `.${postValue}`; | ||
/* istanbul ignore next */ | ||
if (options.aliasMapping && | ||
(0, utils_1.hasOwnProperty)(options.aliasMapping, value)) { | ||
value = options.aliasMapping[value]; | ||
parts.pop(); | ||
if (parts.length > 0) { | ||
const value = parts.join('.'); | ||
if (data.indexOf(value) === -1) { | ||
data.unshift(value); | ||
} | ||
} | ||
if (ret.indexOf(value) === -1) { | ||
ret.push(value); | ||
} | ||
} | ||
} | ||
return ret; | ||
return data; | ||
} | ||
@@ -77,5 +64,3 @@ function parseQueryRelations(data, options) { | ||
for (let i = 0; i < items.length; i++) { | ||
if ((0, utils_1.hasOwnProperty)(options.aliasMapping, items[i])) { | ||
items[i] = options.aliasMapping[items[i]]; | ||
} | ||
items[i] = (0, utils_1.getNameByAliasMapping)(items[i], options.aliasMapping); | ||
} | ||
@@ -95,7 +80,8 @@ if (options.allowed) { | ||
if (Array.isArray(options.includeParents)) { | ||
const parentIncludes = items.filter((item) => item.includes('.') && options.includeParents.filter((parent) => (0, minimatch_1.default)(item, parent)).length > 0); | ||
items.unshift(...includeParents(parentIncludes, options)); | ||
const parentIncludes = items.filter((item) => item.includes('.') && | ||
options.includeParents.filter((parent) => (0, minimatch_1.default)(item, parent)).length > 0); | ||
items.unshift(...includeParents(parentIncludes)); | ||
} | ||
else { | ||
items = includeParents(items, options); | ||
items = includeParents(items); | ||
} | ||
@@ -102,0 +88,0 @@ } |
@@ -67,8 +67,5 @@ "use strict"; | ||
} | ||
let key = parts[i]; | ||
if ((0, utils_1.hasOwnProperty)(options.aliasMapping, key)) { | ||
key = options.aliasMapping[key]; | ||
} | ||
const key = (0, utils_1.getNameByAliasMapping)(parts[i], options.aliasMapping); | ||
const fieldDetails = (0, utils_1.getFieldDetails)(key); | ||
if (!(0, utils_1.isFieldAllowedByRelations)(fieldDetails, options.relations, { defaultAlias: options.defaultAlias })) { | ||
if (!(0, utils_1.isAllowedByRelations)(fieldDetails, options.relations, options.defaultAlias)) { | ||
continue; | ||
@@ -75,0 +72,0 @@ } |
@@ -0,1 +1,2 @@ | ||
export * from './alias'; | ||
export * from './field'; | ||
@@ -2,0 +3,0 @@ export * from './relation'; |
@@ -23,2 +23,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./alias"), exports); | ||
__exportStar(require("./field"), exports); | ||
@@ -25,0 +26,0 @@ __exportStar(require("./relation"), exports); |
import { FieldDetails } from './type'; | ||
export declare function isFieldAllowedByRelations<T extends { | ||
export declare function isAllowedByRelations(field: string | Pick<FieldDetails, 'alias' | 'path'>, includes?: { | ||
value: string; | ||
}>(field: string | FieldDetails, includes?: T[], options?: { | ||
defaultAlias?: string; | ||
}): boolean; | ||
export declare function buildFieldWithAlias(field: string | FieldDetails, defaultAlias?: string): string; | ||
}[], defaultAlias?: string): boolean; | ||
export declare function buildFieldWithAlias(field: string | Pick<FieldDetails, 'alias' | 'name'>, defaultAlias?: string): string; |
@@ -9,10 +9,12 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildFieldWithAlias = exports.isFieldAllowedByRelations = void 0; | ||
exports.buildFieldWithAlias = exports.isAllowedByRelations = void 0; | ||
const field_1 = require("./field"); | ||
function isFieldAllowedByRelations(field, includes, options) { | ||
const constants_1 = require("../constants"); | ||
function isAllowedByRelations(field, includes, defaultAlias) { | ||
if (typeof includes === 'undefined') { | ||
return true; | ||
} | ||
options = options !== null && options !== void 0 ? options : {}; | ||
const details = typeof field === 'string' ? (0, field_1.getFieldDetails)(field) : field; | ||
const details = typeof field === 'string' ? | ||
(0, field_1.getFieldDetails)(field) : | ||
field; | ||
// check if field is associated to the default domain. | ||
@@ -24,19 +26,19 @@ if (typeof details.path === 'undefined' && | ||
// check if field is associated to the default domain. | ||
if (details.path === options.defaultAlias || | ||
details.alias === options.defaultAlias) { | ||
if (details.path === defaultAlias || | ||
details.alias === defaultAlias || | ||
details.alias === constants_1.DEFAULT_ALIAS_ID) { | ||
return true; | ||
} | ||
return includes.filter((include) => include.value === details.path || include.value === details.alias).length > 0; | ||
return includes.some((include) => include.value === details.path || include.value === details.alias); | ||
} | ||
exports.isFieldAllowedByRelations = isFieldAllowedByRelations; | ||
exports.isAllowedByRelations = isAllowedByRelations; | ||
function buildFieldWithAlias(field, defaultAlias) { | ||
const details = typeof field === 'string' ? (0, field_1.getFieldDetails)(field) : field; | ||
if (typeof details.path === 'undefined' && | ||
typeof details.alias === 'undefined') { | ||
// try to use query alias | ||
return defaultAlias ? `${defaultAlias}.${details.name}` : details.name; | ||
} | ||
return `${details.alias}.${details.name}`; | ||
const details = typeof field === 'string' ? | ||
(0, field_1.getFieldDetails)(field) : | ||
field; | ||
return defaultAlias || details.alias ? | ||
`${details.alias || defaultAlias}.${details.name}` : | ||
details.name; | ||
} | ||
exports.buildFieldWithAlias = buildFieldWithAlias; | ||
//# sourceMappingURL=relation.js.map |
{ | ||
"name": "rapiq", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A tiny library which provides utility types/functions for request and response query handling.", | ||
@@ -55,10 +55,10 @@ "main": "./dist/index.js", | ||
"@types/jest": "^27.5.0", | ||
"@types/node": "^18.6.4", | ||
"@types/minimatch": "^3.0.5", | ||
"@types/node": "^18.7.1", | ||
"codecov": "^3.8.3", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.18.0", | ||
"jest": "^27.5.1", | ||
"lerna": "^5.1.6", | ||
"np": "^7.6.2", | ||
"rimraf": "^3.0.2", | ||
"eslint": "^8.18.0", | ||
"ts-jest": "^27.1.4", | ||
@@ -65,0 +65,0 @@ "typescript": "^4.7.4", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
162
2278
153848