@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.
Files changed (105) hide show
  1. package/{LICENSE.md → LICENSE} +1 -1
  2. package/README.md +28 -2
  3. package/build/configure.d.ts +6 -2
  4. package/build/configure.js +11 -0
  5. package/build/index.d.ts +32 -31
  6. package/build/index.js +31 -153
  7. package/build/providers/api_query_provider.d.ts +41 -37
  8. package/build/providers/api_query_provider.js +21 -26
  9. package/build/src/allowed_filter.d.ts +40 -36
  10. package/build/src/allowed_filter.js +113 -0
  11. package/build/src/allowed_include.d.ts +20 -16
  12. package/build/src/allowed_include.js +48 -0
  13. package/build/src/allowed_sort.d.ts +21 -17
  14. package/build/src/allowed_sort.js +50 -0
  15. package/build/src/api_query_builder_request.d.ts +34 -30
  16. package/build/src/api_query_builder_request.js +122 -0
  17. package/build/src/bindings/api_query_request.js +13 -0
  18. package/build/src/bindings/filters_query.js +40 -0
  19. package/build/src/bindings/includes_query.js +51 -0
  20. package/build/src/bindings/sorts_query.js +45 -0
  21. package/build/src/define_config.d.ts +7 -3
  22. package/build/src/define_config.js +25 -0
  23. package/build/src/enums/filter_operator.d.ts +11 -9
  24. package/build/src/enums/filter_operator.js +12 -0
  25. package/build/src/enums/sort_direction.d.ts +6 -4
  26. package/build/src/enums/sort_direction.js +7 -0
  27. package/build/src/exceptions/allowed_fields_must_be_called_before_allowed_includes.d.ts +9 -5
  28. package/build/src/exceptions/allowed_fields_must_be_called_before_allowed_includes.js +11 -0
  29. package/build/src/exceptions/invalid_append_query.d.ts +8 -4
  30. package/build/src/exceptions/invalid_append_query.js +14 -0
  31. package/build/src/exceptions/invalid_direction.d.ts +7 -3
  32. package/build/src/exceptions/invalid_direction.js +10 -0
  33. package/build/src/exceptions/invalid_filter_query.d.ts +10 -6
  34. package/build/src/exceptions/invalid_filter_query.js +18 -0
  35. package/build/src/exceptions/invalid_filter_value.d.ts +7 -3
  36. package/build/src/exceptions/invalid_filter_value.js +9 -0
  37. package/build/src/exceptions/invalid_include_query.d.ts +10 -6
  38. package/build/src/exceptions/invalid_include_query.js +22 -0
  39. package/build/src/exceptions/invalid_query.d.ts +7 -3
  40. package/build/src/exceptions/invalid_query.js +7 -0
  41. package/build/src/exceptions/invalid_sort_query.d.ts +10 -6
  42. package/build/src/exceptions/invalid_sort_query.js +18 -0
  43. package/build/src/exceptions/unknown_included_fields_query.d.ts +8 -4
  44. package/build/src/exceptions/unknown_included_fields_query.js +13 -0
  45. package/build/src/filters/filters_begin_with_strict.d.ts +10 -6
  46. package/build/src/filters/filters_begin_with_strict.js +9 -0
  47. package/build/src/filters/filters_callback.d.ts +10 -6
  48. package/build/src/filters/filters_callback.js +12 -0
  49. package/build/src/filters/filters_ends_with_strict.d.ts +10 -6
  50. package/build/src/filters/filters_ends_with_strict.js +9 -0
  51. package/build/src/filters/filters_exact.d.ts +15 -11
  52. package/build/src/filters/filters_exact.js +47 -0
  53. package/build/src/filters/filters_operator.d.ts +17 -13
  54. package/build/src/filters/filters_operator.js +53 -0
  55. package/build/src/filters/filters_partial.d.ts +15 -11
  56. package/build/src/filters/filters_partial.js +39 -0
  57. package/build/src/filters/filters_trashed.d.ts +9 -5
  58. package/build/src/filters/filters_trashed.js +14 -0
  59. package/build/src/includes/included_callback.d.ts +11 -7
  60. package/build/src/includes/included_callback.js +12 -0
  61. package/build/src/includes/included_count.d.ts +8 -4
  62. package/build/src/includes/included_count.js +11 -0
  63. package/build/src/includes/included_relationship.d.ts +12 -8
  64. package/build/src/includes/included_relationship.js +40 -0
  65. package/build/src/sorts/sorts_callback.d.ts +10 -6
  66. package/build/src/sorts/sorts_callback.js +12 -0
  67. package/build/src/sorts/sorts_field.d.ts +8 -4
  68. package/build/src/sorts/sorts_field.js +8 -0
  69. package/build/src/utils/helpers.js +26 -0
  70. package/build/stubs/main.d.ts +4 -1
  71. package/build/stubs/main.js +4 -0
  72. package/build/types.d.ts +91 -0
  73. package/build/types.js +1 -0
  74. package/package.json +99 -88
  75. package/build/api_query_request-QXOB4BN6.js +0 -18
  76. package/build/api_query_request-QXOB4BN6.js.map +0 -1
  77. package/build/chunk-3ITWUZL5.js +0 -108
  78. package/build/chunk-3ITWUZL5.js.map +0 -1
  79. package/build/chunk-54HNQTDY.js +0 -348
  80. package/build/chunk-54HNQTDY.js.map +0 -1
  81. package/build/chunk-IV3B5WO7.js +0 -160
  82. package/build/chunk-IV3B5WO7.js.map +0 -1
  83. package/build/chunk-MKQ3HMMA.js +0 -198
  84. package/build/chunk-MKQ3HMMA.js.map +0 -1
  85. package/build/chunk-XIRHVLVQ.js +0 -10
  86. package/build/chunk-XIRHVLVQ.js.map +0 -1
  87. package/build/filters_query-LCFH2F2X.js +0 -55
  88. package/build/filters_query-LCFH2F2X.js.map +0 -1
  89. package/build/includes_query-PVONWQMC.js +0 -70
  90. package/build/includes_query-PVONWQMC.js.map +0 -1
  91. package/build/index.js.map +0 -1
  92. package/build/metafile-esm.json +0 -1
  93. package/build/providers/api_query_provider.js.map +0 -1
  94. package/build/sorts_query-NJTC5UXX.js +0 -63
  95. package/build/sorts_query-NJTC5UXX.js.map +0 -1
  96. package/build/src/bindings/api_query_request.d.ts +0 -2
  97. package/build/src/bindings/filters_query.d.ts +0 -3
  98. package/build/src/bindings/includes_query.d.ts +0 -3
  99. package/build/src/bindings/sorts_query.d.ts +0 -3
  100. package/build/src/exceptions/invalid_field_query.d.ts +0 -5
  101. package/build/src/types.d.ts +0 -90
  102. package/build/src/types.js +0 -1
  103. package/build/src/types.js.map +0 -1
  104. package/build/src/utils/helpers.d.ts +0 -3
  105. /package/build/{config.stub → stubs/config.stub} +0 -0
