@dataui/crud-request
Advanced tools
Comparing version 5.3.3 to 5.3.4
@@ -7,2 +7,3 @@ import { CreateQueryParams, CustomOperators, RequestQueryBuilderOptions } from './interfaces'; | ||
private paramNames; | ||
private joinConditionString; | ||
queryObject: { | ||
@@ -9,0 +10,0 @@ [key: string]: any; |
@@ -10,2 +10,7 @@ "use strict"; | ||
this.paramNames = {}; | ||
this.joinConditionString = { | ||
encode: false, | ||
delimiter: this.options.delimStr, | ||
arrayFormat: 'indices', | ||
}; | ||
this.queryObject = {}; | ||
@@ -122,8 +127,19 @@ this.setParamNames(); | ||
} | ||
addJoin(j) { | ||
const join = Array.isArray(j) ? { field: j[0], select: j[1] } : j; | ||
request_query_validator_1.validateJoin(join); | ||
const d = this.options.delim; | ||
const ds = this.options.delimStr; | ||
return join.field + (crud_util_1.isArrayFull(join.select) ? d + join.select.join(ds) : ''); | ||
addJoin(join) { | ||
const { delim, delimStr } = this.options; | ||
const normalizedJoin = Array.isArray(join) | ||
? { field: join[0], select: join[1], on: join[2] } | ||
: join; | ||
request_query_validator_1.validateJoin(normalizedJoin); | ||
const conditions = crud_util_1.isArrayFull(normalizedJoin.on) | ||
? { on: normalizedJoin.on.map((condition) => this.cond(condition, 'filter')) } | ||
: ''; | ||
const fieldPart = normalizedJoin.field; | ||
const selectPart = crud_util_1.isArrayFull(normalizedJoin.select) | ||
? delim + normalizedJoin.select.join(delimStr) | ||
: ''; | ||
const conditionsPart = conditions | ||
? delim + qs_1.stringify(conditions, this.joinConditionString) | ||
: ''; | ||
return fieldPart + selectPart + conditionsPart; | ||
} | ||
@@ -130,0 +146,0 @@ addSortBy(s) { |
@@ -25,2 +25,3 @@ import { ObjectLiteral } from '@dataui/crud-util'; | ||
private _paramsOptions; | ||
private _joinConditionParseOptions; | ||
private get _options(); | ||
@@ -44,2 +45,3 @@ static create(): RequestQueryParser; | ||
private conditionParser; | ||
private parseJoinConditions; | ||
private joinParser; | ||
@@ -46,0 +48,0 @@ private sortParser; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const request_query_validator_1 = require("./request-query.validator"); | ||
const qs_1 = require("qs"); | ||
class RequestQueryParser { | ||
@@ -19,2 +20,5 @@ constructor() { | ||
this.sort = []; | ||
this._joinConditionParseOptions = { | ||
delimiter: this._options.delimStr, | ||
}; | ||
} | ||
@@ -226,7 +230,15 @@ get _options() { | ||
} | ||
parseJoinConditions(conditionsString) { | ||
const conditions = qs_1.parse(conditionsString, this._joinConditionParseOptions)['on']; | ||
return conditions.map((cond) => this.conditionParser('filter', {}, cond)); | ||
} | ||
joinParser(data) { | ||
const param = data.split(this._options.delim); | ||
const field = param[0]; | ||
const selectString = param[1]; | ||
const conditions = param.slice(2).join(this._options.delim); | ||
const join = { | ||
field: param[0], | ||
select: crud_util_1.isStringFull(param[1]) ? param[1].split(this._options.delimStr) : undefined, | ||
field, | ||
select: selectString ? selectString.split(this._options.delimStr) : undefined, | ||
on: crud_util_1.isStringFull(conditions) ? this.parseJoinConditions(conditions) : undefined, | ||
}; | ||
@@ -233,0 +245,0 @@ request_query_validator_1.validateJoin(join); |
@@ -62,2 +62,5 @@ "use strict"; | ||
} | ||
if (!crud_util_1.isUndefined(join.on) && !crud_util_1.isArrayFull(join.on)) { | ||
join.on.map((condition) => validateCondition(condition, 'filter', {})); | ||
} | ||
} | ||
@@ -64,0 +67,0 @@ exports.validateJoin = validateJoin; |
@@ -11,4 +11,5 @@ export declare type QueryFields = string[]; | ||
select?: QueryFields; | ||
on?: QueryFilter[]; | ||
} | ||
export declare type QueryJoinArr = [string, QueryFields?]; | ||
export declare type QueryJoinArr = [string, QueryFields?, QueryFilter[]?]; | ||
export interface QuerySort { | ||
@@ -15,0 +16,0 @@ field: string; |
{ | ||
"name": "@dataui/crud-request", | ||
"description": "NestJs CRUD for RESTful APIs - request query builder", | ||
"version": "5.3.3", | ||
"version": "5.3.4", | ||
"license": "MIT", | ||
@@ -51,6 +51,6 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@dataui/crud-util": "^5.3.3", | ||
"@dataui/crud-util": "^5.3.4", | ||
"qs": "^6.8.0" | ||
}, | ||
"gitHead": "b6c71c5a374b81b0e8719044f5c562d751694ca6" | ||
"gitHead": "61fffe76017d4c21cecf7ea19a8111a64e7f0017" | ||
} |
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
69746
994
Updated@dataui/crud-util@^5.3.4