Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rapiq

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rapiq - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

dist/parameter/utils/parse/allowed-option.d.ts

4

dist/parameter/fields/parse.js

@@ -27,4 +27,4 @@ "use strict";

options !== null && options !== void 0 ? options : (options = {});
const defaultDomainFields = (0, utils_1.groupArrayByKeyPath)((0, utils_2.flattenParseOptionsAllowed)(options.default));
const allowedDomainFields = (0, utils_1.groupArrayByKeyPath)((0, utils_2.flattenParseOptionsAllowed)(options.allowed));
const defaultDomainFields = (0, utils_1.groupArrayByKeyPath)((0, utils_2.flattenParseAllowedOption)(options.default));
const allowedDomainFields = (0, utils_1.groupArrayByKeyPath)((0, utils_2.flattenParseAllowedOption)(options.allowed));
const domainFields = (0, smob_1.merge)({}, defaultDomainFields, allowedDomainFields);

@@ -31,0 +31,0 @@ let domainKeys = Object.keys(domainFields);

import { Flatten, KeyWithOptionalPrefix, NestedKeys, OnlyObject, SimpleKeys } from '../../type';
import { RelationsParseOutput } from '../relations';
import { ParseAllowedKeys } from '../type';
import { ParseAllowedOption } from '../type';
import { FieldOperator } from './constants';

@@ -13,4 +13,4 @@ declare type FieldWithOperator<T extends string> = KeyWithOptionalPrefix<T, FieldOperator>;

mapping?: Record<string, string>;
allowed?: ParseAllowedKeys<T>;
default?: ParseAllowedKeys<T>;
allowed?: ParseAllowedOption<T>;
default?: ParseAllowedOption<T>;
defaultPath?: string;

@@ -17,0 +17,0 @@ relations?: RelationsParseOutput;

@@ -98,18 +98,11 @@ "use strict";

}
let value = data[keys[i]];
const value = data[keys[i]];
if (typeof value !== 'string' &&
typeof value !== 'number' &&
typeof value !== 'boolean' &&
value !== null) {
// eslint-disable-next-line no-continue
typeof value !== 'undefined' &&
value !== null &&
!Array.isArray(value)) {
continue;
}
if (typeof value === 'string') {
value = value.trim();
const stripped = value.replace('/,/g', '');
if (stripped.length === 0) {
// eslint-disable-next-line no-continue
continue;
}
}
keys[i] = (0, utils_1.applyMapping)(keys[i], options.mapping);

@@ -123,3 +116,3 @@ const fieldDetails = (0, utils_1.getFieldDetails)(keys[i]);

if (options.allowed &&
!(0, utils_2.isPathCoveredByParseAllowed)(options.allowed, [keys[i], fullKey])) {
!(0, utils_2.isPathCoveredByParseAllowedOption)(options.allowed, [keys[i], fullKey])) {
continue;

@@ -133,3 +126,9 @@ }

if (Array.isArray(filter.value)) {
filter.value = filter.value.filter((item) => options.validate(filter.key, item));
const output = [];
for (let j = 0; j < filter.value.length; j++) {
if (options.validate(filter.key, filter.value[j])) {
output.push(filter.value[j]);
}
}
filter.value = output;
if (filter.value.length === 0) {

@@ -143,2 +142,10 @@ continue;

}
if (typeof filter.value === 'string' &&
filter.value.length === 0) {
continue;
}
if (Array.isArray(filter.value) &&
filter.value.length === 0) {
continue;
}
if (fieldDetails.path || options.defaultPath) {

@@ -145,0 +152,0 @@ filter.path = fieldDetails.path || options.defaultPath;

import { Flatten, NestedKeys, ObjectLiteral, OnlyObject, OnlyScalar, TypeFromNestedKeyPath } from '../../type';
import { RelationsParseOutput } from '../relations';
import { ParseAllowedKeys } from '../type';
import { ParseAllowedOption } from '../type';
import { FilterComparisonOperator } from './constants';

@@ -16,16 +16,16 @@ declare type FilterValueInputPrimitive = boolean | number | string;

};
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);
export declare type FiltersParseDefaultOption<T extends Record<string, any>> = {
[K in keyof T]?: Flatten<T[K]> extends OnlyObject<T[K]> ? FiltersParseDefaultOption<Flatten<T[K]>> : (K extends string ? FilterValue<TypeFromNestedKeyPath<T, K>> : never);
} | {
[K in NestedKeys<T>]?: FilterValue<TypeFromNestedKeyPath<T, K>>;
};
export declare type FiltersValidator<K extends string> = (key: K, value: unknown) => boolean;
export declare type FiltersValidatorOption<K extends string> = (key: K, value: unknown) => boolean;
export declare type FiltersParseOptions<T extends ObjectLiteral = ObjectLiteral> = {
mapping?: Record<string, string>;
allowed?: ParseAllowedKeys<T>;
default?: FiltersDefaultKeys<T>;
allowed?: ParseAllowedOption<T>;
default?: FiltersParseDefaultOption<T>;
defaultByElement?: boolean;
defaultPath?: string;
relations?: RelationsParseOutput;
validate?: FiltersValidator<NestedKeys<T>>;
validate?: FiltersValidatorOption<NestedKeys<T>>;
};

