@eienjs/adonisjs-api-query 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE.md → LICENSE} +1 -1
- package/README.md +28 -2
- package/build/configure.d.ts +6 -2
- package/build/configure.js +11 -0
- package/build/index.d.ts +32 -31
- package/build/index.js +31 -153
- package/build/providers/api_query_provider.d.ts +41 -37
- package/build/providers/api_query_provider.js +21 -26
- package/build/src/allowed_filter.d.ts +40 -36
- package/build/src/allowed_filter.js +113 -0
- package/build/src/allowed_include.d.ts +20 -16
- package/build/src/allowed_include.js +48 -0
- package/build/src/allowed_sort.d.ts +21 -17
- package/build/src/allowed_sort.js +50 -0
- package/build/src/api_query_builder_request.d.ts +34 -30
- package/build/src/api_query_builder_request.js +122 -0
- package/build/src/bindings/api_query_request.js +13 -0
- package/build/src/bindings/filters_query.js +40 -0
- package/build/src/bindings/includes_query.js +51 -0
- package/build/src/bindings/sorts_query.js +45 -0
- package/build/src/define_config.d.ts +7 -3
- package/build/src/define_config.js +25 -0
- package/build/src/enums/filter_operator.d.ts +11 -9
- package/build/src/enums/filter_operator.js +12 -0
- package/build/src/enums/sort_direction.d.ts +6 -4
- package/build/src/enums/sort_direction.js +7 -0
- package/build/src/exceptions/allowed_fields_must_be_called_before_allowed_includes.d.ts +9 -5
- package/build/src/exceptions/allowed_fields_must_be_called_before_allowed_includes.js +11 -0
- package/build/src/exceptions/invalid_append_query.d.ts +8 -4
- package/build/src/exceptions/invalid_append_query.js +14 -0
- package/build/src/exceptions/invalid_direction.d.ts +7 -3
- package/build/src/exceptions/invalid_direction.js +10 -0
- package/build/src/exceptions/invalid_filter_query.d.ts +10 -6
- package/build/src/exceptions/invalid_filter_query.js +18 -0
- package/build/src/exceptions/invalid_filter_value.d.ts +7 -3
- package/build/src/exceptions/invalid_filter_value.js +9 -0
- package/build/src/exceptions/invalid_include_query.d.ts +10 -6
- package/build/src/exceptions/invalid_include_query.js +22 -0
- package/build/src/exceptions/invalid_query.d.ts +7 -3
- package/build/src/exceptions/invalid_query.js +7 -0
- package/build/src/exceptions/invalid_sort_query.d.ts +10 -6
- package/build/src/exceptions/invalid_sort_query.js +18 -0
- package/build/src/exceptions/unknown_included_fields_query.d.ts +8 -4
- package/build/src/exceptions/unknown_included_fields_query.js +13 -0
- package/build/src/filters/filters_begin_with_strict.d.ts +10 -6
- package/build/src/filters/filters_begin_with_strict.js +9 -0
- package/build/src/filters/filters_callback.d.ts +10 -6
- package/build/src/filters/filters_callback.js +12 -0
- package/build/src/filters/filters_ends_with_strict.d.ts +10 -6
- package/build/src/filters/filters_ends_with_strict.js +9 -0
- package/build/src/filters/filters_exact.d.ts +15 -11
- package/build/src/filters/filters_exact.js +47 -0
- package/build/src/filters/filters_operator.d.ts +17 -13
- package/build/src/filters/filters_operator.js +53 -0
- package/build/src/filters/filters_partial.d.ts +15 -11
- package/build/src/filters/filters_partial.js +39 -0
- package/build/src/filters/filters_trashed.d.ts +9 -5
- package/build/src/filters/filters_trashed.js +14 -0
- package/build/src/includes/included_callback.d.ts +11 -7
- package/build/src/includes/included_callback.js +12 -0
- package/build/src/includes/included_count.d.ts +8 -4
- package/build/src/includes/included_count.js +11 -0
- package/build/src/includes/included_relationship.d.ts +12 -8
- package/build/src/includes/included_relationship.js +40 -0
- package/build/src/sorts/sorts_callback.d.ts +10 -6
- package/build/src/sorts/sorts_callback.js +12 -0
- package/build/src/sorts/sorts_field.d.ts +8 -4
- package/build/src/sorts/sorts_field.js +8 -0
- package/build/src/utils/helpers.js +26 -0
- package/build/stubs/main.d.ts +4 -1
- package/build/stubs/main.js +4 -0
- package/build/types.d.ts +91 -0
- package/build/types.js +1 -0
- package/package.json +99 -88
- package/build/api_query_request-QXOB4BN6.js +0 -18
- package/build/api_query_request-QXOB4BN6.js.map +0 -1
- package/build/chunk-3ITWUZL5.js +0 -108
- package/build/chunk-3ITWUZL5.js.map +0 -1
- package/build/chunk-54HNQTDY.js +0 -348
- package/build/chunk-54HNQTDY.js.map +0 -1
- package/build/chunk-IV3B5WO7.js +0 -160
- package/build/chunk-IV3B5WO7.js.map +0 -1
- package/build/chunk-MKQ3HMMA.js +0 -198
- package/build/chunk-MKQ3HMMA.js.map +0 -1
- package/build/chunk-XIRHVLVQ.js +0 -10
- package/build/chunk-XIRHVLVQ.js.map +0 -1
- package/build/filters_query-LCFH2F2X.js +0 -55
- package/build/filters_query-LCFH2F2X.js.map +0 -1
- package/build/includes_query-PVONWQMC.js +0 -70
- package/build/includes_query-PVONWQMC.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/metafile-esm.json +0 -1
- package/build/providers/api_query_provider.js.map +0 -1
- package/build/sorts_query-NJTC5UXX.js +0 -63
- package/build/sorts_query-NJTC5UXX.js.map +0 -1
- package/build/src/bindings/api_query_request.d.ts +0 -2
- package/build/src/bindings/filters_query.d.ts +0 -3
- package/build/src/bindings/includes_query.d.ts +0 -3
- package/build/src/bindings/sorts_query.d.ts +0 -3
- package/build/src/exceptions/invalid_field_query.d.ts +0 -5
- package/build/src/types.d.ts +0 -90
- package/build/src/types.js +0 -1
- package/build/src/types.js.map +0 -1
- package/build/src/utils/helpers.d.ts +0 -3
- /package/build/{config.stub → stubs/config.stub} +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { configProvider } from "@adonisjs/core";
|
|
2
|
+
//#region src/define_config.ts
|
|
3
|
+
const defineConfig = function(config) {
|
|
4
|
+
return configProvider.create(async (_) => {
|
|
5
|
+
return {
|
|
6
|
+
parameters: {
|
|
7
|
+
include: config.parameters?.include ?? "include",
|
|
8
|
+
filter: config.parameters?.filter ?? "filter",
|
|
9
|
+
sort: config.parameters?.sort ?? "sort",
|
|
10
|
+
fields: config.parameters?.fields ?? "fields",
|
|
11
|
+
append: config.parameters?.append ?? "append"
|
|
12
|
+
},
|
|
13
|
+
countSuffix: config.countSuffix ?? "Count",
|
|
14
|
+
existsSuffix: config.existsSuffix ?? "Exists",
|
|
15
|
+
disableInvalidFilterQueryException: config.disableInvalidFilterQueryException ?? false,
|
|
16
|
+
disableInvalidSortQueryException: config.disableInvalidSortQueryException ?? false,
|
|
17
|
+
disableInvalidIncludesQueryException: config.disableInvalidIncludesQueryException ?? false,
|
|
18
|
+
convertRelationNamesToSnakeCasePlural: config.convertRelationNamesToSnakeCasePlural ?? false,
|
|
19
|
+
convertRelationTableNameStrategy: config.convertRelationTableNameStrategy ?? false,
|
|
20
|
+
convertFieldNamesToSnakeCase: config.convertFieldNamesToSnakeCase ?? false
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { defineConfig };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//#region src/enums/filter_operator.d.ts
|
|
2
|
+
declare const FilterOperator: {
|
|
3
|
+
readonly Dynamic: "";
|
|
4
|
+
readonly Equal: "=";
|
|
5
|
+
readonly LessThan: "<";
|
|
6
|
+
readonly GreaterThan: ">";
|
|
7
|
+
readonly LessThanOrEqual: "<=";
|
|
8
|
+
readonly GreaterThanOrEqual: ">=";
|
|
9
|
+
readonly NotEqual: "<>";
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
//#endregion
|
|
12
|
+
export { FilterOperator };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/enums/sort_direction.d.ts
|
|
2
|
+
declare const SortDirection: {
|
|
3
|
+
readonly Ascending: "asc";
|
|
4
|
+
readonly Descending: "desc";
|
|
4
5
|
};
|
|
5
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
export { SortDirection };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { Exception } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
2
|
+
|
|
3
|
+
//#region src/exceptions/allowed_fields_must_be_called_before_allowed_includes.d.ts
|
|
4
|
+
declare class AllowedFieldsMustBeCalledBeforeAllowedIncludes extends Exception {
|
|
5
|
+
static readonly code: 'E_BAD_METHOD_CALL_EXCEPTION';
|
|
6
|
+
static readonly status: 500;
|
|
7
|
+
constructor();
|
|
6
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { AllowedFieldsMustBeCalledBeforeAllowedIncludes };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
2
|
+
//#region src/exceptions/allowed_fields_must_be_called_before_allowed_includes.ts
|
|
3
|
+
var AllowedFieldsMustBeCalledBeforeAllowedIncludes = class extends Exception {
|
|
4
|
+
static code;
|
|
5
|
+
static status;
|
|
6
|
+
constructor() {
|
|
7
|
+
super("The QueryBuilder's `allowedFields` method must be called before the `allowedIncludes` method");
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { AllowedFieldsMustBeCalledBeforeAllowedIncludes };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { InvalidQuery } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { InvalidQuery } from "./invalid_query.js";
|
|
2
|
+
|
|
3
|
+
//#region src/exceptions/invalid_append_query.d.ts
|
|
4
|
+
declare class InvalidAppendQuery extends InvalidQuery {
|
|
5
|
+
constructor(appendsNotAllowed: string[], allowedAppends: string[]);
|
|
6
|
+
static appendsNotAllowed(appendsNotAllowed: string[], allowedAppends: string[]): InvalidAppendQuery;
|
|
5
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { InvalidAppendQuery };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InvalidQuery } from "./invalid_query.js";
|
|
2
|
+
import { ResponseStatus } from "@adonisjs/core/http";
|
|
3
|
+
//#region src/exceptions/invalid_append_query.ts
|
|
4
|
+
var InvalidAppendQuery = class InvalidAppendQuery extends InvalidQuery {
|
|
5
|
+
constructor(appendsNotAllowed, allowedAppends) {
|
|
6
|
+
const message = `Requested append(s) \`${appendsNotAllowed.join(", ")}\` are not allowed. Allowed append(s) are \`${allowedAppends.join(", ")}\``;
|
|
7
|
+
super(message, { status: ResponseStatus.BadRequest });
|
|
8
|
+
}
|
|
9
|
+
static appendsNotAllowed(appendsNotAllowed, allowedAppends) {
|
|
10
|
+
return new InvalidAppendQuery(appendsNotAllowed, allowedAppends);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { InvalidAppendQuery };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { Exception } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
2
|
+
|
|
3
|
+
//#region src/exceptions/invalid_direction.d.ts
|
|
4
|
+
declare class InvalidDirection extends Exception {
|
|
5
|
+
static make(sort: string): InvalidDirection;
|
|
4
6
|
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { InvalidDirection };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SortDirection } from "../enums/sort_direction.js";
|
|
2
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
3
|
+
//#region src/exceptions/invalid_direction.ts
|
|
4
|
+
var InvalidDirection = class InvalidDirection extends Exception {
|
|
5
|
+
static make(sort) {
|
|
6
|
+
return new InvalidDirection(`The direction should be either \`${SortDirection.Descending}\` or \`${SortDirection.Ascending}\` ${sort} given`);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { InvalidDirection };
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { InvalidQuery } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { InvalidQuery } from "./invalid_query.js";
|
|
2
|
+
|
|
3
|
+
//#region src/exceptions/invalid_filter_query.d.ts
|
|
4
|
+
declare class InvalidFilterQuery extends InvalidQuery {
|
|
5
|
+
readonly unknownFilters: string[];
|
|
6
|
+
readonly allowedFilters: string[];
|
|
7
|
+
constructor(unknownFilters: string[], allowedFilters: string[]);
|
|
8
|
+
static filtersNotAllowed(unknownFilters: string[], allowedFilters: string[]): InvalidFilterQuery;
|
|
7
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { InvalidFilterQuery };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InvalidQuery } from "./invalid_query.js";
|
|
2
|
+
import { ResponseStatus } from "@adonisjs/core/http";
|
|
3
|
+
//#region src/exceptions/invalid_filter_query.ts
|
|
4
|
+
var InvalidFilterQuery = class InvalidFilterQuery extends InvalidQuery {
|
|
5
|
+
unknownFilters;
|
|
6
|
+
allowedFilters;
|
|
7
|
+
constructor(unknownFilters, allowedFilters) {
|
|
8
|
+
const message = `Requested filter(s) \`${unknownFilters.join(", ")}\` are not allowed. Allowed filter(s) are \`${allowedFilters.join(", ")}\``;
|
|
9
|
+
super(message, { status: ResponseStatus.BadRequest });
|
|
10
|
+
this.unknownFilters = unknownFilters;
|
|
11
|
+
this.allowedFilters = allowedFilters;
|
|
12
|
+
}
|
|
13
|
+
static filtersNotAllowed(unknownFilters, allowedFilters) {
|
|
14
|
+
return new InvalidFilterQuery(unknownFilters, allowedFilters);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { InvalidFilterQuery };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { Exception } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
2
|
+
|
|
3
|
+
//#region src/exceptions/invalid_filter_value.d.ts
|
|
4
|
+
declare class InvalidFilterValue extends Exception {
|
|
5
|
+
static make(value: unknown): InvalidFilterValue;
|
|
4
6
|
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { InvalidFilterValue };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
2
|
+
//#region src/exceptions/invalid_filter_value.ts
|
|
3
|
+
var InvalidFilterValue = class InvalidFilterValue extends Exception {
|
|
4
|
+
static make(value) {
|
|
5
|
+
return new InvalidFilterValue(`Filter value \`${value}\` is invalid`);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { InvalidFilterValue };
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { InvalidQuery } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { InvalidQuery } from "./invalid_query.js";
|
|
2
|
+
|
|
3
|
+
//#region src/exceptions/invalid_include_query.d.ts
|
|
4
|
+
declare class InvalidIncludeQuery extends InvalidQuery {
|
|
5
|
+
readonly unknownIncludes: string[];
|
|
6
|
+
readonly allowedIncludes: string[];
|
|
7
|
+
constructor(unknownIncludes: string[], allowedIncludes: string[]);
|
|
8
|
+
static includesNotAllowed(unknownIncludes: string[], allowedIncludes: string[]): InvalidIncludeQuery;
|
|
7
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { InvalidIncludeQuery };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { InvalidQuery } from "./invalid_query.js";
|
|
2
|
+
import { ResponseStatus } from "@adonisjs/core/http";
|
|
3
|
+
//#region src/exceptions/invalid_include_query.ts
|
|
4
|
+
var InvalidIncludeQuery = class InvalidIncludeQuery extends InvalidQuery {
|
|
5
|
+
unknownIncludes;
|
|
6
|
+
allowedIncludes;
|
|
7
|
+
constructor(unknownIncludes, allowedIncludes) {
|
|
8
|
+
let message = `Requested include(s) \`${unknownIncludes.join(", ")}\` are not allowed. `;
|
|
9
|
+
if (allowedIncludes.length > 0) {
|
|
10
|
+
const allowed = allowedIncludes.join(", ");
|
|
11
|
+
message += `Allowed include(s) are \`${allowed}\``;
|
|
12
|
+
} else message += "There are no allowed includes";
|
|
13
|
+
super(message, { status: ResponseStatus.BadRequest });
|
|
14
|
+
this.unknownIncludes = unknownIncludes;
|
|
15
|
+
this.allowedIncludes = allowedIncludes;
|
|
16
|
+
}
|
|
17
|
+
static includesNotAllowed(unknownIncludes, allowedIncludes) {
|
|
18
|
+
return new InvalidIncludeQuery(unknownIncludes, allowedIncludes);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { InvalidIncludeQuery };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { Exception } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
2
|
+
|
|
3
|
+
//#region src/exceptions/invalid_query.d.ts
|
|
4
|
+
declare abstract class InvalidQuery extends Exception {
|
|
5
|
+
static readonly code = "E_INVALID_QUERY_EXCEPTION";
|
|
4
6
|
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { InvalidQuery };
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { InvalidQuery } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { InvalidQuery } from "./invalid_query.js";
|
|
2
|
+
|
|
3
|
+
//#region src/exceptions/invalid_sort_query.d.ts
|
|
4
|
+
declare class InvalidSortQuery extends InvalidQuery {
|
|
5
|
+
readonly unknownSorts: string[];
|
|
6
|
+
readonly allowedSorts: string[];
|
|
7
|
+
constructor(unknownSorts: string[], allowedSorts: string[]);
|
|
8
|
+
static sortsNotAllowed(unknownSorts: string[], allowedSorts: string[]): InvalidSortQuery;
|
|
7
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { InvalidSortQuery };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InvalidQuery } from "./invalid_query.js";
|
|
2
|
+
import { ResponseStatus } from "@adonisjs/core/http";
|
|
3
|
+
//#region src/exceptions/invalid_sort_query.ts
|
|
4
|
+
var InvalidSortQuery = class InvalidSortQuery extends InvalidQuery {
|
|
5
|
+
unknownSorts;
|
|
6
|
+
allowedSorts;
|
|
7
|
+
constructor(unknownSorts, allowedSorts) {
|
|
8
|
+
const message = `Requested sort(s) \`${unknownSorts.join(", ")}\` is not allowed. Allowed sort(s) are \`${allowedSorts.join(", ")}\``;
|
|
9
|
+
super(message, { status: ResponseStatus.BadRequest });
|
|
10
|
+
this.unknownSorts = unknownSorts;
|
|
11
|
+
this.allowedSorts = allowedSorts;
|
|
12
|
+
}
|
|
13
|
+
static sortsNotAllowed(unknownSorts, allowedSorts) {
|
|
14
|
+
return new InvalidSortQuery(unknownSorts, allowedSorts);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { InvalidSortQuery };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { InvalidQuery } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { InvalidQuery } from "./invalid_query.js";
|
|
2
|
+
|
|
3
|
+
//#region src/exceptions/unknown_included_fields_query.d.ts
|
|
4
|
+
declare class UnknownIncludedFieldsQuery extends InvalidQuery {
|
|
5
|
+
readonly unknownFields: string[];
|
|
6
|
+
constructor(unknownFields: string[]);
|
|
5
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { UnknownIncludedFieldsQuery };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InvalidQuery } from "./invalid_query.js";
|
|
2
|
+
import { ResponseStatus } from "@adonisjs/core/http";
|
|
3
|
+
//#region src/exceptions/unknown_included_fields_query.ts
|
|
4
|
+
var UnknownIncludedFieldsQuery = class extends InvalidQuery {
|
|
5
|
+
unknownFields;
|
|
6
|
+
constructor(unknownFields) {
|
|
7
|
+
const message = [`Requested field(s) \`${unknownFields.join(", ")}\` are not allowed (yet). `, "If you want to allow these fields, please make sure to call the QueryBuilder's `allowedFields` method before the `allowedIncludes` method"].join("");
|
|
8
|
+
super(message, { status: ResponseStatus.BadRequest });
|
|
9
|
+
this.unknownFields = unknownFields;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { UnknownIncludedFieldsQuery };
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Filter } from "../../types.js";
|
|
2
|
+
import { FiltersPartial } from "./filters_partial.js";
|
|
3
|
+
import { LucidModel } from "@adonisjs/lucid/types/model";
|
|
4
|
+
import { StrictValuesWithoutRaw } from "@adonisjs/lucid/types/querybuilder";
|
|
5
|
+
|
|
6
|
+
//#region src/filters/filters_begin_with_strict.d.ts
|
|
7
|
+
declare class FiltersBeginWithStrict<Model extends LucidModel> extends FiltersPartial<Model> implements Filter<Model> {
|
|
8
|
+
protected getWhereRawParameters(value: StrictValuesWithoutRaw, property: string): [string, string[]];
|
|
7
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { FiltersBeginWithStrict };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FiltersPartial } from "./filters_partial.js";
|
|
2
|
+
//#region src/filters/filters_begin_with_strict.ts
|
|
3
|
+
var FiltersBeginWithStrict = class FiltersBeginWithStrict extends FiltersPartial {
|
|
4
|
+
getWhereRawParameters(value, property) {
|
|
5
|
+
return [`${property} LIKE ?`, [`${FiltersBeginWithStrict.escapeLike(value.toString())}%`]];
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { FiltersBeginWithStrict };
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Filter } from "../../types.js";
|
|
2
|
+
import { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
|
|
3
|
+
|
|
4
|
+
//#region src/filters/filters_callback.d.ts
|
|
5
|
+
declare class FiltersCallback<Model extends LucidModel> implements Filter<Model> {
|
|
6
|
+
private callback;
|
|
7
|
+
constructor(callback: (query: ModelQueryBuilderContract<Model>, value: unknown, property: string) => void);
|
|
8
|
+
handle(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, value: unknown, property: string): void;
|
|
7
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { FiltersCallback };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/filters/filters_callback.ts
|
|
2
|
+
var FiltersCallback = class {
|
|
3
|
+
callback;
|
|
4
|
+
constructor(callback) {
|
|
5
|
+
this.callback = callback;
|
|
6
|
+
}
|
|
7
|
+
handle(query, value, property) {
|
|
8
|
+
this.callback(query, value, property);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { FiltersCallback };
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Filter } from "../../types.js";
|
|
2
|
+
import { FiltersPartial } from "./filters_partial.js";
|
|
3
|
+
import { LucidModel } from "@adonisjs/lucid/types/model";
|
|
4
|
+
import { StrictValuesWithoutRaw } from "@adonisjs/lucid/types/querybuilder";
|
|
5
|
+
|
|
6
|
+
//#region src/filters/filters_ends_with_strict.d.ts
|
|
7
|
+
declare class FiltersEndsWithStrict<Model extends LucidModel> extends FiltersPartial<Model> implements Filter<Model> {
|
|
8
|
+
protected getWhereRawParameters(value: StrictValuesWithoutRaw, property: string): [string, string[]];
|
|
7
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { FiltersEndsWithStrict };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FiltersPartial } from "./filters_partial.js";
|
|
2
|
+
//#region src/filters/filters_ends_with_strict.ts
|
|
3
|
+
var FiltersEndsWithStrict = class FiltersEndsWithStrict extends FiltersPartial {
|
|
4
|
+
getWhereRawParameters(value, property) {
|
|
5
|
+
return [`${property} LIKE ?`, [`%${FiltersEndsWithStrict.escapeLike(value.toString())}`]];
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { FiltersEndsWithStrict };
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { Filter } from "../../types.js";
|
|
2
|
+
import { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
|
|
3
|
+
import { StrictValuesWithoutRaw } from "@adonisjs/lucid/types/querybuilder";
|
|
4
|
+
|
|
5
|
+
//#region src/filters/filters_exact.d.ts
|
|
6
|
+
declare class FiltersExact<Model extends LucidModel> implements Filter<Model> {
|
|
7
|
+
protected shouldAddRelationConstraint: boolean;
|
|
8
|
+
protected relationConstraints: string[];
|
|
9
|
+
constructor(shouldAddRelationConstraint?: boolean);
|
|
10
|
+
handle(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, value: StrictValuesWithoutRaw | null, property: string): void;
|
|
11
|
+
protected qualifyColumn(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, column: string): string;
|
|
12
|
+
protected isRelationProperty(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, property: string): boolean;
|
|
13
|
+
protected withRelationConstraint(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, value: StrictValuesWithoutRaw | null, property: string): void;
|
|
12
14
|
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { FiltersExact };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import collect$1 from "collect.js";
|
|
2
|
+
//#region src/filters/filters_exact.ts
|
|
3
|
+
var FiltersExact = class {
|
|
4
|
+
shouldAddRelationConstraint;
|
|
5
|
+
relationConstraints = [];
|
|
6
|
+
constructor(shouldAddRelationConstraint = true) {
|
|
7
|
+
this.shouldAddRelationConstraint = shouldAddRelationConstraint;
|
|
8
|
+
}
|
|
9
|
+
handle(query, value, property) {
|
|
10
|
+
if (this.shouldAddRelationConstraint && this.isRelationProperty(query, property)) {
|
|
11
|
+
this.withRelationConstraint(query, value, property);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
query.whereIn(this.qualifyColumn(query, property), value);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (value === null) {
|
|
19
|
+
query.whereNull(this.qualifyColumn(query, property));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
query.where(this.qualifyColumn(query, property), "=", value);
|
|
23
|
+
}
|
|
24
|
+
qualifyColumn(query, column) {
|
|
25
|
+
if (column.includes(".")) return column;
|
|
26
|
+
return `${query.model.table}.${query.model.$getColumn(column)?.columnName}`;
|
|
27
|
+
}
|
|
28
|
+
isRelationProperty(query, property) {
|
|
29
|
+
if (!property.includes(".")) return false;
|
|
30
|
+
if (this.relationConstraints.includes(property)) return false;
|
|
31
|
+
const firstRelationShip = property.split(".", 1)[0];
|
|
32
|
+
return query.model.$relationsDefinitions.has(firstRelationShip);
|
|
33
|
+
}
|
|
34
|
+
withRelationConstraint(query, value, property) {
|
|
35
|
+
const [relation, relationProperty] = collect$1(property.split(".")).pipe((parts) => {
|
|
36
|
+
const rProperty = parts.pop();
|
|
37
|
+
return [parts.implode("."), rProperty];
|
|
38
|
+
});
|
|
39
|
+
query.whereHas(relation, (subQuery) => {
|
|
40
|
+
const columnName = this.qualifyColumn(subQuery, relationProperty);
|
|
41
|
+
this.relationConstraints.push(columnName);
|
|
42
|
+
this.handle(subQuery, value, columnName);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
export { FiltersExact };
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { FilterOperator } from "../enums/filter_operator.js";
|
|
2
|
+
import { EnumType, Filter } from "../../types.js";
|
|
3
|
+
import { FiltersExact } from "./filters_exact.js";
|
|
4
|
+
import { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
|
|
5
|
+
import { StrictValuesWithoutRaw } from "@adonisjs/lucid/types/querybuilder";
|
|
6
|
+
|
|
7
|
+
//#region src/filters/filters_operator.d.ts
|
|
8
|
+
declare class FiltersOperator<Model extends LucidModel> extends FiltersExact<Model> implements Filter<Model> {
|
|
9
|
+
protected shouldAddRelationConstraint: boolean;
|
|
10
|
+
protected filterOperator: EnumType<typeof FilterOperator>;
|
|
11
|
+
protected boolean: 'and' | 'or';
|
|
12
|
+
constructor(shouldAddRelationConstraint: boolean, filterOperator: EnumType<typeof FilterOperator>, boolean: 'and' | 'or');
|
|
13
|
+
handle(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, value: StrictValuesWithoutRaw | null, property: string): void;
|
|
14
|
+
protected getDynamicFilterOperator(value: string): EnumType<typeof FilterOperator>;
|
|
15
|
+
protected removeDynamicFilterOperatorFromValue(value: string, filterOperator: EnumType<typeof FilterOperator>): string;
|
|
14
16
|
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { FiltersOperator };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { substrReplace } from "../utils/helpers.js";
|
|
2
|
+
import { FiltersExact } from "./filters_exact.js";
|
|
3
|
+
import { FilterOperator } from "../enums/filter_operator.js";
|
|
4
|
+
//#region src/filters/filters_operator.ts
|
|
5
|
+
var FiltersOperator = class extends FiltersExact {
|
|
6
|
+
shouldAddRelationConstraint;
|
|
7
|
+
filterOperator;
|
|
8
|
+
boolean;
|
|
9
|
+
constructor(shouldAddRelationConstraint, filterOperator, boolean) {
|
|
10
|
+
super(shouldAddRelationConstraint);
|
|
11
|
+
this.shouldAddRelationConstraint = shouldAddRelationConstraint;
|
|
12
|
+
this.filterOperator = filterOperator;
|
|
13
|
+
this.boolean = boolean;
|
|
14
|
+
}
|
|
15
|
+
handle(query, value, property) {
|
|
16
|
+
let { filterOperator } = this;
|
|
17
|
+
if (this.shouldAddRelationConstraint && this.isRelationProperty(query, property)) {
|
|
18
|
+
this.withRelationConstraint(query, value, property);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
const items = value;
|
|
23
|
+
query.where((subQuery) => {
|
|
24
|
+
for (const item of items) this.handle(subQuery, item, property);
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (value === null) {
|
|
29
|
+
query.whereNull(this.qualifyColumn(query, property));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (filterOperator === FilterOperator.Dynamic) {
|
|
33
|
+
filterOperator = this.getDynamicFilterOperator(value.toString());
|
|
34
|
+
value = this.removeDynamicFilterOperatorFromValue(value.toString(), filterOperator);
|
|
35
|
+
}
|
|
36
|
+
if (this.boolean === "and") {
|
|
37
|
+
query.where(this.qualifyColumn(query, property), filterOperator, value);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
query.orWhere(this.qualifyColumn(query, property), filterOperator, value);
|
|
41
|
+
}
|
|
42
|
+
getDynamicFilterOperator(value) {
|
|
43
|
+
let filterOperator = FilterOperator.Equal;
|
|
44
|
+
for (const filterOperatorCase of Object.values(FilterOperator)) if (value.startsWith(filterOperatorCase) && filterOperatorCase !== FilterOperator.Dynamic) filterOperator = filterOperatorCase;
|
|
45
|
+
return filterOperator;
|
|
46
|
+
}
|
|
47
|
+
removeDynamicFilterOperatorFromValue(value, filterOperator) {
|
|
48
|
+
if (value.includes(filterOperator)) value = substrReplace(value, "", 0, filterOperator.length);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
export { FiltersOperator };
|