Comparing version 0.2.9 to 0.3.0
import { Flatten, KeyWithOptionalPrefix, NestedKeys, OnlyObject, SimpleKeys } from '../../type'; | ||
import { RelationsParseOutput } from '../relations'; | ||
import { ParseOptionsAllowed } from '../type'; | ||
import { ParseAllowedKeys } from '../type'; | ||
import { FieldOperator } from './constants'; | ||
@@ -13,4 +13,4 @@ declare type FieldWithOperator<T extends string> = KeyWithOptionalPrefix<T, FieldOperator>; | ||
mapping?: Record<string, string>; | ||
allowed?: ParseOptionsAllowed<T>; | ||
default?: ParseOptionsAllowed<T>; | ||
allowed?: ParseAllowedKeys<T>; | ||
default?: ParseAllowedKeys<T>; | ||
defaultPath?: string; | ||
@@ -17,0 +17,0 @@ relations?: RelationsParseOutput; |
@@ -11,14 +11,3 @@ "use strict"; | ||
const smob_1 = require("smob"); | ||
const constants_1 = require("./constants"); | ||
const utils_1 = require("./utils"); | ||
const utils_2 = require("../../utils"); | ||
const OperatorWeight = { | ||
[constants_1.FilterOperator.NEGATION]: 0, | ||
[constants_1.FilterOperator.LIKE]: 50, | ||
[constants_1.FilterOperator.LESS_THAN_EQUAL]: 150, | ||
[constants_1.FilterOperator.LESS_THAN]: 450, | ||
[constants_1.FilterOperator.MORE_THAN_EQUAL]: 1350, | ||
[constants_1.FilterOperator.MORE_THAN]: 4050, | ||
[constants_1.FilterOperator.IN]: 13105, | ||
}; | ||
const utils_1 = require("../../utils"); | ||
function buildQueryFilters(data) { | ||
@@ -28,3 +17,3 @@ if (typeof data === 'undefined') { | ||
} | ||
return (0, utils_2.flattenNestedObject)(data, { | ||
return (0, utils_1.flattenNestedObject)(data, { | ||
transformer: (input, output, key) => { | ||
@@ -40,19 +29,2 @@ if (typeof input === 'undefined') { | ||
} | ||
if ((0, utils_1.isFilterOperatorConfig)(input)) { | ||
if (typeof input.value === 'undefined') { | ||
input.value = null; | ||
} | ||
if (Array.isArray(input.value)) { | ||
// todo: check array elements are string | ||
input.value = input.value.join(','); | ||
} | ||
if (Array.isArray(input.operator)) { | ||
// merge operators | ||
input.operator = input.operator | ||
.sort((a, b) => OperatorWeight[a] - OperatorWeight[b]) | ||
.join(''); | ||
} | ||
output[key] = `${input.operator}${input.value}`; | ||
return true; | ||
} | ||
return undefined; | ||
@@ -59,0 +31,0 @@ }, |
@@ -1,11 +0,14 @@ | ||
export declare enum FilterOperatorLabel { | ||
NEGATION = "negation", | ||
LIKE = "like", | ||
LESS_THAN_EQUAL = "lessThanEqual", | ||
LESS_THAN = "lessThan", | ||
MORE_THAN_EQUAL = "moreThanEqual", | ||
MORE_THAN = "moreThan", | ||
IN = "in" | ||
export declare enum FilterComparisonOperator { | ||
EQUAL = "$eq", | ||
NOT_EQUAL = "$ne", | ||
LIKE = "$l", | ||
NOT_LIKE = "$nl", | ||
LESS_THAN_EQUAL = "$lte", | ||
LESS_THAN = "$lt", | ||
GREATER_THAN_EQUAL = "$gte", | ||
GREATER_THAN = "$gt", | ||
IN = "$in", | ||
NOT_IN = "$nin" | ||
} | ||
export declare enum FilterOperator { | ||
export declare enum FilterInputOperatorValue { | ||
NEGATION = "!", | ||
@@ -12,0 +15,0 @@ LIKE = "~", |
@@ -9,23 +9,26 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FilterOperator = exports.FilterOperatorLabel = void 0; | ||
var FilterOperatorLabel; | ||
(function (FilterOperatorLabel) { | ||
FilterOperatorLabel["NEGATION"] = "negation"; | ||
FilterOperatorLabel["LIKE"] = "like"; | ||
FilterOperatorLabel["LESS_THAN_EQUAL"] = "lessThanEqual"; | ||
FilterOperatorLabel["LESS_THAN"] = "lessThan"; | ||
FilterOperatorLabel["MORE_THAN_EQUAL"] = "moreThanEqual"; | ||
FilterOperatorLabel["MORE_THAN"] = "moreThan"; | ||
FilterOperatorLabel["IN"] = "in"; | ||
})(FilterOperatorLabel = exports.FilterOperatorLabel || (exports.FilterOperatorLabel = {})); | ||
var FilterOperator; | ||
(function (FilterOperator) { | ||
FilterOperator["NEGATION"] = "!"; | ||
FilterOperator["LIKE"] = "~"; | ||
FilterOperator["LESS_THAN_EQUAL"] = "<="; | ||
FilterOperator["LESS_THAN"] = "<"; | ||
FilterOperator["MORE_THAN_EQUAL"] = ">="; | ||
FilterOperator["MORE_THAN"] = ">"; | ||
FilterOperator["IN"] = ","; | ||
})(FilterOperator = exports.FilterOperator || (exports.FilterOperator = {})); | ||
exports.FilterInputOperatorValue = exports.FilterComparisonOperator = void 0; | ||
var FilterComparisonOperator; | ||
(function (FilterComparisonOperator) { | ||
FilterComparisonOperator["EQUAL"] = "$eq"; | ||
FilterComparisonOperator["NOT_EQUAL"] = "$ne"; | ||
FilterComparisonOperator["LIKE"] = "$l"; | ||
FilterComparisonOperator["NOT_LIKE"] = "$nl"; | ||
FilterComparisonOperator["LESS_THAN_EQUAL"] = "$lte"; | ||
FilterComparisonOperator["LESS_THAN"] = "$lt"; | ||
FilterComparisonOperator["GREATER_THAN_EQUAL"] = "$gte"; | ||
FilterComparisonOperator["GREATER_THAN"] = "$gt"; | ||
FilterComparisonOperator["IN"] = "$in"; | ||
FilterComparisonOperator["NOT_IN"] = "$nin"; | ||
})(FilterComparisonOperator = exports.FilterComparisonOperator || (exports.FilterComparisonOperator = {})); | ||
var FilterInputOperatorValue; | ||
(function (FilterInputOperatorValue) { | ||
FilterInputOperatorValue["NEGATION"] = "!"; | ||
FilterInputOperatorValue["LIKE"] = "~"; | ||
FilterInputOperatorValue["LESS_THAN_EQUAL"] = "<="; | ||
FilterInputOperatorValue["LESS_THAN"] = "<"; | ||
FilterInputOperatorValue["MORE_THAN_EQUAL"] = ">="; | ||
FilterInputOperatorValue["MORE_THAN"] = ">"; | ||
FilterInputOperatorValue["IN"] = ","; | ||
})(FilterInputOperatorValue = exports.FilterInputOperatorValue || (exports.FilterInputOperatorValue = {})); | ||
//# sourceMappingURL=constants.js.map |
@@ -5,1 +5,2 @@ export * from './constants'; | ||
export * from './type'; | ||
export * from './utils'; |
@@ -27,2 +27,3 @@ "use strict"; | ||
__exportStar(require("./type"), exports); | ||
__exportStar(require("./utils"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -12,2 +12,3 @@ "use strict"; | ||
const utils_2 = require("../utils"); | ||
const constants_1 = require("./constants"); | ||
const utils_3 = require("./utils"); | ||
@@ -17,16 +18,14 @@ // -------------------------------------------------- | ||
if ((0, utils_1.hasOwnProperty)(element, 'path') && | ||
(typeof element.path === 'undefined' || | ||
element.path === null)) { | ||
(typeof element.path === 'undefined' || element.path === null)) { | ||
delete element.path; | ||
} | ||
if (element.operator) { | ||
return element; | ||
} | ||
if (typeof element.value === 'string') { | ||
const { value, operators } = (0, utils_3.determineFilterOperatorLabelsByValue)(element.value); | ||
if (operators.length > 0) { | ||
element.value = value; | ||
element.operator = {}; | ||
for (let i = 0; i < operators.length; i++) { | ||
element.operator[operators[i]] = true; | ||
} | ||
} | ||
element = Object.assign(Object.assign({}, element), (0, utils_3.parseFilterValue)(element.value)); | ||
} | ||
else { | ||
element.operator = constants_1.FilterComparisonOperator.EQUAL; | ||
} | ||
element.value = (0, utils_3.transformFilterValue)(element.value); | ||
@@ -92,3 +91,3 @@ return element; | ||
} | ||
const temp = {}; | ||
const items = {}; | ||
// transform to appreciate data format & validate input | ||
@@ -126,17 +125,28 @@ const keys = Object.keys(data); | ||
if (options.allowed && | ||
!(0, utils_2.isPathCoveredByParseOptionsAllowed)(options.allowed, [keys[i], fullKey])) { | ||
!(0, utils_2.isPathCoveredByParseAllowed)(options.allowed, [keys[i], fullKey])) { | ||
continue; | ||
} | ||
let path; | ||
if (fieldDetails.path) { | ||
path = fieldDetails.path; | ||
const filter = transformFiltersParseOutputElement({ | ||
key: fieldDetails.name, | ||
value: value, | ||
}); | ||
if (options.validate) { | ||
if (Array.isArray(filter.value)) { | ||
filter.value = filter.value.filter((item) => options.validate(filter.key, item)); | ||
if (filter.value.length === 0) { | ||
continue; | ||
} | ||
} | ||
else if (!options.validate(filter.key, filter.value)) { | ||
continue; | ||
} | ||
} | ||
else if (options.defaultPath) { | ||
path = options.defaultPath; | ||
if (fieldDetails.path || options.defaultPath) { | ||
filter.path = fieldDetails.path || options.defaultPath; | ||
} | ||
temp[fullKey] = Object.assign(Object.assign({}, (path ? { path } : {})), { key: fieldDetails.name, value: value }); | ||
items[fullKey] = filter; | ||
} | ||
return transformFiltersParseOutput(buildDefaultFiltersParseOutput(options, temp)); | ||
return buildDefaultFiltersParseOutput(options, items); | ||
} | ||
exports.parseQueryFilters = parseQueryFilters; | ||
//# sourceMappingURL=parse.js.map |
@@ -1,15 +0,11 @@ | ||
import { Flatten, NestedKeys, OnlyObject, OnlyScalar, TypeFromNestedKeyPath } from '../../type'; | ||
import { Flatten, NestedKeys, ObjectLiteral, OnlyObject, OnlyScalar, TypeFromNestedKeyPath } from '../../type'; | ||
import { RelationsParseOutput } from '../relations'; | ||
import { ParseOptionsAllowed } from '../type'; | ||
import { FilterOperator, FilterOperatorLabel } from './constants'; | ||
import { ParseAllowedKeys } from '../type'; | ||
import { FilterComparisonOperator } from './constants'; | ||
declare type FilterValueInputPrimitive = boolean | number | string; | ||
declare type FilterValueInput = FilterValueInputPrimitive | null | undefined; | ||
export declare type FilterValueSimple<V extends FilterValueInput = FilterValueInput> = V extends FilterValueInputPrimitive ? (V | V[]) : V; | ||
export declare type FilterValueWithOperator<V extends FilterValueInput = FilterValueInput> = V extends string | number ? `!${V}` | `!~${V}` | `~${V}` | `${V}~` | `~${V}~` | `<${V}` | `<=${V}` | `>${V}` | `>=${V}` | null | '!null' : V extends boolean ? null | '!null' : never; | ||
export declare type FilterValue<V extends FilterValueInput = FilterValueInput> = V extends FilterValueInputPrimitive ? (FilterValueSimple<V> | FilterValueWithOperator<V> | Array<FilterValueWithOperator<V>>) : V; | ||
export declare type FilterOperatorConfig<V extends FilterValueInput = FilterValueInput> = { | ||
operator: `${FilterOperator}` | (`${FilterOperator}`)[]; | ||
value: FilterValueSimple<V>; | ||
}; | ||
export declare type FiltersBuildInputValue<T> = T extends OnlyScalar<T> ? T | FilterValue<T> | FilterOperatorConfig<T> : never; | ||
export declare type FilterValueSimple<V extends FilterValueInput = FilterValueInput> = V extends string | number ? (V | V[]) : V; | ||
export declare type FilterValueWithOperator<V extends FilterValueInput = FilterValueInput> = V extends string | number ? V | `!${V}` | `!~${V}` | `~${V}` | `<${V}` | `<=${V}` | `>${V}` | `>=${V}` | null | '!null' : V extends boolean ? V | null | '!null' : never; | ||
export declare type FilterValue<V extends FilterValueInput = FilterValueInput> = V extends string | number ? (FilterValueSimple<V> | FilterValueWithOperator<V> | Array<FilterValueWithOperator<V>>) : V; | ||
export declare type FiltersBuildInputValue<T> = T extends OnlyScalar<T> ? T | FilterValue<T> : never; | ||
export declare type FiltersBuildInput<T extends Record<string, any>> = { | ||
@@ -20,19 +16,19 @@ [K in keyof T]?: Flatten<T[K]> extends Record<string, any> ? FiltersBuildInput<Flatten<T[K]>> : FiltersBuildInputValue<Flatten<T[K]>>; | ||
}; | ||
export declare type FiltersParseOptionsDefault<T extends Record<string, any>> = { | ||
[K in keyof T]?: Flatten<T[K]> extends OnlyObject<T[K]> ? FiltersParseOptionsDefault<Flatten<T[K]>> : (K extends string ? FilterValue<TypeFromNestedKeyPath<T, K>> : never); | ||
export declare type FiltersDefaultKeys<T extends Record<string, any>> = { | ||
[K in keyof T]?: Flatten<T[K]> extends OnlyObject<T[K]> ? FiltersDefaultKeys<Flatten<T[K]>> : (K extends string ? FilterValue<TypeFromNestedKeyPath<T, K>> : never); | ||
} | { | ||
[K in NestedKeys<T>]?: FilterValue<TypeFromNestedKeyPath<T, K>>; | ||
}; | ||
export declare type FiltersParseOptions<T extends Record<string, any> = Record<string, any>> = { | ||
export declare type FiltersValidator<K extends string> = (key: K, value: unknown) => boolean; | ||
export declare type FiltersParseOptions<T extends ObjectLiteral = ObjectLiteral> = { | ||
mapping?: Record<string, string>; | ||
allowed?: ParseOptionsAllowed<T>; | ||
default?: FiltersParseOptionsDefault<T>; | ||
allowed?: ParseAllowedKeys<T>; | ||
default?: FiltersDefaultKeys<T>; | ||
defaultByElement?: boolean; | ||
defaultPath?: string; | ||
relations?: RelationsParseOutput; | ||
validate?: FiltersValidator<NestedKeys<T>>; | ||
}; | ||
export declare type FiltersParseOutputElement = { | ||
operator?: { | ||
[K in FilterOperatorLabel]?: boolean; | ||
}; | ||
operator?: `${FilterComparisonOperator}`; | ||
value: FilterValueSimple; | ||
@@ -39,0 +35,0 @@ key: string; |
@@ -1,7 +0,5 @@ | ||
import { FilterOperatorConfig } from '../type'; | ||
import { FilterOperatorLabel } from '../constants'; | ||
export declare function determineFilterOperatorLabelsByValue(input: string): { | ||
operators: (`${FilterOperatorLabel}`)[]; | ||
import { FilterComparisonOperator } from '../constants'; | ||
export declare function parseFilterValue(input: string): { | ||
operator: `${FilterComparisonOperator}`; | ||
value: string | string[]; | ||
}; | ||
export declare function isFilterOperatorConfig(data: unknown): data is FilterOperatorConfig<any>; |
@@ -9,96 +9,81 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isFilterOperatorConfig = exports.determineFilterOperatorLabelsByValue = void 0; | ||
const utils_1 = require("../../../utils"); | ||
exports.parseFilterValue = void 0; | ||
const constants_1 = require("../constants"); | ||
const config = []; | ||
const operatorKeys = Object.keys(constants_1.FilterOperator); | ||
for (let i = 0; i < operatorKeys.length; i++) { | ||
config.push({ | ||
sign: constants_1.FilterOperator[operatorKeys[i]], | ||
label: constants_1.FilterOperatorLabel[operatorKeys[i]], | ||
}); | ||
} | ||
function determineFilterOperatorLabelsByValue(input) { | ||
let value = input; | ||
const operators = []; | ||
for (let i = 0; i < config.length; i++) { | ||
if (typeof value !== 'string') { | ||
// eslint-disable-next-line no-continue | ||
continue; | ||
function matchOperator(key, value, position) { | ||
switch (position) { | ||
case 'start': { | ||
if (value.substring(0, key.length) === key) { | ||
return value.substring(key.length); | ||
} | ||
break; | ||
} | ||
switch (config[i].sign) { | ||
case constants_1.FilterOperator.IN: | ||
if (value.includes(config[i].sign)) { | ||
operators.push(config[i].label); | ||
value = value.split(config[i].sign); | ||
} | ||
break; | ||
default: | ||
if (value.slice(0, config[i].sign.length) === config[i].sign) { | ||
operators.push(config[i].label); | ||
value = value.slice(config[i].sign.length); | ||
if (value.toLowerCase() === 'null') { | ||
value = null; | ||
} | ||
} | ||
break; | ||
case 'end': { | ||
if (value.substring(0 - key.length) === key) { | ||
return value.substring(0, value.length - key.length - 1); | ||
} | ||
break; | ||
} | ||
} | ||
return { | ||
operators, | ||
value, | ||
}; | ||
return undefined; | ||
} | ||
exports.determineFilterOperatorLabelsByValue = determineFilterOperatorLabelsByValue; | ||
function isFilterOperatorConfig(data) { | ||
if (typeof data !== 'object' || data === null) { | ||
return false; | ||
function parseFilterValue(input) { | ||
let negation = false; | ||
let value = matchOperator(constants_1.FilterInputOperatorValue.NEGATION, input, 'start'); | ||
if (typeof value !== 'undefined') { | ||
negation = true; | ||
input = value; | ||
} | ||
if ((0, utils_1.hasOwnProperty)(data, 'operator')) { | ||
const operators = Object.values(constants_1.FilterOperator); | ||
if (typeof data.operator === 'string') { | ||
if (operators.indexOf(data.operator) === -1) { | ||
return false; | ||
} | ||
} | ||
else if (Array.isArray(data.operator)) { | ||
for (let i = 0; i < data.operator.length; i++) { | ||
if (typeof data.operator[i] !== 'string') { | ||
return false; | ||
} | ||
if (operators.indexOf(data.operator[i]) === -1) { | ||
return false; | ||
} | ||
} | ||
} | ||
else { | ||
return false; | ||
} | ||
value = matchOperator(constants_1.FilterInputOperatorValue.LIKE, input, 'start'); | ||
if (typeof value !== 'undefined') { | ||
return { | ||
value, | ||
operator: negation ? | ||
constants_1.FilterComparisonOperator.NOT_LIKE : | ||
constants_1.FilterComparisonOperator.LIKE, | ||
}; | ||
} | ||
else { | ||
return false; | ||
value = matchOperator(constants_1.FilterInputOperatorValue.LESS_THAN_EQUAL, input, 'start'); | ||
if (typeof value !== 'undefined') { | ||
return { | ||
value, | ||
operator: constants_1.FilterComparisonOperator.LESS_THAN_EQUAL, | ||
}; | ||
} | ||
if ((0, utils_1.hasOwnProperty)(data, 'value')) { | ||
if (!(0, utils_1.isSimpleValue)(data.value, { | ||
withNull: true, | ||
withUndefined: true, | ||
})) { | ||
if (Array.isArray(data.value)) { | ||
for (let i = 0; i < data.value.length; i++) { | ||
if (!(0, utils_1.isSimpleValue)(data.value[i])) { | ||
return false; | ||
} | ||
} | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
value = matchOperator(constants_1.FilterInputOperatorValue.LESS_THAN, input, 'start'); | ||
if (typeof value !== 'undefined') { | ||
return { | ||
value, | ||
operator: constants_1.FilterComparisonOperator.LESS_THAN, | ||
}; | ||
} | ||
else { | ||
return false; | ||
value = matchOperator(constants_1.FilterInputOperatorValue.MORE_THAN_EQUAL, input, 'start'); | ||
if (typeof value !== 'undefined') { | ||
return { | ||
value, | ||
operator: constants_1.FilterComparisonOperator.GREATER_THAN_EQUAL, | ||
}; | ||
} | ||
return true; | ||
value = matchOperator(constants_1.FilterInputOperatorValue.MORE_THAN, input, 'start'); | ||
if (typeof value !== 'undefined') { | ||
return { | ||
value, | ||
operator: constants_1.FilterComparisonOperator.GREATER_THAN, | ||
}; | ||
} | ||
if (input.includes(constants_1.FilterInputOperatorValue.IN)) { | ||
return { | ||
value: input.split(constants_1.FilterInputOperatorValue.IN), | ||
operator: negation ? | ||
constants_1.FilterComparisonOperator.NOT_IN : | ||
constants_1.FilterComparisonOperator.IN, | ||
}; | ||
} | ||
return { | ||
value: input, | ||
operator: negation ? | ||
constants_1.FilterComparisonOperator.NOT_EQUAL : | ||
constants_1.FilterComparisonOperator.EQUAL, | ||
}; | ||
} | ||
exports.isFilterOperatorConfig = isFilterOperatorConfig; | ||
exports.parseFilterValue = parseFilterValue; | ||
//# sourceMappingURL=operator.js.map |
@@ -1,2 +0,2 @@ | ||
import { FilterValueSimple } from '../type'; | ||
export declare function transformFilterValue<T>(input: FilterValueSimple): FilterValueSimple; | ||
import { FilterValue, FilterValueSimple } from '../type'; | ||
export declare function transformFilterValue(input: FilterValue): FilterValueSimple; |
@@ -11,12 +11,2 @@ "use strict"; | ||
function transformFilterValue(input) { | ||
if (Array.isArray(input)) { | ||
for (let i = 0; i < input.length; i++) { | ||
input[i] = transformFilterValue(input[i]); | ||
} | ||
return input | ||
.filter((n) => n === 0 || !!n); | ||
} | ||
if (typeof input === 'undefined' || input === null) { | ||
return null; | ||
} | ||
if (typeof input === 'string') { | ||
@@ -37,3 +27,17 @@ const lower = input.trim().toLowerCase(); | ||
} | ||
const parts = input.split(','); | ||
if (parts.length > 1) { | ||
return transformFilterValue(parts); | ||
} | ||
} | ||
if (Array.isArray(input)) { | ||
for (let i = 0; i < input.length; i++) { | ||
input[i] = transformFilterValue(input[i]); | ||
} | ||
return input | ||
.filter((n) => n === 0 || !!n); | ||
} | ||
if (typeof input === 'undefined' || input === null) { | ||
return null; | ||
} | ||
return input; | ||
@@ -40,0 +44,0 @@ } |
@@ -48,3 +48,3 @@ "use strict"; | ||
if (options.allowed) { | ||
items = items.filter((item) => (0, utils_2.isPathCoveredByParseOptionsAllowed)(options.allowed, item)); | ||
items = items.filter((item) => (0, utils_2.isPathCoveredByParseAllowed)(options.allowed, item)); | ||
} | ||
@@ -51,0 +51,0 @@ if (options.includeParents) { |
@@ -95,3 +95,3 @@ "use strict"; | ||
!isMultiDimensionalArray(options.allowed) && | ||
!(0, utils_2.isPathCoveredByParseOptionsAllowed)(options.allowed, [key, keyWithAlias])) { | ||
!(0, utils_2.isPathCoveredByParseAllowed)(options.allowed, [key, keyWithAlias])) { | ||
continue; | ||
@@ -98,0 +98,0 @@ } |
import { Flatten, KeyWithOptionalPrefix, NestedKeys, OnlyObject, SimpleKeys } from '../../type'; | ||
import { RelationsParseOutput } from '../relations'; | ||
import { ParseOptionsAllowed } from '../type'; | ||
import { ParseAllowedKeys } from '../type'; | ||
export declare enum SortDirection { | ||
@@ -11,8 +11,5 @@ ASC = "ASC", | ||
[K in keyof T]?: Flatten<T[K]> extends OnlyObject<T[K]> ? SortBuildInput<Flatten<T[K]>> : `${SortDirection}`; | ||
} | [ | ||
SortWithOperator<SimpleKeys<T>>[], | ||
{ | ||
[K in keyof T]?: Flatten<T[K]> extends OnlyObject<T[K]> ? SortBuildInput<Flatten<T[K]>> : `${SortDirection}`; | ||
} | ||
] | SortWithOperator<NestedKeys<T>>[] | SortWithOperator<NestedKeys<T>>; | ||
} | (SortWithOperator<SimpleKeys<T>>[] | { | ||
[K in keyof T]?: Flatten<T[K]> extends OnlyObject<T[K]> ? SortBuildInput<Flatten<T[K]>> : `${SortDirection}`; | ||
})[] | SortWithOperator<NestedKeys<T>>[] | SortWithOperator<NestedKeys<T>>; | ||
export declare type SortParseOptionsDefault<T extends Record<string, any>> = { | ||
@@ -24,3 +21,3 @@ [K in keyof T]?: Flatten<T[K]> extends OnlyObject<T[K]> ? SortParseOptionsDefault<Flatten<T[K]>> : `${SortDirection}`; | ||
export declare type SortParseOptions<T extends Record<string, any> = Record<string, any>> = { | ||
allowed?: ParseOptionsAllowed<T> | ParseOptionsAllowed<T>[]; | ||
allowed?: ParseAllowedKeys<T>; | ||
mapping?: Record<string, string>; | ||
@@ -27,0 +24,0 @@ default?: SortParseOptionsDefault<T>; |
@@ -1,8 +0,6 @@ | ||
import { Flatten, NestedKeys, OnlyObject, SimpleKeys } from '../type'; | ||
export declare type ParseOptionsAllowedObject<T extends Record<string, any>> = { | ||
[K in keyof T]?: T[K] extends OnlyObject<T[K]> ? ParseOptionsAllowed<Flatten<T[K]>> : never; | ||
import { Flatten, NestedKeys, ObjectLiteral, OnlyObject, SimpleKeys } from '../type'; | ||
declare type ParseAllowedObject<T extends ObjectLiteral = ObjectLiteral> = { | ||
[K in keyof T]?: T[K] extends OnlyObject<T[K]> ? ParseAllowedKeys<Flatten<T[K]>> : never; | ||
}; | ||
export declare type ParseOptionsAllowed<T extends Record<string, any>> = ParseOptionsAllowedObject<T> | [ | ||
SimpleKeys<T>[], | ||
ParseOptionsAllowedObject<T> | ||
] | NestedKeys<T>[]; | ||
export declare type ParseAllowedKeys<T extends ObjectLiteral = ObjectLiteral> = T extends ObjectLiteral ? (ParseAllowedObject<T> | (SimpleKeys<T>[] | ParseAllowedObject<T>)[] | NestedKeys<T>[]) : string[]; | ||
export {}; |
@@ -1,3 +0,4 @@ | ||
import { ParseOptionsAllowed } from '../../type'; | ||
export declare function flattenParseOptionsAllowed<T>(input: ParseOptionsAllowed<T>): string[]; | ||
export declare function isPathCoveredByParseOptionsAllowed<T>(input: ParseOptionsAllowed<T>, path: string | string[]): boolean; | ||
import { NestedKeys, NestedResourceKeys } from '../../../type'; | ||
import { ParseAllowedKeys } from '../../type'; | ||
export declare function flattenParseOptionsAllowed<T>(input: ParseAllowedKeys<T>): string[]; | ||
export declare function isPathCoveredByParseAllowed<T>(input: ParseAllowedKeys<T> | NestedKeys<T>[] | NestedResourceKeys<T>[], path: string | string[]): boolean; |
@@ -9,3 +9,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isPathCoveredByParseOptionsAllowed = exports.flattenParseOptionsAllowed = void 0; | ||
exports.isPathCoveredByParseAllowed = exports.flattenParseOptionsAllowed = void 0; | ||
const utils_1 = require("../../../utils"); | ||
@@ -16,3 +16,3 @@ function flattenParseOptionsAllowed(input) { | ||
exports.flattenParseOptionsAllowed = flattenParseOptionsAllowed; | ||
function isPathCoveredByParseOptionsAllowed(input, path) { | ||
function isPathCoveredByParseAllowed(input, path) { | ||
const paths = Array.isArray(path) ? path : [path]; | ||
@@ -27,3 +27,3 @@ const items = (0, utils_1.flattenToKeyPathArray)(input); | ||
} | ||
exports.isPathCoveredByParseOptionsAllowed = isPathCoveredByParseOptionsAllowed; | ||
exports.isPathCoveredByParseAllowed = isPathCoveredByParseAllowed; | ||
//# sourceMappingURL=options-allowed.js.map |
@@ -10,18 +10,18 @@ export declare type ObjectLiteral = Record<string, any>; | ||
declare type PrevIndex = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; | ||
export declare type SimpleKeys<T extends Record<string, any>> = { | ||
export declare type SimpleKeys<T extends ObjectLiteral> = T extends ObjectLiteral ? ({ | ||
[Key in keyof T & (string | number)]: Flatten<T[Key]> extends Record<string, any> ? (Flatten<T[Key]> extends Date ? `${Key}` : never) : `${Key}`; | ||
}[keyof T & (string | number)]; | ||
export declare type NestedKeys<T extends Record<string, any>, Depth extends number = 4> = [ | ||
}[keyof T & (string | number)]) : string; | ||
export declare type NestedKeys<T extends ObjectLiteral, Depth extends number = 4> = T extends ObjectLiteral ? ([ | ||
Depth | ||
] extends [0] ? never : { | ||
[Key in keyof T & (string | number)]: Flatten<T[Key]> extends Record<string, any> ? (Flatten<T[Key]> extends Date ? `${Key}` : `${Key}.${NestedKeys<Flatten<T[Key]>, PrevIndex[Depth]>}`) : `${Key}`; | ||
}[keyof T & (string | number)]; | ||
export declare type NestedResourceKeys<T extends Record<string, any>, Depth extends number = 4> = [ | ||
}[keyof T & (string | number)]) : string; | ||
export declare type NestedResourceKeys<T extends ObjectLiteral, Depth extends number = 4> = T extends ObjectLiteral ? ([ | ||
Depth | ||
] extends [0] ? never : { | ||
[Key in keyof T & (string | number)]: Flatten<T[Key]> extends Record<string, any> ? Key | `${Key}.${NestedResourceKeys<Flatten<T[Key]>, PrevIndex[Depth]>}` : never; | ||
}[keyof T & (string | number)]; | ||
export declare type TypeFromNestedKeyPath<T extends Record<string, any>, Path extends string> = { | ||
}[keyof T & (string | number)]) : string; | ||
export declare type TypeFromNestedKeyPath<T extends ObjectLiteral, Path extends string> = { | ||
[K in Path]: K extends keyof T ? Flatten<T[K]> : K extends `${infer P}.${infer S}` ? Flatten<T[P]> extends Record<string, any> ? TypeFromNestedKeyPath<Flatten<T[P]>, S> : never : never; | ||
}[Path]; | ||
export {}; |
{ | ||
"name": "rapiq", | ||
"version": "0.2.9", | ||
"version": "0.3.0", | ||
"description": "A tiny library which provides utility types/functions for request and response query handling.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
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
168593
2504