@@ -32,0 +32,0 @@ export declare type FiltersParseOutputElement = {

import { FilterComparisonOperator } from '../constants';
export declare function parseFilterValue(input: string): {
import { FilterValueSimple } from '../type';
export declare function parseFilterValue(input: FilterValueSimple): {
operator: `${FilterComparisonOperator}`;
value: string | string[];
value: FilterValueSimple;
};

@@ -12,15 +12,31 @@ "use strict";

function matchOperator(key, value, position) {
switch (position) {
case 'start': {
if (value.substring(0, key.length) === key) {
return value.substring(key.length);
if (typeof value === 'string') {
switch (position) {
case 'start': {
if (value.substring(0, key.length) === key) {
return value.substring(key.length);
}
break;
}
break;
case 'end': {
if (value.substring(0 - key.length) === key) {
return value.substring(0, value.length - key.length - 1);
}
break;
}
}
case 'end': {
if (value.substring(0 - key.length) === key) {
return value.substring(0, value.length - key.length - 1);
return undefined;
}
if (Array.isArray(value)) {
let match = false;
for (let i = 0; i < value.length; i++) {
const output = matchOperator(key, value[i], position);
if (typeof output !== 'undefined') {
match = true;
value[i] = output;
}
break;
}
if (match) {
return value;
}
}

@@ -30,2 +46,6 @@ return undefined;

function parseFilterValue(input) {
if (typeof input === 'string' &&
input.includes(constants_1.FilterInputOperatorValue.IN)) {
input = input.split(constants_1.FilterInputOperatorValue.IN);
}
let negation = false;

@@ -37,2 +57,10 @@ let value = matchOperator(constants_1.FilterInputOperatorValue.NEGATION, input, 'start');

}
if (Array.isArray(input)) {
return {
value: input,
operator: negation ?
constants_1.FilterComparisonOperator.NOT_IN :
constants_1.FilterComparisonOperator.IN,
};
}
value = matchOperator(constants_1.FilterInputOperatorValue.LIKE, input, 'start');

@@ -75,10 +103,2 @@ if (typeof value !== 'undefined') {

}
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 {

@@ -85,0 +105,0 @@ value: input,

@@ -1,2 +0,2 @@

import { FilterValue, FilterValueSimple } from '../type';
export declare function transformFilterValue(input: FilterValue): FilterValueSimple;
import { FilterValueSimple } from '../type';
export declare function transformFilterValue(input: FilterValueSimple): FilterValueSimple;

@@ -12,3 +12,4 @@ "use strict";

if (typeof input === 'string') {
const lower = input.trim().toLowerCase();
input = input.trim();
const lower = input.toLowerCase();
if (lower === 'true') {

@@ -23,2 +24,5 @@ return true;

}
if (input.length === 0) {
return input;
}
const num = Number(input);

@@ -25,0 +29,0 @@ if (!Number.isNaN(num)) {

@@ -44,7 +44,10 @@ "use strict";

}
for (let i = 0; i < items.length; i++) {
items[i] = (0, utils_1.applyMapping)(items[i], options.mapping);
const mappingKeys = Object.keys(options.mapping);
if (mappingKeys.length > 0) {
for (let i = 0; i < items.length; i++) {
items[i] = (0, utils_1.applyMapping)(items[i], options.mapping);
}
}
if (options.allowed) {
items = items.filter((item) => (0, utils_2.isPathCoveredByParseAllowed)(options.allowed, item));
items = items.filter((item) => (0, utils_2.isPathCoveredByParseAllowedOption)(options.allowed, item));
}

@@ -65,10 +68,2 @@ if (options.includeParents) {

const parts = key.split('.');
/*
let key : string;
if (path.includes('.')) {
key = parts.slice(-2).join('.');
} else {
key = options.defaultAlias ? `${options.defaultAlias}.${path}` : path;
}
*/
let value;

@@ -75,0 +70,0 @@ if (options.pathMapping &&

@@ -95,3 +95,3 @@ "use strict";

!isMultiDimensionalArray(options.allowed) &&
!(0, utils_2.isPathCoveredByParseAllowed)(options.allowed, [key, keyWithAlias])) {
!(0, utils_2.isPathCoveredByParseAllowedOption)(options.allowed, [key, keyWithAlias])) {
continue;

@@ -116,3 +116,3 @@ }

const temp = [];
const keyPaths = (0, utils_2.flattenParseOptionsAllowed)(options.allowed[i]);
const keyPaths = (0, utils_2.flattenParseAllowedOption)(options.allowed[i]);
for (let j = 0; j < keyPaths.length; j++) {

@@ -119,0 +119,0 @@ let keyWithAlias = keyPaths[j];

import { Flatten, KeyWithOptionalPrefix, NestedKeys, OnlyObject, SimpleKeys } from '../../type';
import { RelationsParseOutput } from '../relations';
import { ParseAllowedKeys } from '../type';
import { ParseAllowedOption } from '../type';
export declare enum SortDirection {

@@ -14,4 +14,4 @@ ASC = "ASC",

})[] | SortWithOperator<NestedKeys<T>>[] | SortWithOperator<NestedKeys<T>>;
export declare type SortParseOptionsDefault<T extends Record<string, any>> = {
[K in keyof T]?: Flatten<T[K]> extends OnlyObject<T[K]> ? SortParseOptionsDefault<Flatten<T[K]>> : `${SortDirection}`;
export declare type SortParseDefaultOption<T extends Record<string, any>> = {
[K in keyof T]?: Flatten<T[K]> extends OnlyObject<T[K]> ? SortParseDefaultOption<Flatten<T[K]>> : `${SortDirection}`;
} | {

@@ -21,5 +21,5 @@ [K in NestedKeys<T>]?: `${SortDirection}`;

export declare type SortParseOptions<T extends Record<string, any> = Record<string, any>> = {
allowed?: ParseAllowedKeys<T>;
allowed?: ParseAllowedOption<T>;
mapping?: Record<string, string>;
default?: SortParseOptionsDefault<T>;
default?: SortParseDefaultOption<T>;
defaultPath?: string;

@@ -26,0 +26,0 @@ relations?: RelationsParseOutput;

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;
declare type ParseAllowedObjectOption<T extends ObjectLiteral = ObjectLiteral> = {
[K in keyof T]?: T[K] extends OnlyObject<T[K]> ? ParseAllowedOption<Flatten<T[K]>> : never;
};
export declare type ParseAllowedKeys<T extends ObjectLiteral = ObjectLiteral> = T extends ObjectLiteral ? (ParseAllowedObject<T> | (SimpleKeys<T>[] | ParseAllowedObject<T>)[] | NestedKeys<T>[]) : string[];
export declare type ParseAllowedOption<T extends ObjectLiteral = ObjectLiteral> = T extends ObjectLiteral ? (ParseAllowedObjectOption<T> | (SimpleKeys<T>[] | ParseAllowedObjectOption<T>)[] | NestedKeys<T>[]) : string[];
export {};

@@ -1,1 +0,1 @@

export * from './options-allowed';
export * from './allowed-option';

@@ -23,3 +23,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./options-allowed"), exports);
__exportStar(require("./allowed-option"), exports);
//# sourceMappingURL=index.js.map
{
"name": "rapiq",
"version": "0.3.0",
"version": "0.3.1",
"description": "A tiny library which provides utility types/functions for request and response query handling.",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -248,3 +248,4 @@ # rapiq 🌈

*
* ...
* Request example
* - url: /users?page[limit]=10&page[offset]=0&include=realm&filter[id]=1&fields=id,name
*

@@ -251,0 +252,0 @@ * @param req

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc