ts-dynamic-query
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -29,2 +29,8 @@ import { FilterCondition } from "./enums/FilterCondition"; | ||
declare const _bitwiseAll: FilterOperator; | ||
export { FilterCondition, FilterOperator, SortDirection, DynamicQuery, FilterDescriptor, BaseFilterDescriptor as FilterDescriptorBase, FilterGroupDescriptor, FilterGroupOptions, FilterOptions, SortDescriptor, BaseSortDescriptor as SortDescriptorBase, SortOptions, QueryProvider, _lessThan, _lessThanOrEqual, _equal, _notEqual, _greaterThan, _greaterThanOrEqual, _startWith, _endWith, _contains, _in, _notIn, _between, _bitwiseAny, _bitwiseZero, _bitwiseAll, }; | ||
declare const _asc: SortDirection; | ||
declare const _ascNullFirst: SortDirection; | ||
declare const _ascNullLast: SortDirection; | ||
declare const _desc: SortDirection; | ||
declare const _descNullFirst: SortDirection; | ||
declare const _descNullLast: SortDirection; | ||
export { FilterCondition, FilterOperator, SortDirection, DynamicQuery, FilterDescriptor, BaseFilterDescriptor as FilterDescriptorBase, FilterGroupDescriptor, FilterGroupOptions, FilterOptions, SortDescriptor, BaseSortDescriptor as SortDescriptorBase, SortOptions, QueryProvider, _lessThan, _lessThanOrEqual, _equal, _notEqual, _greaterThan, _greaterThanOrEqual, _startWith, _endWith, _contains, _in, _notIn, _between, _bitwiseAny, _bitwiseZero, _bitwiseAll, _asc, _ascNullFirst, _ascNullLast, _desc, _descNullFirst, _descNullLast }; |
@@ -51,2 +51,14 @@ "use strict"; | ||
exports._bitwiseAll = _bitwiseAll; | ||
var _asc = SortDirection_1.SortDirection.ASC; | ||
exports._asc = _asc; | ||
var _ascNullFirst = SortDirection_1.SortDirection.ASC_NULL_FIRST; | ||
exports._ascNullFirst = _ascNullFirst; | ||
var _ascNullLast = SortDirection_1.SortDirection.ASC_NULL_LAST; | ||
exports._ascNullLast = _ascNullLast; | ||
var _desc = SortDirection_1.SortDirection.DESC; | ||
exports._desc = _desc; | ||
var _descNullFirst = SortDirection_1.SortDirection.DESC_NULL_FIRST; | ||
exports._descNullFirst = _descNullFirst; | ||
var _descNullLast = SortDirection_1.SortDirection.DESC_NULL_LAST; | ||
exports._descNullLast = _descNullLast; | ||
//# sourceMappingURL=index.js.map |
@@ -6,14 +6,19 @@ import { BaseSortDescriptor } from "./BaseSortDescriptor"; | ||
import { BaseFilterGroup } from "./BaseFilterGroup"; | ||
import { SortDirection } from "../enums/SortDirection"; | ||
export declare class DynamicQuery<T> extends BaseFilterGroup<T> { | ||
type: new () => T; | ||
sorts: BaseSortDescriptor[]; | ||
selectedProperties: string[]; | ||
private sorts; | ||
private selectedProperties; | ||
constructor(); | ||
static createQuery<T>(type: new () => T): DynamicQuery<T>; | ||
addFilterDescriptor(option: FilterOptions<T>): DynamicQuery<T>; | ||
addFilterGroupDescriptor(option: FilterGroupOptions<T>): DynamicQuery<T>; | ||
addSorts(sorts: BaseSortDescriptor[]): DynamicQuery<T>; | ||
addSortDescriptor(sortOption: SortOptions<T>): DynamicQuery<T>; | ||
selectProperty(property: keyof T): DynamicQuery<T>; | ||
selectProperties(...properties: (keyof T)[]): DynamicQuery<T>; | ||
addFilterDescriptor(option: FilterOptions<T>): this; | ||
addFilterGroupDescriptor(option: FilterGroupOptions<T>): this; | ||
addSort(sort: BaseSortDescriptor): this; | ||
addSorts(sorts: BaseSortDescriptor[]): this; | ||
addSortDescriptor(sortOption: SortOptions<T>): this; | ||
selectProperty(property: keyof T): this; | ||
selectProperties(...properties: (keyof T)[]): this; | ||
orderBy(propertyPath: keyof T, direction?: SortDirection): this; | ||
getSorts(): BaseSortDescriptor[]; | ||
getSelectedProperties(): string[]; | ||
query(datas: T[]): T[]; | ||
@@ -20,0 +25,0 @@ toJSON(): string; |
@@ -26,2 +26,3 @@ "use strict"; | ||
var BaseFilterGroup_1 = require("./BaseFilterGroup"); | ||
var SortDirection_1 = require("../enums/SortDirection"); | ||
var DynamicQuery = /** @class */ (function (_super) { | ||
@@ -58,2 +59,5 @@ __extends(DynamicQuery, _super); | ||
}; | ||
DynamicQuery.prototype.addSort = function (sort) { | ||
return this.addSorts([sort]); | ||
}; | ||
DynamicQuery.prototype.addSorts = function (sorts) { | ||
@@ -82,2 +86,15 @@ this.sorts = this.sorts.concat(sorts); | ||
}; | ||
DynamicQuery.prototype.orderBy = function (propertyPath, direction) { | ||
return this.addSortDescriptor({ | ||
propertyPath: propertyPath, | ||
// 默认升序 | ||
direction: ts_commons_1.ObjectUtils.getOrDefault(direction, SortDirection_1.SortDirection.ASC), | ||
}); | ||
}; | ||
DynamicQuery.prototype.getSorts = function () { | ||
return this.sorts; | ||
}; | ||
DynamicQuery.prototype.getSelectedProperties = function () { | ||
return this.selectedProperties; | ||
}; | ||
DynamicQuery.prototype.query = function (datas) { | ||
@@ -84,0 +101,0 @@ return QueryProvider_1.QueryProvider.query(datas, this); |
@@ -23,10 +23,10 @@ "use strict"; | ||
} | ||
if (ts_commons_1.ArrayUtils.isNotEmpty(query.sorts)) { | ||
if (ts_commons_1.ArrayUtils.isNotEmpty(query.getSorts())) { | ||
cloneDatas = cloneDatas.sort(function (obj1, obj2) { | ||
return SortHelper_1.SortHelper.predicateBySorts(obj1, obj2, query.sorts); | ||
return SortHelper_1.SortHelper.predicateBySorts(obj1, obj2, query.getSorts()); | ||
}); | ||
} | ||
if (ts_commons_1.ArrayUtils.isNotEmpty(query.selectedProperties)) { | ||
if (ts_commons_1.ArrayUtils.isNotEmpty(query.getSelectedProperties())) { | ||
cloneDatas = cloneDatas.map(function (x) { | ||
return _this.pick(query.type, x, query.selectedProperties); | ||
return _this.pick(query.type, x, query.getSelectedProperties()); | ||
}); | ||
@@ -33,0 +33,0 @@ } |
{ | ||
"name": "ts-dynamic-query", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "", | ||
@@ -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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
190729
1396
0