@eienjs/adonisjs-api-query 2.0.0 → 3.0.1

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.
Files changed (89) hide show
  1. package/README.md +138 -0
  2. package/build/configure.d.ts +1 -5
  3. package/build/configure.js +1 -2
  4. package/build/index.d.ts +12 -6
  5. package/build/index.js +26 -20
  6. package/build/providers/api_query_provider.d.ts +19 -12
  7. package/build/providers/api_query_provider.js +7 -3
  8. package/build/src/allowed_filter.d.ts +14 -10
  9. package/build/src/allowed_filter.js +34 -12
  10. package/build/src/allowed_include.d.ts +6 -11
  11. package/build/src/allowed_include.js +14 -15
  12. package/build/src/allowed_sort.d.ts +2 -6
  13. package/build/src/allowed_sort.js +1 -2
  14. package/build/src/api_query_builder_request.d.ts +33 -12
  15. package/build/src/api_query_builder_request.js +119 -41
  16. package/build/src/base_filterable.d.ts +45 -0
  17. package/build/src/base_filterable.js +172 -0
  18. package/build/src/bindings/api_query_request.js +3 -3
  19. package/build/src/bindings/filterable_query.js +51 -0
  20. package/build/src/bindings/filters_query.js +21 -23
  21. package/build/src/bindings/includes_query.js +32 -33
  22. package/build/src/bindings/sorts_query.js +20 -23
  23. package/build/src/bindings/validation_query.js +27 -0
  24. package/build/src/decorators/filterable.d.ts +20 -0
  25. package/build/src/decorators/filterable.js +24 -0
  26. package/build/src/define_config.d.ts +1 -5
  27. package/build/src/define_config.js +3 -3
  28. package/build/src/enums/filter_operator.d.ts +2 -5
  29. package/build/src/enums/filter_operator.js +1 -2
  30. package/build/src/enums/sort_direction.d.ts +2 -5
  31. package/build/src/enums/sort_direction.js +1 -2
  32. package/build/src/exceptions/allowed_fields_must_be_called_before_allowed_includes.d.ts +4 -8
  33. package/build/src/exceptions/allowed_fields_must_be_called_before_allowed_includes.js +3 -4
  34. package/build/src/exceptions/filterable_not_configured.d.ts +5 -0
  35. package/build/src/exceptions/filterable_not_configured.js +12 -0
  36. package/build/src/exceptions/invalid_append_query.d.ts +4 -6
  37. package/build/src/exceptions/invalid_append_query.js +5 -2
  38. package/build/src/exceptions/invalid_direction.d.ts +2 -6
  39. package/build/src/exceptions/invalid_direction.js +1 -2
  40. package/build/src/exceptions/invalid_field_query.d.ts +7 -0
  41. package/build/src/exceptions/invalid_field_query.js +17 -0
  42. package/build/src/exceptions/invalid_filter_query.d.ts +2 -6
  43. package/build/src/exceptions/invalid_filter_query.js +1 -2
  44. package/build/src/exceptions/invalid_filter_value.d.ts +2 -6
  45. package/build/src/exceptions/invalid_filter_value.js +1 -2
  46. package/build/src/exceptions/invalid_include_query.d.ts +2 -6
  47. package/build/src/exceptions/invalid_include_query.js +1 -2
  48. package/build/src/exceptions/invalid_query.d.ts +2 -6
  49. package/build/src/exceptions/invalid_query.js +1 -2
  50. package/build/src/exceptions/invalid_sort_query.d.ts +2 -6
  51. package/build/src/exceptions/invalid_sort_query.js +1 -2
  52. package/build/src/exceptions/unknown_included_fields_query.d.ts +2 -6
  53. package/build/src/exceptions/unknown_included_fields_query.js +1 -2
  54. package/build/src/exceptions/vine_not_installed.d.ts +5 -0
  55. package/build/src/exceptions/vine_not_installed.js +12 -0
  56. package/build/src/filters/filters_begin_with_strict.d.ts +2 -6
  57. package/build/src/filters/filters_begin_with_strict.js +2 -3
  58. package/build/src/filters/filters_callback.d.ts +2 -6
  59. package/build/src/filters/filters_callback.js +1 -2
  60. package/build/src/filters/filters_ends_with_strict.d.ts +2 -6
  61. package/build/src/filters/filters_ends_with_strict.js +2 -3
  62. package/build/src/filters/filters_exact.d.ts +2 -6
  63. package/build/src/filters/filters_exact.js +15 -12
  64. package/build/src/filters/filters_operator.d.ts +3 -7
  65. package/build/src/filters/filters_operator.js +10 -11
  66. package/build/src/filters/filters_partial.d.ts +2 -8
  67. package/build/src/filters/filters_partial.js +7 -9
  68. package/build/src/filters/filters_scope.d.ts +12 -0
  69. package/build/src/filters/filters_scope.js +98 -0
  70. package/build/src/filters/filters_trashed.d.ts +2 -6
  71. package/build/src/filters/filters_trashed.js +1 -2
  72. package/build/src/includes/included_callback.d.ts +2 -6
  73. package/build/src/includes/included_callback.js +1 -2
  74. package/build/src/includes/included_count.d.ts +2 -6
  75. package/build/src/includes/included_count.js +2 -2
  76. package/build/src/includes/included_relationship.d.ts +4 -8
  77. package/build/src/includes/included_relationship.js +19 -22
  78. package/build/src/sorts/sorts_callback.d.ts +2 -6
  79. package/build/src/sorts/sorts_callback.js +1 -2
  80. package/build/src/sorts/sorts_field.d.ts +2 -6
  81. package/build/src/sorts/sorts_field.js +1 -2
  82. package/build/src/utils/helpers.js +2 -14
  83. package/build/src/validation/schema_builder.d.ts +3 -0
  84. package/build/src/validation/schema_builder.js +38 -0
  85. package/build/src/validation/vine_resolver.js +13 -0
  86. package/build/stubs/main.d.ts +1 -4
  87. package/build/stubs/main.js +1 -2
  88. package/build/types.d.ts +44 -19
  89. package/package.json +31 -24
