New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dataui/crud-request

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dataui/crud-request - npm Package Compare versions

Comparing version 5.3.1-alpha.3 to 5.3.1

6

lib/exceptions/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {

@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {

@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {

@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k;

2

lib/interfaces/operators-options.interface.d.ts

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

export type CustomOperatorQuery = (field: string, param: string) => string;
export declare type CustomOperatorQuery = (field: string, param: string) => string;
export interface CustomOperators {

@@ -3,0 +3,0 @@ [key: string]: {

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

const qb = new RequestQueryBuilder();
return (0, crud_util_1.isObject)(params) ? qb.createFromParams(params, customOperators) : qb;
return crud_util_1.isObject(params) ? qb.createFromParams(params, customOperators) : qb;
}

@@ -37,3 +37,3 @@ get options() {

const name = RequestQueryBuilder._options.paramNamesMap[key];
this.paramNames[key] = (0, crud_util_1.isString)(name) ? name : name[0];
this.paramNames[key] = crud_util_1.isString(name) ? name : name[0];
});

@@ -46,8 +46,8 @@ }

}
this.queryString = (0, qs_1.stringify)(this.queryObject, { encode });
this.queryString = qs_1.stringify(this.queryObject, { encode });
return this.queryString;
}
select(fields) {
if ((0, crud_util_1.isArrayFull)(fields)) {
(0, request_query_validator_1.validateFields)(fields);
if (crud_util_1.isArrayFull(fields)) {
request_query_validator_1.validateFields(fields);
this.queryObject[this.paramNames.fields] = fields.join(this.options.delimStr);

@@ -58,3 +58,3 @@ }

search(s) {
if (!(0, crud_util_1.isNil)(s) && (0, crud_util_1.isObject)(s)) {
if (!crud_util_1.isNil(s) && crud_util_1.isObject(s)) {
this.queryObject[this.paramNames.search] = JSON.stringify(s);

@@ -73,7 +73,7 @@ }

setJoin(j) {
if (!(0, crud_util_1.isNil)(j)) {
if (!crud_util_1.isNil(j)) {
const param = this.checkQueryObjectParam('join', []);
this.queryObject[param] = [
...this.queryObject[param],
...(Array.isArray(j) && !(0, crud_util_1.isString)(j[0])
...(Array.isArray(j) && !crud_util_1.isString(j[0])
? j.map((o) => this.addJoin(o))

@@ -86,7 +86,7 @@ : [this.addJoin(j)]),

sortBy(s) {
if (!(0, crud_util_1.isNil)(s)) {
if (!crud_util_1.isNil(s)) {
const param = this.checkQueryObjectParam('sort', []);
this.queryObject[param] = [
...this.queryObject[param],
...(Array.isArray(s) && !(0, crud_util_1.isString)(s[0])
...(Array.isArray(s) && !crud_util_1.isString(s[0])
? s.map((o) => this.addSortBy(o))

@@ -120,3 +120,3 @@ : [this.addSortBy(s)]),

const filter = Array.isArray(f) ? { field: f[0], operator: f[1], value: f[2] } : f;
(0, request_query_validator_1.validateCondition)(filter, cond, customOperators);
request_query_validator_1.validateCondition(filter, cond, customOperators);
const d = this.options.delim;

@@ -126,14 +126,14 @@ return (filter.field +

filter.operator +
((0, crud_util_1.hasValue)(filter.value) ? d + filter.value : ''));
(crud_util_1.hasValue(filter.value) ? d + filter.value : ''));
}
addJoin(j) {
const join = Array.isArray(j) ? { field: j[0], select: j[1] } : j;
(0, request_query_validator_1.validateJoin)(join);
request_query_validator_1.validateJoin(join);
const d = this.options.delim;
const ds = this.options.delimStr;
return join.field + ((0, crud_util_1.isArrayFull)(join.select) ? d + join.select.join(ds) : '');
return join.field + (crud_util_1.isArrayFull(join.select) ? d + join.select.join(ds) : '');
}
addSortBy(s) {
const sort = Array.isArray(s) ? { field: s[0], order: s[1] } : s;
(0, request_query_validator_1.validateSort)(sort);
request_query_validator_1.validateSort(sort);
const ds = this.options.delimStr;

@@ -160,3 +160,3 @@ return sort.field + ds + sort.order;

const param = this.paramNames[cond];
if ((0, crud_util_1.isNil)(this.queryObject[param]) && !(0, crud_util_1.isUndefined)(defaults)) {
if (crud_util_1.isNil(this.queryObject[param]) && !crud_util_1.isUndefined(defaults)) {
this.queryObject[param] = defaults;

@@ -167,7 +167,7 @@ }

setCondition(f, cond, customOperators) {
if (!(0, crud_util_1.isNil)(f)) {
if (!crud_util_1.isNil(f)) {
const param = this.checkQueryObjectParam(cond, []);
this.queryObject[param] = [
...this.queryObject[param],
...(Array.isArray(f) && !(0, crud_util_1.isString)(f[0])
...(Array.isArray(f) && !crud_util_1.isString(f[0])
? f.map((o) => this.cond(o, cond, customOperators))

@@ -179,4 +179,4 @@ : [this.cond(f, cond, customOperators)]),

setNumeric(n, cond) {
if (!(0, crud_util_1.isNil)(n)) {
(0, request_query_validator_1.validateNumeric)(n, cond);
if (!crud_util_1.isNil(n)) {
request_query_validator_1.validateNumeric(n, cond);
this.queryObject[this.paramNames[cond]] = n;

@@ -183,0 +183,0 @@ }

@@ -45,5 +45,5 @@ "use strict";

parseQuery(query, customOperators = {}) {
if ((0, crud_util_1.isObject)(query)) {
const paramNames = (0, crud_util_1.objKeys)(query);
if ((0, crud_util_1.hasLength)(paramNames)) {
if (crud_util_1.isObject(query)) {
const paramNames = crud_util_1.objKeys(query);
if (crud_util_1.hasLength(paramNames)) {
this._query = query;

@@ -53,3 +53,3 @@ this._paramNames = paramNames;

this.search = this.parseSearchQueryParam(searchData);
if ((0, crud_util_1.isNil)(this.search)) {
if (crud_util_1.isNil(this.search)) {
this.filter = this.parseQueryParam('filter', this.conditionParser.bind(this, 'filter', customOperators));

@@ -73,5 +73,5 @@ this.or = this.parseQueryParam('or', this.conditionParser.bind(this, 'or', customOperators));

parseParams(params, options) {
if ((0, crud_util_1.isObject)(params)) {
const paramNames = (0, crud_util_1.objKeys)(params);
if ((0, crud_util_1.hasLength)(paramNames)) {
if (crud_util_1.isObject(params)) {
const paramNames = crud_util_1.objKeys(params);
if (crud_util_1.hasLength(paramNames)) {
this._params = params;

@@ -110,10 +110,10 @@ this._paramsOptions = options;

const name = this._options.paramNamesMap[type];
return (0, crud_util_1.isString)(name) ? name === p : name.some((m) => m === p);
return crud_util_1.isString(name) ? name === p : name.some((m) => m === p);
});
}
getParamValues(value, parser) {
if ((0, crud_util_1.isStringFull)(value)) {
if (crud_util_1.isStringFull(value)) {
return [parser.call(this, value)];
}
if ((0, crud_util_1.isArrayFull)(value)) {
if (crud_util_1.isArrayFull(value)) {
return value.map((val) => parser(val));

@@ -125,3 +125,3 @@ }

const param = this.getParamNames(type);
if ((0, crud_util_1.isArrayFull)(param)) {
if (crud_util_1.isArrayFull(param)) {
return param.reduce((a, name) => [...a, ...this.getParamValues(this._query[name], parser)], []);

@@ -158,3 +158,3 @@ }

const parsed = JSON.parse(val);
if (!(0, crud_util_1.isDate)(parsed) && (0, crud_util_1.isObject)(parsed)) {
if (!crud_util_1.isDate(parsed) && crud_util_1.isObject(parsed)) {
return val;

@@ -169,3 +169,3 @@ }

catch (ignored) {
if ((0, crud_util_1.isDateString)(val)) {
if (crud_util_1.isDateString(val)) {
return new Date(val);

@@ -177,3 +177,3 @@ }

parseValues(vals) {
if ((0, crud_util_1.isArrayFull)(vals)) {
if (crud_util_1.isArrayFull(vals)) {
return vals.map((v) => this.parseValue(v));

@@ -190,7 +190,7 @@ }

try {
if ((0, crud_util_1.isNil)(d)) {
if (crud_util_1.isNil(d)) {
return undefined;
}
const data = JSON.parse(d);
if (!(0, crud_util_1.isObject)(data)) {
if (!crud_util_1.isObject(data)) {
throw new Error();

@@ -214,2 +214,4 @@ }

'$notinL',
'$contArr',
'$intersectsArr',
].concat(Object.keys(customOperators).filter((op) => customOperators[op].isArray));

@@ -225,7 +227,7 @@ const isEmptyValue = ['isnull', 'notnull', '$isnull', '$notnull'];

value = this.parseValues(value);
if (!isEmptyValue.some((name) => name === operator) && !(0, crud_util_1.hasValue)(value)) {
if (!isEmptyValue.some((name) => name === operator) && !crud_util_1.hasValue(value)) {
throw new exceptions_1.RequestQueryException(`Invalid ${cond} value`);
}
const condition = { field, operator, value };
(0, request_query_validator_1.validateCondition)(condition, cond, customOperators);
request_query_validator_1.validateCondition(condition, cond, customOperators);
return condition;

@@ -237,5 +239,5 @@ }

field: param[0],
select: (0, crud_util_1.isStringFull)(param[1]) ? param[1].split(this._options.delimStr) : undefined,
select: crud_util_1.isStringFull(param[1]) ? param[1].split(this._options.delimStr) : undefined,
};
(0, request_query_validator_1.validateJoin)(join);
request_query_validator_1.validateJoin(join);
return join;

@@ -249,3 +251,3 @@ }

};
(0, request_query_validator_1.validateSort)(sort);
request_query_validator_1.validateSort(sort);
return sort;

@@ -255,7 +257,7 @@ }

const val = this.parseValue(data);
(0, request_query_validator_1.validateNumeric)(val, num);
request_query_validator_1.validateNumeric(val, num);
return val;
}
paramParser(name) {
(0, request_query_validator_1.validateParamOption)(this._paramsOptions, name);
request_query_validator_1.validateParamOption(this._paramsOptions, name);
const option = this._paramsOptions[name];

@@ -269,6 +271,6 @@ if (option.disabled) {

value = this.parseValue(value);
(0, request_query_validator_1.validateNumeric)(value, `param ${name}`);
request_query_validator_1.validateNumeric(value, `param ${name}`);
break;
case 'uuid':
(0, request_query_validator_1.validateUUID)(value, name);
request_query_validator_1.validateUUID(value, name);
break;

@@ -275,0 +277,0 @@ default:

@@ -23,6 +23,8 @@ "use strict";

'between',
'contArr',
'intersectsArr',
];
exports.comparisonOperatorsList = [
...exports.deprecatedComparisonOperatorsList,
...(0, crud_util_1.objKeys)(types_1.CondOperator).map((n) => types_1.CondOperator[n]),
...crud_util_1.objKeys(types_1.CondOperator).map((n) => types_1.CondOperator[n]),
];

@@ -32,3 +34,3 @@ exports.sortOrdersList = ['ASC', 'DESC'];

function validateFields(fields) {
if (!(0, crud_util_1.isArrayStrings)(fields)) {
if (!crud_util_1.isArrayStrings(fields)) {
throw new exceptions_1.RequestQueryException('Invalid fields. Array of strings expected');

@@ -39,3 +41,3 @@ }

function validateCondition(val, cond, customOperators) {
if (!(0, crud_util_1.isObject)(val) || !(0, crud_util_1.isStringFull)(val.field)) {
if (!crud_util_1.isObject(val) || !crud_util_1.isStringFull(val.field)) {
throw new exceptions_1.RequestQueryException(`Invalid field type in ${cond} condition. String expected`);

@@ -57,6 +59,6 @@ }

function validateJoin(join) {
if (!(0, crud_util_1.isObject)(join) || !(0, crud_util_1.isStringFull)(join.field)) {
if (!crud_util_1.isObject(join) || !crud_util_1.isStringFull(join.field)) {
throw new exceptions_1.RequestQueryException('Invalid join field. String expected');
}
if (!(0, crud_util_1.isUndefined)(join.select) && !(0, crud_util_1.isArrayStrings)(join.select)) {
if (!crud_util_1.isUndefined(join.select) && !crud_util_1.isArrayStrings(join.select)) {
throw new exceptions_1.RequestQueryException('Invalid join select. Array of strings expected');

@@ -67,7 +69,7 @@ }

function validateSort(sort) {
if (!(0, crud_util_1.isObject)(sort) || !(0, crud_util_1.isStringFull)(sort.field)) {
if (!crud_util_1.isObject(sort) || !crud_util_1.isStringFull(sort.field)) {
throw new exceptions_1.RequestQueryException('Invalid sort field. String expected');
}
if (!(0, crud_util_1.isEqual)(sort.order, exports.sortOrdersList[0]) &&
!(0, crud_util_1.isEqual)(sort.order, exports.sortOrdersList[1])) {
if (!crud_util_1.isEqual(sort.order, exports.sortOrdersList[0]) &&
!crud_util_1.isEqual(sort.order, exports.sortOrdersList[1])) {
throw new exceptions_1.RequestQueryException(`Invalid sort order. ${sortOrdersListStr} expected`);

@@ -78,3 +80,3 @@ }

function validateNumeric(val, num) {
if (!(0, crud_util_1.isNumber)(val)) {
if (!crud_util_1.isNumber(val)) {
throw new exceptions_1.RequestQueryException(`Invalid ${num}. Number expected`);

@@ -85,3 +87,3 @@ }

function validateParamOption(options, name) {
if (!(0, crud_util_1.isObject)(options)) {
if (!crud_util_1.isObject(options)) {
throw new exceptions_1.RequestQueryException(`Invalid param ${name}. Invalid crud options`);

@@ -93,3 +95,3 @@ }

}
if (!(0, crud_util_1.isObject)(option) || (0, crud_util_1.isNil)(option.field) || (0, crud_util_1.isNil)(option.type)) {
if (!crud_util_1.isObject(option) || crud_util_1.isNil(option.field) || crud_util_1.isNil(option.type)) {
throw new exceptions_1.RequestQueryException(`Invalid param option in Crud`);

@@ -96,0 +98,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {

@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k;

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

export type ParamOptionType = 'number' | 'string' | 'uuid';
export declare type ParamOptionType = 'number' | 'string' | 'uuid';

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

export type QueryFields = string[];
export declare type QueryFields = string[];
export interface QueryFilter {

@@ -7,3 +7,3 @@ field: string;

}
export type QueryFilterArr = [string, ComparisonOperator, any?];
export declare type QueryFilterArr = [string, ComparisonOperator, any?];
export interface QueryJoin {

@@ -13,3 +13,3 @@ field: string;

}
export type QueryJoinArr = [string, QueryFields?];
export declare type QueryJoinArr = [string, QueryFields?];
export interface QuerySort {

@@ -19,6 +19,6 @@ field: string;

}
export type QueryExtra = any | undefined;
export type QuerySortArr = [string, QuerySortOperator];
export type QuerySortOperator = 'ASC' | 'DESC';
type DeprecatedCondOperator = 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'starts' | 'ends' | 'cont' | 'excl' | 'in' | 'notin' | 'isnull' | 'notnull' | 'between';
export declare type QueryExtra = any | undefined;
export declare type QuerySortArr = [string, QuerySortOperator];
export declare type QuerySortOperator = 'ASC' | 'DESC';
declare type DeprecatedCondOperator = 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'starts' | 'ends' | 'cont' | 'excl' | 'in' | 'notin' | 'isnull' | 'notnull' | 'between' | 'contArr' | 'intersectsArr';
export declare enum CondOperator {

@@ -47,31 +47,36 @@ EQUALS = "$eq",

IN_LOW = "$inL",
NOT_IN_LOW = "$notinL"
NOT_IN_LOW = "$notinL",
CONTAINS_ARRAY = "$contArr",
INTERSECTS_ARRAY = "$intersectsArr"
}
export type ComparisonOperator = DeprecatedCondOperator | keyof SFieldOperator | string;
export type SPrimitivesVal = string | number | boolean;
export type SFiledValues = SPrimitivesVal | SPrimitivesVal[];
export declare type ComparisonOperator = DeprecatedCondOperator | keyof SFieldOperator | string;
export declare type SPrimitivesVal = string | number | boolean;
export declare type SFieldValues = SPrimitivesVal | Array<SPrimitivesVal>;
export declare type SFiledValues = SFieldValues;
export interface SFieldOperator {
$eq?: SFiledValues;
$ne?: SFiledValues;
$gt?: SFiledValues;
$lt?: SFiledValues;
$gte?: SFiledValues;
$lte?: SFiledValues;
$starts?: SFiledValues;
$ends?: SFiledValues;
$cont?: SFiledValues;
$excl?: SFiledValues;
$in?: SFiledValues;
$notin?: SFiledValues;
$between?: SFiledValues;
$isnull?: SFiledValues;
$notnull?: SFiledValues;
$eqL?: SFiledValues;
$neL?: SFiledValues;
$startsL?: SFiledValues;
$endsL?: SFiledValues;
$contL?: SFiledValues;
$exclL?: SFiledValues;
$inL?: SFiledValues;
$notinL?: SFiledValues;
$eq?: SFieldValues;
$ne?: SFieldValues;
$gt?: SFieldValues;
$lt?: SFieldValues;
$gte?: SFieldValues;
$lte?: SFieldValues;
$starts?: SFieldValues;
$ends?: SFieldValues;
$cont?: SFieldValues;
$excl?: SFieldValues;
$in?: SFieldValues;
$notin?: SFieldValues;
$between?: SFieldValues;
$isnull?: SFieldValues;
$notnull?: SFieldValues;
$eqL?: SFieldValues;
$neL?: SFieldValues;
$startsL?: SFieldValues;
$endsL?: SFieldValues;
$contL?: SFieldValues;
$exclL?: SFieldValues;
$inL?: SFieldValues;
$notinL?: SFieldValues;
$contArr?: Array<SPrimitivesVal>;
$intersectsArr?: Array<SPrimitivesVal>;
$or?: SFieldOperator;

@@ -81,4 +86,4 @@ $and?: never;

}
export type SField = SPrimitivesVal | SFieldOperator | {
[$custom: string]: SFiledValues;
export declare type SField = SPrimitivesVal | SFieldOperator | {
[$custom: string]: SFieldValues;
};

@@ -101,4 +106,4 @@ export interface SFields {

}
export type SConditionKey = '$and' | '$or' | '$not';
export type SCondition = SFields | SConditionAND | SConditionNOT;
export declare type SConditionKey = '$and' | '$or' | '$not';
export declare type SCondition = SFields | SConditionAND | SConditionNOT;
export {};

@@ -29,3 +29,5 @@ "use strict";

CondOperator["NOT_IN_LOW"] = "$notinL";
})(CondOperator || (exports.CondOperator = CondOperator = {}));
CondOperator["CONTAINS_ARRAY"] = "$contArr";
CondOperator["INTERSECTS_ARRAY"] = "$intersectsArr";
})(CondOperator = exports.CondOperator || (exports.CondOperator = {}));
//# sourceMappingURL=request-query.types.js.map
{
"name": "@dataui/crud-request",
"description": "NestJs CRUD for RESTful APIs - request query builder",
"version": "5.3.1-alpha.3",
"version": "5.3.1",
"license": "MIT",

@@ -51,6 +51,6 @@ "main": "lib/index.js",

"dependencies": {
"@dataui/crud-util": "^5.3.1-alpha.3",
"@dataui/crud-util": "^5.3.1",
"qs": "^6.8.0"
},
"gitHead": "5acf14b6f5057bf8b92c31a34ddd19543bd6358a"
"gitHead": "bb89c0ca59a5bca1b57cd8f2f7370a6d281eeb70"
}

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

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