@@ -1,12 +1,16 @@
1
- import { type DialectContract } from '@adonisjs/lucid/types/database';
2
- import { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';
3
- import { type StrictValuesWithoutRaw } from '@adonisjs/lucid/types/querybuilder';
4
- import { type Filter } from '../types.js';
5
- import { FiltersExact } from './filters_exact.js';
6
- export declare class FiltersPartial<Model extends LucidModel> extends FiltersExact<Model> implements Filter<Model> {
7
- handle(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, value: StrictValuesWithoutRaw | null, property: string): void;
8
- protected parsePropertyToColumn(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, property: string): string;
9
- protected getDatabaseDialect(query: ModelQueryBuilderContract<Model, InstanceType<Model>>): DialectContract['name'];
10
- protected getWhereRawParameters(value: StrictValuesWithoutRaw | null, property: string): [string, string[]];
11
- protected static escapeLike(value: string): string;
1
+ import { Filter } from "../../types.js";
2
+ import { FiltersExact } from "./filters_exact.js";
3
+ import { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
4
+ import { StrictValuesWithoutRaw } from "@adonisjs/lucid/types/querybuilder";
5
+ import { DialectContract } from "@adonisjs/lucid/types/database";
6
+
7
+ //#region src/filters/filters_partial.d.ts
8
+ declare class FiltersPartial<Model extends LucidModel> extends FiltersExact<Model> implements Filter<Model> {
9
+ handle(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, value: StrictValuesWithoutRaw | null, property: string): void;
10
+ protected parsePropertyToColumn(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, property: string): string;
11
+ protected getDatabaseDialect(query: ModelQueryBuilderContract<Model, InstanceType<Model>>): DialectContract['name'];
12
+ protected getWhereRawParameters(value: StrictValuesWithoutRaw | null, property: string): [string, string[]];
13
+ protected static escapeLike(value: string): string;
12
14
  }
15
+ //#endregion
16
+ export { FiltersPartial };
@@ -0,0 +1,39 @@
1
+ import { FiltersExact } from "./filters_exact.js";
2
+ //#region src/filters/filters_partial.ts
3
+ var FiltersPartial = class FiltersPartial extends FiltersExact {
4
+ handle(query, value, property) {
5
+ if (this.shouldAddRelationConstraint && this.isRelationProperty(query, property)) {
6
+ this.withRelationConstraint(query, value, property);
7
+ return;
8
+ }
9
+ if (Array.isArray(value)) {
10
+ if (value.every((item) => item.toString().length === 0)) return;
11
+ query.where((subQuery) => {
12
+ const subValues = value.filter((item) => item.toString().length > 0);
13
+ for (const partialValue of subValues) {
14
+ const [innerSql, innerBindings] = this.getWhereRawParameters(partialValue, this.parsePropertyToColumn(subQuery, property));
15
+ subQuery.orWhereRaw(innerSql, innerBindings);
16
+ }
17
+ });
18
+ return;
19
+ }
20
+ const [sql, bindings] = this.getWhereRawParameters(value, this.parsePropertyToColumn(query, property));
21
+ query.whereRaw(sql, bindings);
22
+ }
23
+ parsePropertyToColumn(query, property) {
24
+ if (property.includes(".")) return property;
25
+ return query.model.$getColumn(property)?.columnName ?? property;
26
+ }
27
+ getDatabaseDialect(query) {
28
+ return query.client.dialect.name;
29
+ }
30
+ getWhereRawParameters(value, property) {
31
+ const resolvedValue = String(value).toLowerCase();
32
+ return ["LOWER(??) LIKE ?", [property, `%${FiltersPartial.escapeLike(resolvedValue)}%`]];
33
+ }
34
+ static escapeLike(value) {
35
+ return value.replaceAll("\\", "\\\\").replaceAll("_", String.raw`\\_`).replaceAll("%", String.raw`\\%`);
36
+ }
37
+ };
38
+ //#endregion
39
+ export { FiltersPartial };
@@ -1,6 +1,10 @@
1
- import { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';
2
- import { type StrictValuesWithoutRaw } from '@adonisjs/lucid/types/querybuilder';
3
- import { type Filter } from '../types.js';
4
- export declare class FiltersTrashed<Model extends LucidModel> implements Filter<Model> {
5
- handle(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, value: StrictValuesWithoutRaw, _property: string): void;
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_trashed.d.ts
6
+ declare class FiltersTrashed<Model extends LucidModel> implements Filter<Model> {
7
+ handle(query: ModelQueryBuilderContract<Model, InstanceType<Model>>, value: StrictValuesWithoutRaw | null, _property: string): void;
6
8
  }
9
+ //#endregion
10
+ export { FiltersTrashed };
@@ -0,0 +1,14 @@
1
+ //#region src/filters/filters_trashed.ts
2
+ var FiltersTrashed = class {
3
+ handle(query, value, _property) {
4
+ if (!("withTrashed" in query && "onlyTrashed" in query)) return;
5
+ const queryWithSoftDeletes = query;
6
+ if (value === "with") {
7
+ queryWithSoftDeletes.withTrashed();
8
+ return;
9
+ }
10
+ if (value === "only") queryWithSoftDeletes.onlyTrashed();
11
+ }
12
+ };
13
+ //#endregion
14
+ export { FiltersTrashed };
@@ -1,8 +1,12 @@
1
- import { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';
2
- import { type ModelRelations } from '@adonisjs/lucid/types/relations';
3
- import { type Include } from '../types.js';
4
- export declare class IncludedCallback<ParentModel extends LucidModel, RelatedModel extends LucidModel> implements Include<ParentModel> {
5
- readonly callback: (query: ModelRelations<RelatedModel, ParentModel>['builder'] | ModelRelations<RelatedModel, ParentModel>['subQuery']) => void;
6
- constructor(callback: (query: ModelRelations<RelatedModel, ParentModel>['builder'] | ModelRelations<RelatedModel, ParentModel>['subQuery']) => void);
7
- handle(query: ModelQueryBuilderContract<ParentModel, InstanceType<ParentModel>>, include: string): void;
1
+ import { Include } from "../../types.js";
2
+ import { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
3
+ import { ModelRelations } from "@adonisjs/lucid/types/relations";
4
+
5
+ //#region src/includes/included_callback.d.ts
6
+ declare class IncludedCallback<ParentModel extends LucidModel, RelatedModel extends LucidModel> implements Include<ParentModel> {
7
+ readonly callback: (query: ModelRelations<RelatedModel, ParentModel>['builder'] | ModelRelations<RelatedModel, ParentModel>['subQuery']) => void;
8
+ constructor(callback: (query: ModelRelations<RelatedModel, ParentModel>['builder'] | ModelRelations<RelatedModel, ParentModel>['subQuery']) => void);
9
+ handle(query: ModelQueryBuilderContract<ParentModel, InstanceType<ParentModel>>, include: string): void;
8
10
  }
11
+ //#endregion
12
+ export { IncludedCallback };
@@ -0,0 +1,12 @@
1
+ //#region src/includes/included_callback.ts
2
+ var IncludedCallback = class {
3
+ callback;
4
+ constructor(callback) {
5
+ this.callback = callback;
6
+ }
7
+ handle(query, include) {
8
+ query.preload(include, this.callback);
9
+ }
10
+ };
11
+ //#endregion
12
+ export { IncludedCallback };
@@ -1,5 +1,9 @@
1
- import { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';
2
- import { type Include } from '../types.js';
3
- export declare class IncludedCount<ParentModel extends LucidModel> implements Include<ParentModel> {
4
- handle(query: ModelQueryBuilderContract<ParentModel, InstanceType<ParentModel>>, count: string): void;
1
+ import { Include } from "../../types.js";
2
+ import { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
3
+
4
+ //#region src/includes/included_count.d.ts
5
+ declare class IncludedCount<ParentModel extends LucidModel> implements Include<ParentModel> {
6
+ handle(query: ModelQueryBuilderContract<ParentModel, InstanceType<ParentModel>>, count: string): void;
5
7
  }
8
+ //#endregion
9
+ export { IncludedCount };
@@ -0,0 +1,11 @@
1
+ import app from "@adonisjs/core/services/app";
2
+ //#region src/includes/included_count.ts
3
+ var IncludedCount = class {
4
+ handle(query, count) {
5
+ const suffix = app.config.get("apiquery.countSuffix", "Count");
6
+ const relation = count.endsWith(suffix) ? count.slice(0, -suffix.length) : count;
7
+ query.withCount(relation);
8
+ }
9
+ };
10
+ //#endregion
11
+ export { IncludedCount };
@@ -1,9 +1,13 @@
1
- import { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';
2
- import { Collection } from 'collect.js';
3
- import { type Include } from '../types.js';
4
- export declare class IncludedRelationship<ParentModel extends LucidModel> implements Include<ParentModel> {
5
- static getIndividualRelationshipPathsFromInclude(include: string): Collection<string>;
6
- getRequestedFieldsForRelatedTable?: (relationship: string) => string[];
7
- handle(query: ModelQueryBuilderContract<ParentModel, InstanceType<ParentModel>>, relationship: string): void;
8
- private buildNestedQuery;
1
+ import { Include } from "../../types.js";
2
+ import { Collection } from "collect.js";
3
+ import { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
4
+
5
+ //#region src/includes/included_relationship.d.ts
6
+ declare class IncludedRelationship<ParentModel extends LucidModel> implements Include<ParentModel> {
7
+ getRequestedFieldsForRelatedTable?: (relationship: string) => string[];
8
+ handle(query: ModelQueryBuilderContract<ParentModel, InstanceType<ParentModel>>, relationship: string): void;
9
+ static getIndividualRelationshipPathsFromInclude(include: string): Collection<string>;
10
+ private buildNestedQuery;
9
11
  }
12
+ //#endregion
13
+ export { IncludedRelationship };
@@ -0,0 +1,40 @@
1
+ import { Collection } from "collect.js";
2
+ //#region src/includes/included_relationship.ts
3
+ var IncludedRelationship = class {
4
+ getRequestedFieldsForRelatedTable;
5
+ handle(query, relationship) {
6
+ const relatedTables = relationship.split(".");
7
+ if (relatedTables.length === 0) return;
8
+ const [relation, ...rest] = relatedTables;
9
+ if (!query.model.$hasRelation(relation)) return;
10
+ query.preload(relation, (subQuery) => {
11
+ if (this.getRequestedFieldsForRelatedTable !== void 0) {
12
+ const fields = this.getRequestedFieldsForRelatedTable(relation);
13
+ if (fields.length > 0) subQuery.select(fields);
14
+ }
15
+ this.buildNestedQuery(rest, subQuery, relation);
16
+ });
17
+ }
18
+ static getIndividualRelationshipPathsFromInclude(include) {
19
+ return new Collection(include.split(".")).reduce((includes, relationship) => {
20
+ const includesArray = includes ?? new Collection();
21
+ if (includesArray.isEmpty()) return includesArray.push(relationship);
22
+ return includesArray.push(`${includes.last()}.${relationship}`);
23
+ }, new Collection());
24
+ }
25
+ buildNestedQuery(relatedTables, subQuery, parent = "") {
26
+ if (relatedTables.length === 0) return;
27
+ const [relation, ...rest] = relatedTables;
28
+ if (!subQuery.model.$hasRelation(relation)) return;
29
+ subQuery.preload(relation, (nestedQuery) => {
30
+ const fullRelationName = parent === "" ? relation : `${parent}.${relation}`;
31
+ if (this.getRequestedFieldsForRelatedTable !== void 0) {
32
+ const fields = this.getRequestedFieldsForRelatedTable(fullRelationName);
33
+ if (fields.length > 0) nestedQuery.select(fields);
34
+ }
35
+ this.buildNestedQuery(rest, nestedQuery, fullRelationName);
36
+ });
37
+ }
38
+ };
39
+ //#endregion
40
+ export { IncludedRelationship };
@@ -1,7 +1,11 @@
1
- import { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';
2
- import { type Sort } from '../types.js';
3
- export declare class SortsCallback<Model extends LucidModel> implements Sort<Model> {
4
- private readonly _callback;
5
- constructor(_callback: (query: ModelQueryBuilderContract<Model>, descending: boolean, property: string) => void);
6
- handle(query: ModelQueryBuilderContract<Model>, descending: boolean, property: string): void;
1
+ import { Sort } from "../../types.js";
2
+ import { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
3
+
4
+ //#region src/sorts/sorts_callback.d.ts
5
+ declare class SortsCallback<Model extends LucidModel> implements Sort<Model> {
6
+ private readonly _callback;
7
+ constructor(_callback: (query: ModelQueryBuilderContract<Model>, isDescending: boolean, property: string) => void);
8
+ handle(query: ModelQueryBuilderContract<Model>, isDescending: boolean, property: string): void;
7
9
  }
10
+ //#endregion
11
+ export { SortsCallback };
@@ -0,0 +1,12 @@
1
+ //#region src/sorts/sorts_callback.ts
2
+ var SortsCallback = class {
3
+ _callback;
4
+ constructor(_callback) {
5
+ this._callback = _callback;
6
+ }
7
+ handle(query, isDescending, property) {
8
+ this._callback(query, isDescending, property);
9
+ }
10
+ };
11
+ //#endregion
12
+ export { SortsCallback };
@@ -1,5 +1,9 @@
1
- import { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';
2
- import { type Sort } from '../types.js';
3
- export declare class SortsField<Model extends LucidModel> implements Sort<Model> {
4
- handle(query: ModelQueryBuilderContract<Model>, descending: boolean, property: string): void;
1
+ import { Sort } from "../../types.js";
2
+ import { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
3
+
4
+ //#region src/sorts/sorts_field.d.ts
5
+ declare class SortsField<Model extends LucidModel> implements Sort<Model> {
6
+ handle(query: ModelQueryBuilderContract<Model>, isDescending: boolean, property: string): void;
5
7
  }
8
+ //#endregion
9
+ export { SortsField };
@@ -0,0 +1,8 @@
1
+ //#region src/sorts/sorts_field.ts
2
+ var SortsField = class {
3
+ handle(query, isDescending, property) {
4
+ query.orderBy(property, isDescending ? "desc" : "asc");
5
+ }
6
+ };
7
+ //#endregion
8
+ export { SortsField };
@@ -0,0 +1,26 @@
1
+ //#region src/utils/helpers.ts
2
+ const substrReplace = (str, replace, start, length) => {
3
+ if (start < 0) start += str.length;
4
+ length ??= str.length;
5
+ if (length < 0) length = length + str.length - start;
6
+ return [
7
+ str.slice(0, start),
8
+ replace.slice(0, Math.max(0, length)),
9
+ replace.slice(length),
10
+ str.slice(start + length)
11
+ ].join("");
12
+ };
13
+ const strBeforeLast = (subject, search) => {
14
+ if (search === "") return subject;
15
+ const pos = subject.lastIndexOf(search);
16
+ if (pos === -1) return subject;
17
+ return subject.slice(0, Math.max(0, pos));
18
+ };
19
+ const strAfterLast = (subject, search) => {
20
+ if (search === "") return subject;
21
+ const pos = subject.lastIndexOf(search);
22
+ if (pos === -1) return subject;
23
+ return subject.slice(pos + search.length);
24
+ };
25
+ //#endregion
26
+ export { strAfterLast, strBeforeLast, substrReplace };
@@ -1 +1,4 @@
1
- export declare const stubsRoot: string;
1
+ //#region stubs/main.d.ts
2
+ declare const stubsRoot: string;
3
+ //#endregion
4
+ export { stubsRoot };
@@ -0,0 +1,4 @@
1
+ //#region stubs/main.ts
2
+ const stubsRoot = import.meta.dirname;
3
+ //#endregion
4
+ export { stubsRoot };
@@ -0,0 +1,91 @@
1
+ import { LucidModel, ModelAttributes, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
2
+ import { StrictValuesWithoutRaw } from "@adonisjs/lucid/types/querybuilder";
3
+
4
+ //#region src/types.d.ts
5
+ interface ApiQueryConfigParameters {
6
+ include?: string;
7
+ filter?: string;
8
+ sort?: string;
9
+ fields?: string;
10
+ append?: string;
11
+ }
12
+ interface ApiQueryConfig {
13
+ /**
14
+ * By default the package will use the `include`, `filter`, `sort`
15
+ * and `fields` query parameters as described in the readme.
16
+ *
17
+ * You can customize these query string parameters here.
18
+ */
19
+ parameters?: ApiQueryConfigParameters;
20
+ /**
21
+ * Related model counts are included using the relationship name suffixed with this string.
22
+ * For example: GET /users?include=postsCount
23
+ */
24
+ countSuffix?: string;
25
+ /**
26
+ * Related model exists are included using the relationship name suffixed with this string.
27
+ * For example: GET /users?include=postsExists
28
+ */
29
+ existsSuffix?: string;
30
+ /**
31
+ * By default the package will throw an `InvalidFilterQuery` exception when a filter in the
32
+ * URL is not allowed in the `allowedFilters()` method.
33
+ */
34
+ disableInvalidFilterQueryException?: boolean;
35
+ /**
36
+ * By default the package will throw an `InvalidSortQuery` exception when a sort in the
37
+ * URL is not allowed in the `allowedSorts()` method.
38
+ */
39
+ disableInvalidSortQueryException?: boolean;
40
+ /**
41
+ * By default the package will throw an `InvalidIncludeQuery` exception when an include in the
42
+ * URL is not allowed in the `allowedIncludes()` method.
43
+ */
44
+ disableInvalidIncludesQueryException?: boolean;
45
+ /**
46
+ * By default, the package expects relationship names to be camel case plural when using fields[relationship].
47
+ * For example, fetching the id and name for a userOwner relation would look like this:
48
+ * GET /users?fields[userOwner]=id,name
49
+ *
50
+ * Set this to `true` if you don't want that and keep the requested relationship names as-is and allows you to
51
+ * request the fields using a snake case relationship name:
52
+ * GET /users?fields[user_owner]=id,name
53
+ */
54
+ convertRelationNamesToSnakeCasePlural?: boolean;
55
+ /**
56
+ * By default, the package expects relationship names to be camel case plural when using fields[relationship].
57
+ * For example, fetching the id and name for a userOwner relation would look like this:
58
+ * GET /users?fields[userOwner]=id,name
59
+ *
60
+ * Set this to one of `snake_case`, `camelCase` or `none` if you want to enable table name resolution in addition to the relation name resolution
61
+ * GET /users?include=top_orders&fields[orders]=id,name
62
+ */
63
+ convertRelationTableNameStrategy?: 'snake_case' | 'camelCase' | 'none' | false;
64
+ /**
65
+ * By default, the package expects the field names to match the database names
66
+ * For example, fetching the field named firstName would look like this:
67
+ * GET /users?fields=firstName
68
+ *
69
+ * Set this to `true` if you want to convert the firstName into first_name for the underlying query
70
+ */
71
+ convertFieldNamesToSnakeCase?: boolean;
72
+ }
73
+ type ResolvedApiQueryConfig = Required<ApiQueryConfig> & {
74
+ parameters: Required<ApiQueryConfigParameters>;
75
+ };
76
+ type EnumType<T> = T[keyof T];
77
+ interface Sort<Model extends LucidModel> {
78
+ handle: (query: ModelQueryBuilderContract<Model, InstanceType<Model>>, isDescending: boolean, property: string) => void;
79
+ }
80
+ interface Filter<Model extends LucidModel> {
81
+ handle: (query: ModelQueryBuilderContract<Model, InstanceType<Model>>, value: StrictValuesWithoutRaw | null, property: string) => void;
82
+ }
83
+ interface Include<ParentModel extends LucidModel> {
84
+ handle: (query: ModelQueryBuilderContract<ParentModel, InstanceType<ParentModel>>, include: string) => void;
85
+ }
86
+ type ExtractKeys<T> = T extends object ? { [K in keyof T & string]: K }[keyof T & string] : never;
87
+ type ExtractKeysWithSort<T> = T extends object ? { [K in keyof T & string]: `-${K}` }[keyof T & string] : never;
88
+ type SortUnionKeyParams<Model extends LucidModel> = ExtractKeys<ModelAttributes<InstanceType<Model>>> | ExtractKeysWithSort<ModelAttributes<InstanceType<Model>>>;
89
+ type HintedString<KnownValues> = KnownValues extends string ? (string & {}) | KnownValues : never;
90
+ //#endregion
91
+ export { ApiQueryConfig, ApiQueryConfigParameters, EnumType, ExtractKeys, ExtractKeysWithSort, Filter, HintedString, Include, ResolvedApiQueryConfig, Sort, SortUnionKeyParams };
package/build/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,60 +1,8 @@
1
1
  {
2
2
  "name": "@eienjs/adonisjs-api-query",
3
- "description": "Easily build Lucid queries from API requests",
4
- "version": "1.1.0",
5
3
  "type": "module",
6
- "module": "./build/index.js",
7
- "types": "./build/index.d.ts",
8
- "files": [
9
- "build",
10
- "!build/bin",
11
- "!build/tests"
12
- ],
13
- "exports": {
14
- ".": "./build/index.js",
15
- "./types": "./build/src/types.js",
16
- "./api_query_provider": "./build/providers/api_query_provider.js"
17
- },
18
- "devDependencies": {
19
- "@adonisjs/assembler": "^7.8.2",
20
- "@adonisjs/core": "^6.17.2",
21
- "@adonisjs/lucid": "^21.6.0",
22
- "@commitlint/cli": "^19.8.1",
23
- "@commitlint/config-conventional": "^19.8.1",
24
- "@japa/assert": "^4.0.1",
25
- "@japa/file-system": "^2.3.2",
26
- "@japa/runner": "^4.2.0",
27
- "@nodecfdi/eslint-config": "^3.2.1",
28
- "@nodecfdi/prettier-config": "^1.4.1",
29
- "@nodecfdi/tsconfig": "^1.7.4",
30
- "@poppinss/hooks": "^7.2.5",
31
- "@swc/core": "^1.11.24",
32
- "@types/luxon": "^3.6.2",
33
- "@types/node": "^22.15.17",
34
- "adonis-lucid-soft-deletes": "^2.1.0",
35
- "auto-changelog": "^2.5.0",
36
- "better-sqlite3": "^11.10.0",
37
- "c8": "^10.1.3",
38
- "del-cli": "^6.0.0",
39
- "enforce-unique": "^1.3.0",
40
- "eslint": "^9.26.0",
41
- "husky": "^9.1.7",
42
- "is-in-ci": "^1.0.0",
43
- "luxon": "^3.6.1",
44
- "native-copyfiles": "^0.3.2",
45
- "np": "^10.2.0",
46
- "prettier": "^3.5.3",
47
- "ts-node-maintained": "^10.9.5",
48
- "tsup": "^8.4.0",
49
- "typescript": "^5.8.3"
50
- },
51
- "dependencies": {
52
- "collect.js": "^4.36.1"
53
- },
54
- "peerDependencies": {
55
- "@adonisjs/core": "^6.17.2",
56
- "@adonisjs/lucid": "^21.6.0"
57
- },
4
+ "version": "2.0.0",
5
+ "description": "Easily build Lucid queries from API requests",
58
6
  "author": "Fernando Isidro <luffynando@gmail.com>",
59
7
  "license": "MIT",
60
8
  "homepage": "https://github.com/eienjs/adonisjs-api-query",
@@ -76,8 +24,62 @@
76
24
  "sort",
77
25
  "includes"
78
26
  ],
27
+ "exports": {
28
+ ".": "./build/index.js",
29
+ "./providers/api_query_provider": "./build/providers/api_query_provider.js",
30
+ "./types": "./build/types.js",
31
+ "./package.json": "./package.json"
32
+ },
33
+ "types": "build/index.d.ts",
34
+ "files": [
35
+ "build"
36
+ ],
79
37
  "engines": {
80
- "node": ">=20.6.0"
38
+ "node": ">=24.0.0"
39
+ },
40
+ "peerDependencies": {
41
+ "@adonisjs/assembler": "^8.4.0",
42
+ "@adonisjs/core": "^7.3.4",
43
+ "@adonisjs/lucid": "^22.4.2"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "@adonisjs/assembler": {
47
+ "optional": true
48
+ }
49
+ },
50
+ "dependencies": {
51
+ "collect.js": "^4.36.1"
52
+ },
53
+ "devDependencies": {
54
+ "@adonisjs/assembler": "^8.4.0",
55
+ "@adonisjs/core": "^7.3.4",
56
+ "@adonisjs/eslint-plugin": "^2.2.2",
57
+ "@adonisjs/lucid": "^22.4.2",
58
+ "@adonisjs/tsconfig": "^2.0.0",
59
+ "@codenameryuu/adonis-lucid-soft-deletes": "^2.0.3",
60
+ "@commitlint/cli": "^21.1.0",
61
+ "@commitlint/config-conventional": "^21.1.0",
62
+ "@eienjs/eslint-config": "^2.1.2",
63
+ "@japa/assert": "^4.2.0",
64
+ "@japa/file-system": "^3.0.0",
65
+ "@japa/runner": "^5.3.0",
66
+ "@poppinss/hooks": "^7.3.0",
67
+ "@poppinss/ts-exec": "^1.4.4",
68
+ "@types/luxon": "^3.7.2",
69
+ "@types/node": "^24.13.2",
70
+ "auto-changelog": "^2.6.0",
71
+ "better-sqlite3": "^12.11.1",
72
+ "c8": "^11.0.0",
73
+ "enforce-unique": "^1.3.0",
74
+ "eslint": "^10.6.0",
75
+ "eslint-plugin-erasable-syntax-only": "^0.4.2",
76
+ "husky": "^9.1.7",
77
+ "is-in-ci": "^2.0.0",
78
+ "luxon": "^3.7.2",
79
+ "release-it": "^20.2.1",
80
+ "tsdown": "^0.22.3",
81
+ "tsdown-stale-guard": "^0.1.2",
82
+ "typescript": "^6.0.3"
81
83
  },
82
84
  "c8": {
83
85
  "reporter": [
@@ -94,51 +96,60 @@
94
96
  "@commitlint/config-conventional"
95
97
  ]
96
98
  },
97
- "prettier": "@nodecfdi/prettier-config/pkg",
98
99
  "publishConfig": {
99
100
  "access": "public",
100
101
  "tag": "latest"
101
102
  },
102
103
  "auto-changelog": {
103
104
  "template": "keepachangelog",
104
- "hideCredit": true
105
+ "hideCredit": true,
106
+ "commitLimit": false
105
107
  },
106
- "np": {
107
- "message": "chore(release): :tada: %s",
108
- "tag": "latest",
109
- "branch": "main",
110
- "testScript": "test"
111
- },
112
- "tsup": {
113
- "entry": [
114
- "index.ts",
115
- "src/types.ts",
116
- "providers/api_query_provider.ts"
117
- ],
118
- "outDir": "./build",
119
- "clean": true,
120
- "format": "esm",
121
- "dts": false,
122
- "sourcemap": true,
123
- "target": "esnext"
108
+ "release-it": {
109
+ "git": {
110
+ "commit": true,
111
+ "tag": true,
112
+ "push": true,
113
+ "requireCleanWorkingDir": true,
114
+ "commitMessage": "chore(release): :tada: v${version}",
115
+ "tagAnnotation": "chore(release): :tada: v${version}"
116
+ },
117
+ "github": {
118
+ "release": true,
119
+ "web": true,
120
+ "releaseName": "Release v${version}"
121
+ },
122
+ "npm": {
123
+ "publish": true,
124
+ "publishPackageManager": "pnpm",
125
+ "publishArgs": [
126
+ "--no-git-checks"
127
+ ]
128
+ },
129
+ "hooks": {
130
+ "before:init": [
131
+ "pnpm run lint:check",
132
+ "pnpm run typecheck",
133
+ "pnpm test"
134
+ ],
135
+ "after:bump": [
136
+ "pnpm run build",
137
+ "pnpm run changelog"
138
+ ]
139
+ }
124
140
  },
125
141
  "scripts": {
126
- "clean": "del-cli build",
127
- "copy:templates": "copyfiles \"stubs/**/*.stub\" build --up 1",
128
- "changelog": "auto-changelog -p && git add CHANGELOG.md",
129
- "typecheck": "tsc --noEmit",
142
+ "changelog": "auto-changelog -u -p",
143
+ "commitlint": "commitlint --edit",
144
+ "index:commands": "adonis-kit index build/commands",
130
145
  "lint": "eslint . --fix",
131
146
  "lint:check": "eslint .",
132
- "format": "prettier --write .",
133
- "format:check": "prettier --check .",
134
- "test": "node --import ts-node-maintained/register/esm --enable-source-maps bin/test.ts",
147
+ "typecheck": "tsc --noEmit",
148
+ "test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts",
135
149
  "test:coverage": "c8 pnpm run test",
136
- "tool:code": "pnpm run lint:check && pnpm run format:check && pnpm run typecheck",
150
+ "tool:code": "pnpm run lint:check && pnpm run typecheck",
137
151
  "tool:build": "pnpm run tool:code && pnpm run test",
138
- "prebuild": "pnpm run tool:code && pnpm run clean",
139
- "build": "tsup-node --metafile && tsc --emitDeclarationOnly --declaration",
140
- "postbuild": "pnpm run copy:templates",
141
- "release": "np",
142
- "version": "pnpm run build && pnpm run changelog"
152
+ "build": "tsdown",
153
+ "release": "release-it"
143
154
  }
144
155
  }