@@ -1,51 +1,50 @@
1
1
  import { AllowedInclude } from "../allowed_include.js";
2
2
  import { InvalidIncludeQuery } from "../exceptions/invalid_include_query.js";
3
- import { Collection } from "collect.js";
4
- //#region src/bindings/includes_query.ts
3
+ // src/bindings/includes_query.ts
5
4
  const extendModelQueryBuilderWithIncludesQuery = function(builder, config) {
6
- const ensureAllIncludesExist = (self) => {
7
- if (config.disableInvalidIncludesQueryException) return;
8
- const includes = self.$apiQueryBuilderRequest.includes();
9
- const allowedIncludeNames = self._allowedIncludes.map((allowedInclude) => {
10
- return allowedInclude.getName();
11
- });
12
- const diff = includes.diff(allowedIncludeNames);
13
- if (diff.isNotEmpty()) throw InvalidIncludeQuery.includesNotAllowed(diff.all(), allowedIncludeNames.all());
5
+ const ensureAllIncludesExist = (self, requestedIncludes) => {
6
+ if (config.disableInvalidIncludesQueryException || requestedIncludes.length === 0) return;
7
+ const allowedIncludeNames = self._allowedIncludes.map((allowedInclude) => allowedInclude.getName());
8
+ const allowedSet = new Set(allowedIncludeNames);
9
+ const diff = requestedIncludes.filter((include) => !allowedSet.has(include));
10
+ if (diff.length > 0) throw InvalidIncludeQuery.includesNotAllowed(diff, allowedIncludeNames);
14
11
  };
15
12
  const findInclude = (self, include) => {
16
- return self._allowedIncludes.first((included) => included.isForInclude(include));
17
- };
18
- const filterNonExistingIncludes = (self) => {
19
- const includes = self.$apiQueryBuilderRequest.includes();
20
- if (!config.disableInvalidIncludesQueryException) return includes;
21
- return includes.filter((include) => !findInclude(self, include));
13
+ return self._allowedIncludes.find((included) => included.isForInclude(include));
22
14
  };
23
15
  const addIncludesToQuery = (self, includes) => {
24
- includes.each((include) => {
25
- findInclude(self, include)?.include(self);
26
- });
16
+ for (const include of includes) findInclude(self, include)?.include(self);
27
17
  };
28
18
  builder.macro("allowedIncludes", function(...includes) {
29
19
  const arrayIncludes = Array.isArray(includes.at(0)) ? includes.at(0) : includes;
30
- this._allowedIncludes = new Collection(arrayIncludes).reject((include) => typeof include === "string" && include.length === 0).reduce((result, include) => {
31
- if (include instanceof Collection) {
32
- for (const allowedInclude of include) result = result.push(allowedInclude);
33
- return result;
20
+ const reduced = [];
21
+ for (const include of arrayIncludes) {
22
+ if (typeof include === "string" && include.length === 0) continue;
23
+ if (Array.isArray(include)) {
24
+ reduced.push(...include);
25
+ continue;
26
+ }
27
+ if (include instanceof AllowedInclude) {
28
+ reduced.push(include);
29
+ continue;
34
30
  }
35
31
  if (include.endsWith(config.countSuffix)) {
36
- for (const allowedInclude of AllowedInclude.count(include)) result = result.push(allowedInclude);
37
- return result;
32
+ reduced.push(...AllowedInclude.count(include));
33
+ continue;
38
34
  }
39
- for (const allowedInclude of AllowedInclude.relationship(include)) result = result.push(allowedInclude);
40
- return result;
41
- }, new Collection()).unique((allowedInclude) => {
42
- return allowedInclude.getName();
35
+ reduced.push(...AllowedInclude.relationship(include));
36
+ }
37
+ const seen = /* @__PURE__ */ new Set();
38
+ this._allowedIncludes = reduced.filter((allowedInclude) => {
39
+ const name = allowedInclude.getName();
40
+ if (seen.has(name)) return false;
41
+ seen.add(name);
42
+ return true;
43
43
  });
44
- ensureAllIncludesExist(this);
45
- const resultIncludes = filterNonExistingIncludes(this);
46
- addIncludesToQuery(this, resultIncludes);
44
+ const requestedIncludes = this.$apiQueryBuilderRequest.includes();
45
+ ensureAllIncludesExist(this, requestedIncludes);
46
+ addIncludesToQuery(this, requestedIncludes);
47
47
  return this;
48
48
  });
49
49
  };
50
- //#endregion
51
50
  export { extendModelQueryBuilderWithIncludesQuery };
@@ -1,45 +1,42 @@
1
1
  import { AllowedSort } from "../allowed_sort.js";
2
2
  import { InvalidSortQuery } from "../exceptions/invalid_sort_query.js";
3
- import { collect } from "collect.js";
4
- //#region src/bindings/sorts_query.ts
3
+ // src/bindings/sorts_query.ts
5
4
  const DESCENDING_ORDER_PREFIX = /^-+/;
6
5
  const extendModelQueryBuilderWithSortsQuery = function(builder, config) {
7
- const ensureAllSortsExist = (self) => {
8
- if (config.disableInvalidSortQueryException) return;
9
- const requestedSortNames = self.$apiQueryBuilderRequest.sorts().map((sort) => sort.replace(DESCENDING_ORDER_PREFIX, ""));
6
+ const ensureAllSortsExist = (self, requestedSorts) => {
7
+ if (config.disableInvalidSortQueryException || requestedSorts.length === 0) return;
8
+ const requestedSortNames = requestedSorts.map((sort) => sort.replace(DESCENDING_ORDER_PREFIX, ""));
10
9
  const allowedSortNames = self._allowedSorts.map((sort) => sort.getName());
11
- const unknownSort = requestedSortNames.diff(allowedSortNames);
12
- if (unknownSort.isNotEmpty()) throw InvalidSortQuery.sortsNotAllowed(unknownSort.all(), allowedSortNames.all());
10
+ const allowedSet = new Set(allowedSortNames);
11
+ const unknownSort = requestedSortNames.filter((sort) => !allowedSet.has(sort));
12
+ if (unknownSort.length > 0) throw InvalidSortQuery.sortsNotAllowed(unknownSort, allowedSortNames);
13
13
  };
14
14
  const findSort = (self, property) => {
15
- return self._allowedSorts.first((sort) => sort.isSort(property));
15
+ return self._allowedSorts.find((sort) => sort.isSort(property));
16
16
  };
17
- const addRequestedSortsToQuery = (self) => {
18
- self.$apiQueryBuilderRequest.sorts().each((property) => {
17
+ const addRequestedSortsToQuery = (self, requestedSorts) => {
18
+ for (const property of requestedSorts) {
19
19
  const isDescending = property.startsWith("-");
20
- findSort(self, property.replace(DESCENDING_ORDER_PREFIX, ""))?.sort(self, isDescending);
21
- });
20
+ const key = property.replace(DESCENDING_ORDER_PREFIX, "");
21
+ findSort(self, key)?.sort(self, isDescending);
22
+ }
22
23
  };
23
24
  builder.macro("allowedSorts", function(...sorts) {
24
25
  const arraySorts = Array.isArray(sorts.at(0)) ? sorts.at(0) : sorts;
25
- this._allowedSorts = collect(arraySorts).map((sort) => {
26
+ this._allowedSorts = arraySorts.map((sort) => {
26
27
  if (sort instanceof AllowedSort) return sort;
27
28
  return AllowedSort.field(sort.replace(DESCENDING_ORDER_PREFIX, ""));
28
29
  });
29
- ensureAllSortsExist(this);
30
- addRequestedSortsToQuery(this);
30
+ const requestedSorts = this.$apiQueryBuilderRequest.sorts();
31
+ ensureAllSortsExist(this, requestedSorts);
32
+ addRequestedSortsToQuery(this, requestedSorts);
31
33
  return this;
32
34
  });
33
35
  builder.macro("defaultSort", function(...sorts) {
34
- if (this.$apiQueryBuilderRequest.sorts().isNotEmpty()) return this;
35
- collect(Array.isArray(sorts.at(0)) ? sorts.at(0) : sorts).map((sort) => {
36
- if (sort instanceof AllowedSort) return sort;
37
- return AllowedSort.field(sort);
38
- }).each((sort) => {
39
- sort.sort(this);
40
- });
36
+ if (this.$apiQueryBuilderRequest.sorts().length > 0) return this;
37
+ const arraySorts = Array.isArray(sorts.at(0)) ? sorts.at(0) : sorts;
38
+ for (const rawSort of arraySorts) (rawSort instanceof AllowedSort ? rawSort : AllowedSort.field(rawSort)).sort(this);
41
39
  return this;
42
40
  });
43
41
  };
44
- //#endregion
45
42
  export { extendModelQueryBuilderWithSortsQuery };
@@ -0,0 +1,27 @@
1
+ // src/bindings/validation_query.ts
2
+ let isPatched = false;
3
+ const extendModelQueryBuilderWithValidation = function(builder) {
4
+ builder.macro("validate", async function() {
5
+ return this.$apiQueryBuilderRequest.validate();
6
+ });
7
+ if (isPatched) return;
8
+ const proto = builder.prototype;
9
+ const originalExecQuery = proto.execQuery;
10
+ proto.execQuery = async function(...args) {
11
+ const query = this;
12
+ if (query.$queryBuilderRequest) {
13
+ const apiRequest = query.$queryBuilderRequest;
14
+ if (apiRequest.shouldAutoValidate() && apiRequest.hasValidation()) await apiRequest.validate();
15
+ }
16
+ return originalExecQuery.apply(this, args);
17
+ };
18
+ const originalClone = proto.clone;
19
+ proto.clone = function() {
20
+ const cloned = originalClone.call(this);
21
+ const query = this;
22
+ if (query.$queryBuilderRequest) cloned.$queryBuilderRequest = query.$queryBuilderRequest;
23
+ return cloned;
24
+ };
25
+ isPatched = true;
26
+ };
27
+ export { extendModelQueryBuilderWithValidation };
@@ -0,0 +1,20 @@
1
+ import { ApiQueryBuilderRequest } from "../api_query_builder_request.js";
2
+ import { BaseFilterable } from "../base_filterable.js";
3
+ import { FilterableConstructor, FilterableTarget } from "../../types.js";
4
+ import { HttpRequest } from "@adonisjs/core/http";
5
+ import { BaseModel } from "@adonisjs/lucid/orm";
6
+ import { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
7
+ import { NormalizeConstructor } from "@adonisjs/core/types/helpers";
8
+ export type FilterableModel<T extends NormalizeConstructor<typeof BaseModel>> = (new (...args: unknown[]) => InstanceType<T>) & { [K in keyof T]: T[K]; } & {
9
+ $filterable?: FilterableTarget;
10
+ $filter<Model extends LucidModel>(this: Model, request?: HttpRequest | ApiQueryBuilderRequest): ModelQueryBuilderContract<Model, InstanceType<Model>>;
11
+ $filter<Model extends LucidModel>(this: Model, filterable: FilterableConstructor<Model> | BaseFilterable<Model>, request?: HttpRequest | ApiQueryBuilderRequest): ModelQueryBuilderContract<Model, InstanceType<Model>>;
12
+ };
13
+ /**
14
+ * Decorator to assign a filterable class to a Lucid Model
15
+ */
16
+ export declare function filterable<Model extends LucidModel = LucidModel>(target: FilterableTarget<Model>): (model: unknown) => void;
17
+ /**
18
+ * Mixin that adds filterable capabilities to a Lucid Model
19
+ */
20
+ export declare function Filterable<T extends NormalizeConstructor<typeof BaseModel>, Model extends LucidModel = LucidModel>(filterableTarget?: FilterableTarget<Model>): (superclass: T) => FilterableModel<T>;
@@ -0,0 +1,24 @@
1
+ // src/decorators/filterable.ts
2
+ /**
3
+ * Decorator to assign a filterable class to a Lucid Model
4
+ */
5
+ function filterable(target) {
6
+ return function(model) {
7
+ model.$filterable = target;
8
+ };
9
+ }
10
+ /**
11
+ * Mixin that adds filterable capabilities to a Lucid Model
12
+ */
13
+ function Filterable(filterableTarget) {
14
+ return function(superclass) {
15
+ class ModelWithFilterable extends superclass {
16
+ static $filterable = filterableTarget ?? superclass.$filterable;
17
+ static $filter(filterableOrRequest, maybeRequest) {
18
+ return this.query().filter(filterableOrRequest, maybeRequest);
19
+ }
20
+ }
21
+ return ModelWithFilterable;
22
+ };
23
+ }
24
+ export { Filterable, filterable };
@@ -1,7 +1,3 @@
1
1
  import { ApiQueryConfig, ResolvedApiQueryConfig } from "../types.js";
2
2
  import { ConfigProvider } from "@adonisjs/core/types";
3
-
4
- //#region src/define_config.d.ts
5
- declare const defineConfig: (config: ApiQueryConfig) => ConfigProvider<ResolvedApiQueryConfig>;
6
- //#endregion
7
- export { defineConfig };
3
+ export declare const defineConfig: (config: ApiQueryConfig) => ConfigProvider<ResolvedApiQueryConfig>;
@@ -1,5 +1,5 @@
1
1
  import { configProvider } from "@adonisjs/core";
2
- //#region src/define_config.ts
2
+ // src/define_config.ts
3
3
  const defineConfig = function(config) {
4
4
  return configProvider.create(async (_) => {
5
5
  return {
@@ -17,9 +17,9 @@ const defineConfig = function(config) {
17
17
  disableInvalidIncludesQueryException: config.disableInvalidIncludesQueryException ?? false,
18
18
  convertRelationNamesToSnakeCasePlural: config.convertRelationNamesToSnakeCasePlural ?? false,
19
19
  convertRelationTableNameStrategy: config.convertRelationTableNameStrategy ?? false,
20
- convertFieldNamesToSnakeCase: config.convertFieldNamesToSnakeCase ?? false
20
+ convertFieldNamesToSnakeCase: config.convertFieldNamesToSnakeCase ?? false,
21
+ autoValidate: config.autoValidate ?? true
21
22
  };
22
23
  });
23
24
  };
24
- //#endregion
25
25
  export { defineConfig };
@@ -1,5 +1,4 @@
1
- //#region src/enums/filter_operator.d.ts
2
- declare const FilterOperator: {
1
+ export declare const FilterOperator: {
3
2
  readonly Dynamic: "";
4
3
  readonly Equal: "=";
5
4
  readonly LessThan: "<";
@@ -7,6 +6,4 @@ declare const FilterOperator: {
7
6
  readonly LessThanOrEqual: "<=";
8
7
  readonly GreaterThanOrEqual: ">=";
9
8
  readonly NotEqual: "<>";
10
- };
11
- //#endregion
12
- export { FilterOperator };
9
+ };
@@ -1,4 +1,4 @@
1
- //#region src/enums/filter_operator.ts
1
+ // src/enums/filter_operator.ts
2
2
  const FilterOperator = {
3
3
  Dynamic: "",
4
4
  Equal: "=",
@@ -8,5 +8,4 @@ const FilterOperator = {
8
8
  GreaterThanOrEqual: ">=",
9
9
  NotEqual: "<>"
10
10
  };
11
- //#endregion
12
11
  export { FilterOperator };
@@ -1,7 +1,4 @@
1
- //#region src/enums/sort_direction.d.ts
2
- declare const SortDirection: {
1
+ export declare const SortDirection: {
3
2
  readonly Ascending: "asc";
4
3
  readonly Descending: "desc";
5
- };
6
- //#endregion
7
- export { SortDirection };
4
+ };
@@ -1,7 +1,6 @@
1
- //#region src/enums/sort_direction.ts
1
+ // src/enums/sort_direction.ts
2
2
  const SortDirection = {
3
3
  Ascending: "asc",
4
4
  Descending: "desc"
5
5
  };
6
- //#endregion
7
6
  export { SortDirection };
@@ -1,10 +1,6 @@
1
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;
2
+ export declare class AllowedFieldsMustBeCalledBeforeAllowedIncludes extends Exception {
3
+ static readonly code = "E_BAD_METHOD_CALL_EXCEPTION";
4
+ static readonly status = 500;
7
5
  constructor();
8
- }
9
- //#endregion
10
- export { AllowedFieldsMustBeCalledBeforeAllowedIncludes };
6
+ }
@@ -1,11 +1,10 @@
1
1
  import { Exception } from "@adonisjs/core/exceptions";
2
- //#region src/exceptions/allowed_fields_must_be_called_before_allowed_includes.ts
2
+ // src/exceptions/allowed_fields_must_be_called_before_allowed_includes.ts
3
3
  var AllowedFieldsMustBeCalledBeforeAllowedIncludes = class extends Exception {
4
- static code;
5
- static status;
4
+ static code = "E_BAD_METHOD_CALL_EXCEPTION";
5
+ static status = 500;
6
6
  constructor() {
7
7
  super("The QueryBuilder's `allowedFields` method must be called before the `allowedIncludes` method");
8
8
  }
9
9
  };
10
- //#endregion
11
10
  export { AllowedFieldsMustBeCalledBeforeAllowedIncludes };
@@ -0,0 +1,5 @@
1
+ import { Exception } from "@adonisjs/core/exceptions";
2
+ export declare class FilterableNotConfigured extends Exception {
3
+ static readonly code = "E_FILTERABLE_NOT_CONFIGURED";
4
+ constructor(modelName: string);
5
+ }
@@ -0,0 +1,12 @@
1
+ import { Exception } from "@adonisjs/core/exceptions";
2
+ // src/exceptions/filterable_not_configured.ts
3
+ var FilterableNotConfigured = class FilterableNotConfigured extends Exception {
4
+ static code = "E_FILTERABLE_NOT_CONFIGURED";
5
+ constructor(modelName) {
6
+ super(`No filterable class is configured for model "${modelName}". Define "static \$filterable = UserFilterable" or use "@filterable(UserFilterable)", or pass a filterable class directly to "\$filter()".`, {
7
+ status: 500,
8
+ code: FilterableNotConfigured.code
9
+ });
10
+ }
11
+ };
12
+ export { FilterableNotConfigured };
@@ -1,9 +1,7 @@
1
1
  import { InvalidQuery } from "./invalid_query.js";
2
-
3
- //#region src/exceptions/invalid_append_query.d.ts
4
- declare class InvalidAppendQuery extends InvalidQuery {
2
+ export declare class InvalidAppendQuery extends InvalidQuery {
3
+ readonly appendsNotAllowed: string[];
4
+ readonly allowedAppends: string[];
5
5
  constructor(appendsNotAllowed: string[], allowedAppends: string[]);
6
6
  static appendsNotAllowed(appendsNotAllowed: string[], allowedAppends: string[]): InvalidAppendQuery;
7
- }
8
- //#endregion
9
- export { InvalidAppendQuery };
7
+ }
@@ -1,14 +1,17 @@
1
1
  import { InvalidQuery } from "./invalid_query.js";
2
2
  import { ResponseStatus } from "@adonisjs/core/http";
3
- //#region src/exceptions/invalid_append_query.ts
3
+ // src/exceptions/invalid_append_query.ts
4
4
  var InvalidAppendQuery = class InvalidAppendQuery extends InvalidQuery {
5
+ appendsNotAllowed;
6
+ allowedAppends;
5
7
  constructor(appendsNotAllowed, allowedAppends) {
6
8
  const message = `Requested append(s) \`${appendsNotAllowed.join(", ")}\` are not allowed. Allowed append(s) are \`${allowedAppends.join(", ")}\``;
7
9
  super(message, { status: ResponseStatus.BadRequest });
10
+ this.appendsNotAllowed = appendsNotAllowed;
11
+ this.allowedAppends = allowedAppends;
8
12
  }
9
13
  static appendsNotAllowed(appendsNotAllowed, allowedAppends) {
10
14
  return new InvalidAppendQuery(appendsNotAllowed, allowedAppends);
11
15
  }
12
16
  };
13
- //#endregion
14
17
  export { InvalidAppendQuery };
@@ -1,8 +1,4 @@
1
1
  import { Exception } from "@adonisjs/core/exceptions";
2
-
3
- //#region src/exceptions/invalid_direction.d.ts
4
- declare class InvalidDirection extends Exception {
2
+ export declare class InvalidDirection extends Exception {
5
3
  static make(sort: string): InvalidDirection;
6
- }
7
- //#endregion
8
- export { InvalidDirection };
4
+ }
@@ -1,10 +1,9 @@
1
1
  import { SortDirection } from "../enums/sort_direction.js";
2
2
  import { Exception } from "@adonisjs/core/exceptions";
3
- //#region src/exceptions/invalid_direction.ts
3
+ // src/exceptions/invalid_direction.ts
4
4
  var InvalidDirection = class InvalidDirection extends Exception {
5
5
  static make(sort) {
6
6
  return new InvalidDirection(`The direction should be either \`${SortDirection.Descending}\` or \`${SortDirection.Ascending}\` ${sort} given`);
7
7
  }
8
8
  };
9
- //#endregion
10
9
  export { InvalidDirection };
@@ -0,0 +1,7 @@
1
+ import { InvalidQuery } from "./invalid_query.js";
2
+ export declare class InvalidFieldQuery extends InvalidQuery {
3
+ readonly unknownFields: string[];
4
+ readonly allowedFields: string[];
5
+ constructor(unknownFields: string[], allowedFields: string[]);
6
+ static fieldsNotAllowed(unknownFields: string[], allowedFields: string[]): InvalidFieldQuery;
7
+ }
@@ -0,0 +1,17 @@
1
+ import { InvalidQuery } from "./invalid_query.js";
2
+ import { ResponseStatus } from "@adonisjs/core/http";
3
+ // src/exceptions/invalid_field_query.ts
4
+ var InvalidFieldQuery = class InvalidFieldQuery extends InvalidQuery {
5
+ unknownFields;
6
+ allowedFields;
7
+ constructor(unknownFields, allowedFields) {
8
+ const message = `Requested field(s) \`${unknownFields.join(", ")}\` are not allowed. Allowed field(s) are \`${allowedFields.join(", ")}\``;
9
+ super(message, { status: ResponseStatus.BadRequest });
10
+ this.unknownFields = unknownFields;
11
+ this.allowedFields = allowedFields;
12
+ }
13
+ static fieldsNotAllowed(unknownFields, allowedFields) {
14
+ return new InvalidFieldQuery(unknownFields, allowedFields);
15
+ }
16
+ };
17
+ export { InvalidFieldQuery };
@@ -1,11 +1,7 @@
1
1
  import { InvalidQuery } from "./invalid_query.js";
2
-
3
- //#region src/exceptions/invalid_filter_query.d.ts
4
- declare class InvalidFilterQuery extends InvalidQuery {
2
+ export declare class InvalidFilterQuery extends InvalidQuery {
5
3
  readonly unknownFilters: string[];
6
4
  readonly allowedFilters: string[];
7
5
  constructor(unknownFilters: string[], allowedFilters: string[]);
8
6
  static filtersNotAllowed(unknownFilters: string[], allowedFilters: string[]): InvalidFilterQuery;
9
- }
10
- //#endregion
11
- export { InvalidFilterQuery };
7
+ }
@@ -1,6 +1,6 @@
1
1
  import { InvalidQuery } from "./invalid_query.js";
2
2
  import { ResponseStatus } from "@adonisjs/core/http";
3
- //#region src/exceptions/invalid_filter_query.ts
3
+ // src/exceptions/invalid_filter_query.ts
4
4
  var InvalidFilterQuery = class InvalidFilterQuery extends InvalidQuery {
5
5
  unknownFilters;
6
6
  allowedFilters;
@@ -14,5 +14,4 @@ var InvalidFilterQuery = class InvalidFilterQuery extends InvalidQuery {
14
14
  return new InvalidFilterQuery(unknownFilters, allowedFilters);
15
15
  }
16
16
  };
17
- //#endregion
18
17
  export { InvalidFilterQuery };
@@ -1,8 +1,4 @@
1
1
  import { Exception } from "@adonisjs/core/exceptions";
2
-
3
- //#region src/exceptions/invalid_filter_value.d.ts
4
- declare class InvalidFilterValue extends Exception {
2
+ export declare class InvalidFilterValue extends Exception {
5
3
  static make(value: unknown): InvalidFilterValue;
6
- }
7
- //#endregion
8
- export { InvalidFilterValue };
4
+ }
@@ -1,9 +1,8 @@
1
1
  import { Exception } from "@adonisjs/core/exceptions";
2
- //#region src/exceptions/invalid_filter_value.ts
2
+ // src/exceptions/invalid_filter_value.ts
3
3
  var InvalidFilterValue = class InvalidFilterValue extends Exception {
4
4
  static make(value) {
5
5
  return new InvalidFilterValue(`Filter value \`${value}\` is invalid`);
6
6
  }
7
7
  };
8
- //#endregion
9
8
  export { InvalidFilterValue };
@@ -1,11 +1,7 @@
1
1
  import { InvalidQuery } from "./invalid_query.js";
2
-
3
- //#region src/exceptions/invalid_include_query.d.ts
4
- declare class InvalidIncludeQuery extends InvalidQuery {
2
+ export declare class InvalidIncludeQuery extends InvalidQuery {
5
3
  readonly unknownIncludes: string[];
6
4
  readonly allowedIncludes: string[];
7
5
  constructor(unknownIncludes: string[], allowedIncludes: string[]);
8
6
  static includesNotAllowed(unknownIncludes: string[], allowedIncludes: string[]): InvalidIncludeQuery;
9
- }
10
- //#endregion
11
- export { InvalidIncludeQuery };
7
+ }
@@ -1,6 +1,6 @@
1
1
  import { InvalidQuery } from "./invalid_query.js";
2
2
  import { ResponseStatus } from "@adonisjs/core/http";
3
- //#region src/exceptions/invalid_include_query.ts
3
+ // src/exceptions/invalid_include_query.ts
4
4
  var InvalidIncludeQuery = class InvalidIncludeQuery extends InvalidQuery {
5
5
  unknownIncludes;
6
6
  allowedIncludes;
@@ -18,5 +18,4 @@ var InvalidIncludeQuery = class InvalidIncludeQuery extends InvalidQuery {
18
18
  return new InvalidIncludeQuery(unknownIncludes, allowedIncludes);
19
19
  }
20
20
  };
21
- //#endregion
22
21
  export { InvalidIncludeQuery };
@@ -1,8 +1,4 @@
1
1
  import { Exception } from "@adonisjs/core/exceptions";
2
-
3
- //#region src/exceptions/invalid_query.d.ts
4
- declare abstract class InvalidQuery extends Exception {
2
+ export declare abstract class InvalidQuery extends Exception {
5
3
  static readonly code = "E_INVALID_QUERY_EXCEPTION";
6
- }
7
- //#endregion
8
- export { InvalidQuery };
4
+ }
@@ -1,7 +1,6 @@
1
1
  import { Exception } from "@adonisjs/core/exceptions";
2
- //#region src/exceptions/invalid_query.ts
2
+ // src/exceptions/invalid_query.ts
3
3
  var InvalidQuery = class extends Exception {
4
4
  static code = "E_INVALID_QUERY_EXCEPTION";
5
5
  };
6
- //#endregion
7
6
  export { InvalidQuery };
@@ -1,11 +1,7 @@
1
1
  import { InvalidQuery } from "./invalid_query.js";
2
-
3
- //#region src/exceptions/invalid_sort_query.d.ts
4
- declare class InvalidSortQuery extends InvalidQuery {
2
+ export declare class InvalidSortQuery extends InvalidQuery {
5
3
  readonly unknownSorts: string[];
6
4
  readonly allowedSorts: string[];
7
5
  constructor(unknownSorts: string[], allowedSorts: string[]);
8
6
  static sortsNotAllowed(unknownSorts: string[], allowedSorts: string[]): InvalidSortQuery;
9
- }
10
- //#endregion
11
- export { InvalidSortQuery };
7
+ }
@@ -1,6 +1,6 @@
1
1
  import { InvalidQuery } from "./invalid_query.js";
2
2
  import { ResponseStatus } from "@adonisjs/core/http";
3
- //#region src/exceptions/invalid_sort_query.ts
3
+ // src/exceptions/invalid_sort_query.ts
4
4
  var InvalidSortQuery = class InvalidSortQuery extends InvalidQuery {
5
5
  unknownSorts;
6
6
  allowedSorts;
@@ -14,5 +14,4 @@ var InvalidSortQuery = class InvalidSortQuery extends InvalidQuery {
14
14
  return new InvalidSortQuery(unknownSorts, allowedSorts);
15
15
  }
16
16
  };
17
- //#endregion
18
17
  export { InvalidSortQuery };
@@ -1,9 +1,5 @@
1
1
  import { InvalidQuery } from "./invalid_query.js";
2
-
3
- //#region src/exceptions/unknown_included_fields_query.d.ts
4
- declare class UnknownIncludedFieldsQuery extends InvalidQuery {
2
+ export declare class UnknownIncludedFieldsQuery extends InvalidQuery {
5
3
  readonly unknownFields: string[];
6
4
  constructor(unknownFields: string[]);
7
- }
8
- //#endregion
9
- export { UnknownIncludedFieldsQuery };
5
+ }
@@ -1,6 +1,6 @@
1
1
  import { InvalidQuery } from "./invalid_query.js";
2
2
  import { ResponseStatus } from "@adonisjs/core/http";
3
- //#region src/exceptions/unknown_included_fields_query.ts
3
+ // src/exceptions/unknown_included_fields_query.ts
4
4
  var UnknownIncludedFieldsQuery = class extends InvalidQuery {
5
5
  unknownFields;
6
6
  constructor(unknownFields) {
@@ -9,5 +9,4 @@ var UnknownIncludedFieldsQuery = class extends InvalidQuery {
9
9
  this.unknownFields = unknownFields;
10
10
  }
11
11
  };
12
- //#endregion
13
12
  export { UnknownIncludedFieldsQuery };
@@ -0,0 +1,5 @@
1
+ import { Exception } from "@adonisjs/core/exceptions";
2
+ export declare class VineNotInstalledException extends Exception {
3
+ static readonly code = "E_VINE_NOT_INSTALLED";
4
+ constructor();
5
+ }
@@ -0,0 +1,12 @@
1
+ import { Exception } from "@adonisjs/core/exceptions";
2
+ // src/exceptions/vine_not_installed.ts
3
+ var VineNotInstalledException = class VineNotInstalledException extends Exception {
4
+ static code = "E_VINE_NOT_INSTALLED";
5
+ constructor() {
6
+ super("To use validation in \"@eienjs/adonisjs-api-query\", you must install \"@vinejs/vine\". Run: \"pnpm add @vinejs/vine\" or \"npm install @vinejs/vine\".", {
7
+ status: 500,
8
+ code: VineNotInstalledException.code
9
+ });
10
+ }
11
+ };
12
+ export { VineNotInstalledException };