@eienjs/adonisjs-api-query 1.1.1 → 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,160 +0,0 @@
1
- import {
2
- InvalidQuery
3
- } from "./chunk-XIRHVLVQ.js";
4
-
5
- // src/includes/included_callback.ts
6
- var IncludedCallback = class {
7
- constructor(callback) {
8
- this.callback = callback;
9
- }
10
- handle(query, include) {
11
- void query.preload(include, this.callback);
12
- }
13
- };
14
-
15
- // src/includes/included_count.ts
16
- import app from "@adonisjs/core/services/app";
17
- var IncludedCount = class {
18
- handle(query, count) {
19
- const suffix = app.config.get("apiquery.countSuffix", "Count");
20
- const relation = count.endsWith(suffix) ? count.slice(0, -suffix.length) : count;
21
- void query.withCount(relation);
22
- }
23
- };
24
-
25
- // src/includes/included_relationship.ts
26
- import { Collection } from "collect.js";
27
- var IncludedRelationship = class {
28
- static getIndividualRelationshipPathsFromInclude(include) {
29
- const originalInclude = new Collection(include.split("."));
30
- return originalInclude.reduce((includes, relationship) => {
31
- const includesArray = includes ?? new Collection();
32
- if (includesArray.isEmpty()) {
33
- return includesArray.push(relationship);
34
- }
35
- return includesArray.push(`${includes.last()}.${relationship}`);
36
- }, new Collection());
37
- }
38
- getRequestedFieldsForRelatedTable;
39
- handle(query, relationship) {
40
- const relatedTables = relationship.split(".");
41
- if (relatedTables.length === 0) {
42
- return;
43
- }
44
- const [relation, ...rest] = relatedTables;
45
- if (!query.model.$hasRelation(relation)) {
46
- return;
47
- }
48
- void query.preload(relation, (subQuery) => {
49
- if (this.getRequestedFieldsForRelatedTable !== void 0) {
50
- const fields = this.getRequestedFieldsForRelatedTable(relation);
51
- if (fields.length > 0) {
52
- void subQuery.select(fields);
53
- }
54
- }
55
- this.buildNestedQuery(rest, subQuery, relation);
56
- });
57
- }
58
- buildNestedQuery(relatedTables, subQuery, parent = "") {
59
- if (relatedTables.length === 0) {
60
- return;
61
- }
62
- const [relation, ...rest] = relatedTables;
63
- if (!subQuery.model.$hasRelation(relation)) {
64
- return;
65
- }
66
- void subQuery.preload(relation, (nestedQuery) => {
67
- const fullRelationName = parent === "" ? relation : `${parent}.${relation}`;
68
- if (this.getRequestedFieldsForRelatedTable !== void 0) {
69
- const fields = this.getRequestedFieldsForRelatedTable(fullRelationName);
70
- if (fields.length > 0) {
71
- void nestedQuery.select(fields);
72
- }
73
- }
74
- this.buildNestedQuery(rest, nestedQuery, fullRelationName);
75
- });
76
- }
77
- };
78
-
79
- // src/allowed_include.ts
80
- import app2 from "@adonisjs/core/services/app";
81
- import { Collection as Collection2 } from "collect.js";
82
- var AllowedInclude = class _AllowedInclude {
83
- static relationship(name, internalName) {
84
- internalName = internalName ?? name;
85
- return IncludedRelationship.getIndividualRelationshipPathsFromInclude(internalName).zip(IncludedRelationship.getIndividualRelationshipPathsFromInclude(name).toArray()).reduce((includes, args) => {
86
- const [relationship, alias] = args;
87
- includes = includes.push(
88
- new _AllowedInclude(alias, new IncludedRelationship(), relationship)
89
- );
90
- if (!relationship.includes(".")) {
91
- const countSuffix = app2.config.get("apiquery.countSuffix", "Count");
92
- for (const countAllowedInclude of _AllowedInclude.count(
93
- `${alias}${countSuffix}`,
94
- `${relationship}${countSuffix}`
95
- )) {
96
- includes = includes.push(countAllowedInclude);
97
- }
98
- }
99
- return includes;
100
- }, new Collection2());
101
- }
102
- static count(name, internalName) {
103
- return new Collection2([new _AllowedInclude(name, new IncludedCount(), internalName)]);
104
- }
105
- static callback(name, callback, internalName) {
106
- return new Collection2([
107
- new _AllowedInclude(name, new IncludedCallback(callback), internalName)
108
- ]);
109
- }
110
- static custom(name, includeClass, internalName) {
111
- return new Collection2([new _AllowedInclude(name, includeClass, internalName)]);
112
- }
113
- internalName;
114
- name;
115
- includeClass;
116
- constructor(name, includeClass, internalName) {
117
- this.name = name;
118
- this.includeClass = includeClass;
119
- this.internalName = internalName ?? this.name;
120
- }
121
- include(query) {
122
- this.includeClass.handle(query, this.internalName);
123
- }
124
- getName() {
125
- return this.name;
126
- }
127
- isForInclude(includeName) {
128
- return this.name === includeName;
129
- }
130
- };
131
-
132
- // src/exceptions/invalid_include_query.ts
133
- import { ResponseStatus } from "@adonisjs/core/http";
134
- var InvalidIncludeQuery = class _InvalidIncludeQuery extends InvalidQuery {
135
- constructor(unknownIncludes, allowedIncludes) {
136
- const notAllowed = unknownIncludes.join(", ");
137
- let message = `Requested include(s) \`${notAllowed}\` are not allowed. `;
138
- if (allowedIncludes.length > 0) {
139
- const allowed = allowedIncludes.join(", ");
140
- message = `${message}Allowed include(s) are \`${allowed}\``;
141
- } else {
142
- message = `${message}There are no allowed includes`;
143
- }
144
- super(message, { status: ResponseStatus.BadRequest });
145
- this.unknownIncludes = unknownIncludes;
146
- this.allowedIncludes = allowedIncludes;
147
- }
148
- static includesNotAllowed(unknownIncludes, allowedIncludes) {
149
- return new _InvalidIncludeQuery(unknownIncludes, allowedIncludes);
150
- }
151
- };
152
-
153
- export {
154
- IncludedCallback,
155
- IncludedCount,
156
- IncludedRelationship,
157
- AllowedInclude,
158
- InvalidIncludeQuery
159
- };
160
- //# sourceMappingURL=chunk-IV3B5WO7.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/includes/included_callback.ts","../src/includes/included_count.ts","../src/includes/included_relationship.ts","../src/allowed_include.ts","../src/exceptions/invalid_include_query.ts"],"sourcesContent":["import { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';\nimport { type ExtractModelRelations, type ModelRelations } from '@adonisjs/lucid/types/relations';\nimport { type Include } from '../types.js';\n\nexport class IncludedCallback<ParentModel extends LucidModel, RelatedModel extends LucidModel>\n implements Include<ParentModel>\n{\n public constructor(\n public readonly callback: (\n query:\n | ModelRelations<RelatedModel, ParentModel>['builder']\n | ModelRelations<RelatedModel, ParentModel>['subQuery'],\n ) => void,\n ) {}\n\n public handle(query: ModelQueryBuilderContract<ParentModel, InstanceType<ParentModel>>, include: string): void {\n void query.preload(include as ExtractModelRelations<InstanceType<ParentModel>>, this.callback);\n }\n}\n","import app from '@adonisjs/core/services/app';\nimport { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';\nimport { type ExtractModelRelations } from '@adonisjs/lucid/types/relations';\nimport { type Include } from '../types.js';\n\nexport class IncludedCount<ParentModel extends LucidModel> implements Include<ParentModel> {\n public handle(query: ModelQueryBuilderContract<ParentModel, InstanceType<ParentModel>>, count: string): void {\n const suffix = app.config.get<string>('apiquery.countSuffix', 'Count');\n const relation = (count.endsWith(suffix) ? count.slice(0, -suffix.length) : count) as ExtractModelRelations<\n InstanceType<ParentModel>\n >;\n\n void query.withCount(relation);\n }\n}\n","import { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';\nimport { type ExtractModelRelations, type ModelRelations } from '@adonisjs/lucid/types/relations';\nimport { Collection } from 'collect.js';\nimport { type Include } from '../types.js';\n\nexport class IncludedRelationship<ParentModel extends LucidModel> implements Include<ParentModel> {\n public static getIndividualRelationshipPathsFromInclude(include: string): Collection<string> {\n const originalInclude = new Collection(include.split('.'));\n\n return originalInclude.reduce((includes, relationship) => {\n const includesArray = includes ?? new Collection<string>();\n\n if (includesArray.isEmpty()) {\n return includesArray.push(relationship);\n }\n\n return includesArray.push(`${includes!.last()}.${relationship}`);\n }, new Collection<string>()) as Collection<string>;\n }\n\n public getRequestedFieldsForRelatedTable?: (relationship: string) => string[];\n\n public handle(query: ModelQueryBuilderContract<ParentModel, InstanceType<ParentModel>>, relationship: string): void {\n const relatedTables = relationship.split('.');\n\n if (relatedTables.length === 0) {\n return;\n }\n\n const [relation, ...rest] = relatedTables;\n\n if (!query.model.$hasRelation(relation)) {\n return;\n }\n\n void query.preload(relation as ExtractModelRelations<InstanceType<ParentModel>>, (subQuery) => {\n if (this.getRequestedFieldsForRelatedTable !== undefined) {\n const fields = this.getRequestedFieldsForRelatedTable(relation);\n if (fields.length > 0) {\n void subQuery.select(fields);\n }\n }\n\n this.buildNestedQuery(rest, subQuery, relation);\n });\n }\n\n private buildNestedQuery<SubParentModel extends LucidModel, SubRelatedModel extends LucidModel>(\n relatedTables: string[],\n subQuery:\n | ModelRelations<SubRelatedModel, SubParentModel>['builder']\n | ModelRelations<SubRelatedModel, SubParentModel>['subQuery'],\n parent = '',\n ): void {\n if (relatedTables.length === 0) {\n return;\n }\n\n const [relation, ...rest] = relatedTables;\n\n if (!subQuery.model.$hasRelation(relation)) {\n return;\n }\n\n void subQuery.preload(relation as ExtractModelRelations<InstanceType<SubRelatedModel>>, (nestedQuery) => {\n const fullRelationName = parent === '' ? relation : `${parent}.${relation}`;\n if (this.getRequestedFieldsForRelatedTable !== undefined) {\n const fields = this.getRequestedFieldsForRelatedTable(fullRelationName);\n if (fields.length > 0) {\n void nestedQuery.select(fields);\n }\n }\n\n this.buildNestedQuery(rest, nestedQuery, fullRelationName);\n });\n }\n}\n","import app from '@adonisjs/core/services/app';\nimport { type LucidModel, type ModelQueryBuilderContract } from '@adonisjs/lucid/types/model';\nimport { type ModelRelations } from '@adonisjs/lucid/types/relations';\nimport { Collection } from 'collect.js';\nimport { IncludedCallback } from './includes/included_callback.js';\nimport { IncludedCount } from './includes/included_count.js';\nimport { IncludedRelationship } from './includes/included_relationship.js';\nimport { type Include } from './types.js';\n\nexport class AllowedInclude<Model extends LucidModel> {\n public static relationship<ParentModel extends LucidModel>(\n name: string,\n internalName?: string,\n ): Collection<AllowedInclude<ParentModel>> {\n internalName = internalName ?? name;\n\n return IncludedRelationship.getIndividualRelationshipPathsFromInclude(internalName)\n .zip(IncludedRelationship.getIndividualRelationshipPathsFromInclude(name).toArray<string>())\n .reduce((includes, args) => {\n const [relationship, alias] = args;\n\n includes = includes!.push(\n new AllowedInclude<ParentModel>(alias, new IncludedRelationship<ParentModel>(), relationship),\n );\n\n if (!relationship.includes('.')) {\n const countSuffix = app.config.get<string>('apiquery.countSuffix', 'Count');\n for (const countAllowedInclude of AllowedInclude.count(\n `${alias}${countSuffix}`,\n `${relationship}${countSuffix}`,\n )) {\n includes = includes.push(countAllowedInclude);\n }\n }\n\n return includes;\n }, new Collection<AllowedInclude<ParentModel>>()) as Collection<AllowedInclude<ParentModel>>;\n }\n\n public static count<ParentModel extends LucidModel>(\n name: string,\n internalName?: string,\n ): Collection<AllowedInclude<ParentModel>> {\n return new Collection([new AllowedInclude<ParentModel>(name, new IncludedCount<ParentModel>(), internalName)]);\n }\n\n public static callback<ParentModel extends LucidModel, RelatedModel extends LucidModel>(\n name: string,\n callback: (\n query:\n | ModelRelations<RelatedModel, ParentModel>['builder']\n | ModelRelations<RelatedModel, ParentModel>['subQuery'],\n ) => void,\n internalName?: string,\n ): Collection<AllowedInclude<ParentModel>> {\n return new Collection([\n new AllowedInclude<ParentModel>(name, new IncludedCallback<ParentModel, RelatedModel>(callback), internalName),\n ]);\n }\n\n public static custom<ParentModel extends LucidModel>(\n name: string,\n includeClass: Include<ParentModel>,\n internalName?: string,\n ): Collection<AllowedInclude<ParentModel>> {\n return new Collection([new AllowedInclude<ParentModel>(name, includeClass, internalName)]);\n }\n\n protected internalName: string;\n\n protected name: string;\n\n protected includeClass: Include<Model>;\n\n public constructor(name: string, includeClass: Include<Model>, internalName?: string) {\n this.name = name;\n this.includeClass = includeClass;\n this.internalName = internalName ?? this.name;\n }\n\n public include(query: ModelQueryBuilderContract<Model>): void {\n // if ('getRequestedFieldsForRelatedTable' in this.includeClass) {\n // this.includeClass.getRequestedFieldsForRelatedTable = (relationship: string) => {\n // return query.getRequestedFieldsForRelatedTable(relationship);\n // };\n // }\n\n this.includeClass.handle(query, this.internalName);\n }\n\n public getName(): string {\n return this.name;\n }\n\n public isForInclude(includeName: string): boolean {\n return this.name === includeName;\n }\n}\n","import { ResponseStatus } from '@adonisjs/core/http';\nimport { InvalidQuery } from './invalid_query.js';\n\nexport class InvalidIncludeQuery extends InvalidQuery {\n public constructor(\n public readonly unknownIncludes: string[],\n public readonly allowedIncludes: string[],\n ) {\n const notAllowed = unknownIncludes.join(', ');\n let message = `Requested include(s) \\`${notAllowed}\\` are not allowed. `;\n\n if (allowedIncludes.length > 0) {\n const allowed = allowedIncludes.join(', ');\n message = `${message}Allowed include(s) are \\`${allowed}\\``;\n } else {\n message = `${message}There are no allowed includes`;\n }\n\n super(message, { status: ResponseStatus.BadRequest });\n }\n\n public static includesNotAllowed(unknownIncludes: string[], allowedIncludes: string[]): InvalidIncludeQuery {\n return new InvalidIncludeQuery(unknownIncludes, allowedIncludes);\n }\n}\n"],"mappings":";;;;;AAIO,IA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,IACzD,OAAO;AACL,gBAAU,GAAG,OAAO;AAAA,IACtB;AAEA,UAAM,SAAS,EAAE,QAAQ,eAAe,WAAW,CAAC;AAbpC;AACA;AAAA,EAalB;AAAA,EAEA,OAAc,mBAAmB,iBAA2B,iBAAgD;AAC1G,WAAO,IAAI,qBAAoB,iBAAiB,eAAe;AAAA,EACjE;AACF;","names":["app","Collection","app","Collection"]}
@@ -1,198 +0,0 @@
1
- // src/api_query_builder_request.ts
2
- import { HttpContext } from "@adonisjs/core/http";
3
- import app from "@adonisjs/core/services/app";
4
- import { Collection } from "collect.js";
5
-
6
- // src/utils/helpers.ts
7
- var substrReplace = (str, replace, start, length) => {
8
- if (start < 0) {
9
- start += str.length;
10
- }
11
- length = length ?? str.length;
12
- if (length < 0) {
13
- length = length + str.length - start;
14
- }
15
- return [
16
- str.slice(0, start),
17
- replace.slice(0, Math.max(0, length)),
18
- replace.slice(length),
19
- str.slice(start + length)
20
- ].join("");
21
- };
22
- var strBeforeLast = (subject, search) => {
23
- if (search === "") {
24
- return subject;
25
- }
26
- const pos = subject.lastIndexOf(search);
27
- if (pos === -1) {
28
- return subject;
29
- }
30
- return subject.slice(0, Math.max(0, pos));
31
- };
32
- var strAfterLast = (subject, search) => {
33
- if (search === "") {
34
- return subject;
35
- }
36
- const pos = subject.lastIndexOf(search);
37
- if (pos === -1) {
38
- return subject;
39
- }
40
- return subject.slice(pos + search.length);
41
- };
42
-
43
- // src/api_query_builder_request.ts
44
- var ApiQueryBuilderRequest = class _ApiQueryBuilderRequest {
45
- static includesArrayValueDelimiter = ",";
46
- static appendsArrayValueDelimiter = ",";
47
- static fieldsArrayValueDelimiter = ",";
48
- static sortsArrayValueDelimiter = ",";
49
- static filterArrayValueDelimiter = ",";
50
- static setArrayValueDelimiter(delimiter) {
51
- this.includesArrayValueDelimiter = delimiter;
52
- this.appendsArrayValueDelimiter = delimiter;
53
- this.fieldsArrayValueDelimiter = delimiter;
54
- this.sortsArrayValueDelimiter = delimiter;
55
- this.filterArrayValueDelimiter = delimiter;
56
- }
57
- static setIncludesArrayValueDelimiter(includesArrayValueDelimiter) {
58
- this.includesArrayValueDelimiter = includesArrayValueDelimiter;
59
- }
60
- static setAppendsArrayValueDelimiter(appendsArrayValueDelimiter) {
61
- this.appendsArrayValueDelimiter = appendsArrayValueDelimiter;
62
- }
63
- static setFieldsArrayValueDelimiter(fieldsArrayValueDelimiter) {
64
- this.fieldsArrayValueDelimiter = fieldsArrayValueDelimiter;
65
- }
66
- static setSortsArrayValueDelimiter(sortsArrayValueDelimiter) {
67
- this.sortsArrayValueDelimiter = sortsArrayValueDelimiter;
68
- }
69
- static setFilterArrayValueDelimiter(filterArrayValueDelimiter) {
70
- this.filterArrayValueDelimiter = filterArrayValueDelimiter;
71
- }
72
- static getIncludesArrayValueDelimiter() {
73
- return this.includesArrayValueDelimiter;
74
- }
75
- static getAppendsArrayValueDelimiter() {
76
- return this.appendsArrayValueDelimiter;
77
- }
78
- static getFieldsArrayValueDelimiter() {
79
- return this.fieldsArrayValueDelimiter;
80
- }
81
- static getSortsArrayValueDelimiter() {
82
- return this.sortsArrayValueDelimiter;
83
- }
84
- static getFilterArrayValueDelimiter() {
85
- return this.filterArrayValueDelimiter;
86
- }
87
- static resetDelimiters() {
88
- this.includesArrayValueDelimiter = ",";
89
- this.appendsArrayValueDelimiter = ",";
90
- this.fieldsArrayValueDelimiter = ",";
91
- this.sortsArrayValueDelimiter = ",";
92
- this.filterArrayValueDelimiter = ",";
93
- }
94
- static fromRequest(request) {
95
- return new _ApiQueryBuilderRequest(request);
96
- }
97
- _request;
98
- constructor(request) {
99
- if (!request) {
100
- const ctx = HttpContext.getOrFail();
101
- request = ctx.request;
102
- }
103
- this._request = request;
104
- }
105
- includes() {
106
- const includeParameterName = app.config.get("apiquery.parameters.include", "include");
107
- let includeParts = this.getRequestData(includeParameterName, []);
108
- if (typeof includeParts === "string") {
109
- includeParts = includeParts.split(_ApiQueryBuilderRequest.getIncludesArrayValueDelimiter());
110
- }
111
- return new Collection(includeParts).filter();
112
- }
113
- appends() {
114
- const appendParameterName = app.config.get("apiquery.parameters.append", "append");
115
- let appendParts = this.getRequestData(appendParameterName, {});
116
- if (typeof appendParts === "string") {
117
- appendParts = appendParts.split(_ApiQueryBuilderRequest.getAppendsArrayValueDelimiter());
118
- }
119
- return new Collection(appendParts).filter();
120
- }
121
- fields() {
122
- const fieldsParameterName = app.config.get("apiquery.parameters.fields", "fields");
123
- const fieldsData = this.getRequestData(fieldsParameterName, {});
124
- const fieldsPerTable = new Collection(
125
- typeof fieldsData === "string" ? fieldsData.split(_ApiQueryBuilderRequest.getFieldsArrayValueDelimiter()) : fieldsData
126
- );
127
- if (fieldsPerTable.isEmpty()) {
128
- return new Collection();
129
- }
130
- const fields = {};
131
- fieldsPerTable.each((tableFields, model) => {
132
- if (!model || typeof model === "number") {
133
- model = typeof tableFields === "string" && tableFields.includes(".") ? strBeforeLast(tableFields, ".") : "_";
134
- }
135
- if (!fields[model]) {
136
- fields[model] = [];
137
- }
138
- if (typeof tableFields === "string") {
139
- tableFields = tableFields.split(_ApiQueryBuilderRequest.getFieldsArrayValueDelimiter()).map((field) => {
140
- return strAfterLast(field, ".");
141
- });
142
- }
143
- fields[model] = [...fields[model], ...tableFields];
144
- });
145
- return new Collection(fields);
146
- }
147
- sorts() {
148
- const sortParameterName = app.config.get("apiquery.parameters.sort", "sort");
149
- let sortParts = this.getRequestData(sortParameterName, []);
150
- if (typeof sortParts === "string") {
151
- sortParts = sortParts.split(_ApiQueryBuilderRequest.getSortsArrayValueDelimiter());
152
- }
153
- return new Collection(sortParts).filter();
154
- }
155
- filters() {
156
- const filterParameterName = app.config.get("apiquery.parameters.filter", "filter");
157
- const filterParts = this.getRequestData(filterParameterName, []);
158
- if (typeof filterParts === "string") {
159
- return new Collection();
160
- }
161
- const filters = new Collection(filterParts);
162
- return filters.map((value) => {
163
- return this.getFilterValue(value);
164
- });
165
- }
166
- getFilterValue(value) {
167
- if (value === void 0 || value === null) {
168
- return null;
169
- }
170
- if (value === "" || Array.isArray(value) && value.length === 0 || typeof value === "object" && Object.keys(value).length === 0) {
171
- return typeof value === "object" ? [] : value;
172
- }
173
- if (Array.isArray(value) || typeof value === "object") {
174
- return new Collection(value).map((valueValue) => {
175
- return this.getFilterValue(valueValue);
176
- }).all();
177
- }
178
- if (typeof value === "string" && value.includes(_ApiQueryBuilderRequest.getFilterArrayValueDelimiter())) {
179
- return value.split(_ApiQueryBuilderRequest.getFilterArrayValueDelimiter());
180
- }
181
- if (value === "true") {
182
- return true;
183
- }
184
- if (value === "false") {
185
- return false;
186
- }
187
- return value;
188
- }
189
- getRequestData(key, defaultValue) {
190
- return this._request.input(key, defaultValue);
191
- }
192
- };
193
-
194
- export {
195
- substrReplace,
196
- ApiQueryBuilderRequest
197
- };
198
- //# sourceMappingURL=chunk-MKQ3HMMA.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/api_query_builder_request.ts","../src/utils/helpers.ts"],"sourcesContent":["import { HttpContext, type Request } from '@adonisjs/core/http';\nimport app from '@adonisjs/core/services/app';\nimport { Collection } from 'collect.js';\nimport { strAfterLast, strBeforeLast } from './utils/helpers.js';\n\nexport class ApiQueryBuilderRequest {\n protected static includesArrayValueDelimiter = ',';\n\n protected static appendsArrayValueDelimiter = ',';\n\n protected static fieldsArrayValueDelimiter = ',';\n\n protected static sortsArrayValueDelimiter = ',';\n\n protected static filterArrayValueDelimiter = ',';\n\n public static setArrayValueDelimiter(delimiter: string): void {\n this.includesArrayValueDelimiter = delimiter;\n this.appendsArrayValueDelimiter = delimiter;\n this.fieldsArrayValueDelimiter = delimiter;\n this.sortsArrayValueDelimiter = delimiter;\n this.filterArrayValueDelimiter = delimiter;\n }\n\n public static setIncludesArrayValueDelimiter(includesArrayValueDelimiter: string): void {\n this.includesArrayValueDelimiter = includesArrayValueDelimiter;\n }\n\n public static setAppendsArrayValueDelimiter(appendsArrayValueDelimiter: string): void {\n this.appendsArrayValueDelimiter = appendsArrayValueDelimiter;\n }\n\n public static setFieldsArrayValueDelimiter(fieldsArrayValueDelimiter: string): void {\n this.fieldsArrayValueDelimiter = fieldsArrayValueDelimiter;\n }\n\n public static setSortsArrayValueDelimiter(sortsArrayValueDelimiter: string): void {\n this.sortsArrayValueDelimiter = sortsArrayValueDelimiter;\n }\n\n public static setFilterArrayValueDelimiter(filterArrayValueDelimiter: string): void {\n this.filterArrayValueDelimiter = filterArrayValueDelimiter;\n }\n\n public static getIncludesArrayValueDelimiter(): string {\n return this.includesArrayValueDelimiter;\n }\n\n public static getAppendsArrayValueDelimiter(): string {\n return this.appendsArrayValueDelimiter;\n }\n\n public static getFieldsArrayValueDelimiter(): string {\n return this.fieldsArrayValueDelimiter;\n }\n\n public static getSortsArrayValueDelimiter(): string {\n return this.sortsArrayValueDelimiter;\n }\n\n public static getFilterArrayValueDelimiter(): string {\n return this.filterArrayValueDelimiter;\n }\n\n public static resetDelimiters(): void {\n this.includesArrayValueDelimiter = ',';\n this.appendsArrayValueDelimiter = ',';\n this.fieldsArrayValueDelimiter = ',';\n this.sortsArrayValueDelimiter = ',';\n this.filterArrayValueDelimiter = ',';\n }\n\n public static fromRequest(request: Request): ApiQueryBuilderRequest {\n return new ApiQueryBuilderRequest(request);\n }\n\n private readonly _request: Request;\n\n public constructor(request?: Request) {\n if (!request) {\n const ctx = HttpContext.getOrFail();\n request = ctx.request;\n }\n\n this._request = request;\n }\n\n public includes(): Collection<string> {\n const includeParameterName = app.config.get<string>('apiquery.parameters.include', 'include');\n let includeParts = this.getRequestData<string[] | string>(includeParameterName, []);\n\n if (typeof includeParts === 'string') {\n includeParts = includeParts.split(ApiQueryBuilderRequest.getIncludesArrayValueDelimiter());\n }\n\n return new Collection(includeParts).filter();\n }\n\n public appends(): Collection<unknown> {\n const appendParameterName = app.config.get<string>('apiquery.parameters.append', 'append');\n\n let appendParts = this.getRequestData(appendParameterName, {});\n\n if (typeof appendParts === 'string') {\n appendParts = appendParts.split(ApiQueryBuilderRequest.getAppendsArrayValueDelimiter());\n }\n\n return new Collection(appendParts).filter();\n }\n\n public fields(): Collection<unknown> {\n const fieldsParameterName = app.config.get<string>('apiquery.parameters.fields', 'fields');\n const fieldsData = this.getRequestData(fieldsParameterName, {});\n const fieldsPerTable = new Collection(\n typeof fieldsData === 'string'\n ? fieldsData.split(ApiQueryBuilderRequest.getFieldsArrayValueDelimiter())\n : fieldsData,\n );\n\n if (fieldsPerTable.isEmpty()) {\n return new Collection();\n }\n\n const fields: Record<string, unknown> = {};\n fieldsPerTable.each((tableFields, model) => {\n if (!model || typeof model === 'number') {\n model = typeof tableFields === 'string' && tableFields.includes('.') ? strBeforeLast(tableFields, '.') : '_';\n }\n\n if (!fields[model]) {\n fields[model] = [];\n }\n\n if (typeof tableFields === 'string') {\n tableFields = tableFields.split(ApiQueryBuilderRequest.getFieldsArrayValueDelimiter()).map((field) => {\n return strAfterLast(field, '.');\n });\n }\n\n fields[model] = [...(fields[model] as string[]), ...(tableFields as string[])];\n });\n\n return new Collection(fields);\n }\n\n public sorts(): Collection<string> {\n const sortParameterName = app.config.get<string>('apiquery.parameters.sort', 'sort');\n\n let sortParts = this.getRequestData<string[] | string>(sortParameterName, []);\n\n if (typeof sortParts === 'string') {\n sortParts = sortParts.split(ApiQueryBuilderRequest.getSortsArrayValueDelimiter());\n }\n\n return new Collection<string>(sortParts).filter();\n }\n\n public filters(): Collection<unknown> {\n const filterParameterName = app.config.get<string>('apiquery.parameters.filter', 'filter');\n\n const filterParts = this.getRequestData(filterParameterName, []);\n\n if (typeof filterParts === 'string') {\n return new Collection();\n }\n\n const filters = new Collection(filterParts);\n\n return filters.map((value) => {\n return this.getFilterValue(value);\n });\n }\n\n protected getFilterValue(value: unknown): unknown {\n if (value === undefined || value === null) {\n return null;\n }\n\n if (\n value === '' ||\n (Array.isArray(value) && value.length === 0) ||\n (typeof value === 'object' && Object.keys(value).length === 0)\n ) {\n return typeof value === 'object' ? [] : value;\n }\n\n if (Array.isArray(value) || typeof value === 'object') {\n return new Collection(value)\n .map((valueValue) => {\n return this.getFilterValue(valueValue);\n })\n .all();\n }\n\n if (typeof value === 'string' && value.includes(ApiQueryBuilderRequest.getFilterArrayValueDelimiter())) {\n return value.split(ApiQueryBuilderRequest.getFilterArrayValueDelimiter());\n }\n\n if (value === 'true') {\n return true;\n }\n\n if (value === 'false') {\n return false;\n }\n\n return value;\n }\n\n protected getRequestData<T = unknown>(key: string, defaultValue?: T): T {\n return this._request.input(key, defaultValue) as T;\n }\n}\n","export const substrReplace = (str: string, replace: string, start: number, length?: number): string => {\n if (start < 0) {\n start += str.length;\n }\n\n length = length ?? str.length;\n if (length < 0) {\n length = length + str.length - start;\n }\n\n return [\n str.slice(0, start),\n replace.slice(0, Math.max(0, length)),\n replace.slice(length),\n str.slice(start + length),\n ].join('');\n};\n\nexport const strBeforeLast = (subject: string, search: string): string => {\n if (search === '') {\n return subject;\n }\n\n const pos = subject.lastIndexOf(search);\n\n if (pos === -1) {\n return subject;\n }\n\n return subject.slice(0, Math.max(0, pos));\n};\n\nexport const strAfterLast = (subject: string, search: string): string => {\n if (search === '') {\n return subject;\n }\n\n const pos = subject.lastIndexOf(search);\n\n if (pos === -1) {\n return subject;\n }\n\n return subject.slice(pos + search.length);\n};\n"],"mappings":";AAAA,SAAS,mBAAiC;AAC1C,OAAO,SAAS;AAChB,SAAS,kBAAkB;;;ACFpB,IAAM,gBAAgB,CAAC,KAAa,SAAiB,OAAe,WAA4B;AACrG,MAAI,QAAQ,GAAG;AACb,aAAS,IAAI;AAAA,EACf;AAEA,WAAS,UAAU,IAAI;AACvB,MAAI,SAAS,GAAG;AACd,aAAS,SAAS,IAAI,SAAS;AAAA,EACjC;AAEA,SAAO;AAAA,IACL,IAAI,MAAM,GAAG,KAAK;AAAA,IAClB,QAAQ,MAAM,GAAG,KAAK,IAAI,GAAG,MAAM,CAAC;AAAA,IACpC,QAAQ,MAAM,MAAM;AAAA,IACpB,IAAI,MAAM,QAAQ,MAAM;AAAA,EAC1B,EAAE,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AAM,UAAU,IAAI,WAAW,WAAW;AAE1C,WAAO,QAAQ,IAAI,CAAC,UAAU;AAC5B,aAAO,KAAK,eAAe,KAAK;AAAA,IAClC,CAAC;AAAA,EACH;AAAA,EAEU,eAAe,OAAyB;AAChD,QAAI,UAAU,UAAa,UAAU,MAAM;AACzC,aAAO;AAAA,IACT;AAEA,QACE,UAAU,MACT,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,KACzC,OAAO,UAAU,YAAY,OAAO,KAAK,KAAK,EAAE,WAAW,GAC5D;AACA,aAAO,OAAO,UAAU,WAAW,CAAC,IAAI;AAAA,IAC1C;AAEA,QAAI,MAAM,QAAQ,KAAK,KAAK,OAAO,UAAU,UAAU;AACrD,aAAO,IAAI,WAAW,KAAK,EACxB,IAAI,CAAC,eAAe;AACnB,eAAO,KAAK,eAAe,UAAU;AAAA,MACvC,CAAC,EACA,IAAI;AAAA,IACT;AAEA,QAAI,OAAO,UAAU,YAAY,MAAM,SAAS,wBAAuB,6BAA6B,CAAC,GAAG;AACtG,aAAO,MAAM,MAAM,wBAAuB,6BAA6B,CAAC;AAAA,IAC1E;AAEA,QAAI,UAAU,QAAQ;AACpB,aAAO;AAAA,IACT;AAEA,QAAI,UAAU,SAAS;AACrB,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EAEU,eAA4B,KAAa,cAAqB;AACtE,WAAO,KAAK,SAAS,MAAM,KAAK,YAAY;AAAA,EAC9C;AACF;","names":[]}
@@ -1,10 +0,0 @@
1
- // src/exceptions/invalid_query.ts
2
- import { Exception } from "@adonisjs/core/exceptions";
3
- var InvalidQuery = class extends Exception {
4
- static code = "E_INVALID_QUERY_EXCEPTION";
5
- };
6
-
7
- export {
8
- InvalidQuery
9
- };
10
- //# sourceMappingURL=chunk-XIRHVLVQ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/exceptions/invalid_query.ts"],"sourcesContent":["import { Exception } from '@adonisjs/core/exceptions';\n\nexport abstract class InvalidQuery extends Exception {\n public static readonly code = 'E_INVALID_QUERY_EXCEPTION';\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAEnB,IAAe,eAAf,cAAoC,UAAU;AAAA,EACnD,OAAuB,OAAO;AAChC;","names":[]}
@@ -1,55 +0,0 @@
1
- import {
2
- AllowedFilter,
3
- InvalidFilterQuery
4
- } from "./chunk-54HNQTDY.js";
5
- import "./chunk-MKQ3HMMA.js";
6
- import "./chunk-XIRHVLVQ.js";
7
-
8
- // src/bindings/filters_query.ts
9
- import collect from "collect.js";
10
- var extendModelQueryBuilderWithFiltersQuery = function(builder, config) {
11
- const ensureAllFiltersExist = (self) => {
12
- if (config.disableInvalidFilterQueryException) {
13
- return;
14
- }
15
- const filterNames = self.$apiQueryBuilderRequest.filters().keys();
16
- const allowedFilterNames = self._allowedFilters.map((allowedFilter) => {
17
- return allowedFilter.getName();
18
- });
19
- const diff = filterNames.diff(allowedFilterNames);
20
- if (diff.isNotEmpty()) {
21
- throw InvalidFilterQuery.filtersNotAllowed(diff.all(), allowedFilterNames.all());
22
- }
23
- };
24
- const isFilterRequested = (self, allowedFilter) => {
25
- return self.$apiQueryBuilderRequest.filters().has(allowedFilter.getName());
26
- };
27
- const addRequestedFiltersToQuery = (query) => {
28
- query._allowedFilters.each((allowedFilter) => {
29
- if (isFilterRequested(query, allowedFilter)) {
30
- const value = query.$apiQueryBuilderRequest.filters().get(allowedFilter.getName());
31
- allowedFilter.filter(query, value);
32
- return;
33
- }
34
- if (allowedFilter.hasDefault()) {
35
- allowedFilter.filter(query, allowedFilter.getDefault());
36
- }
37
- });
38
- };
39
- builder.macro("allowedFilters", function(...filters) {
40
- const arrayFilters = Array.isArray(filters.at(0)) ? filters.at(0) : filters;
41
- this._allowedFilters = collect(arrayFilters).map((filter) => {
42
- if (filter instanceof AllowedFilter) {
43
- return filter;
44
- }
45
- return AllowedFilter.partial(filter);
46
- });
47
- ensureAllFiltersExist(this);
48
- addRequestedFiltersToQuery(this);
49
- return this;
50
- });
51
- };
52
- export {
53
- extendModelQueryBuilderWithFiltersQuery
54
- };
55
- //# sourceMappingURL=filters_query-LCFH2F2X.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/bindings/filters_query.ts"],"sourcesContent":["/* eslint-disable unicorn/no-array-method-this-argument, unicorn/no-array-callback-reference */\nimport { type ModelQueryBuilder } from '@adonisjs/lucid/orm';\nimport { type LucidModel } from '@adonisjs/lucid/types/model';\nimport collect, { type Collection } from 'collect.js';\nimport { AllowedFilter } from '../allowed_filter.js';\nimport { InvalidFilterQuery } from '../exceptions/invalid_filter_query.js';\nimport { type ResolvedApiQueryConfig } from '../types.js';\n\ntype ModelQueryBuilderWithAllowedFilters = ModelQueryBuilder & {\n _allowedFilters: Collection<AllowedFilter<LucidModel>>;\n};\n\nexport const extendModelQueryBuilderWithFiltersQuery = function (\n builder: typeof ModelQueryBuilder,\n config: ResolvedApiQueryConfig,\n): void {\n const ensureAllFiltersExist = (self: ModelQueryBuilderWithAllowedFilters): void => {\n if (config.disableInvalidFilterQueryException) {\n return;\n }\n\n const filterNames = self.$apiQueryBuilderRequest.filters().keys();\n const allowedFilterNames = self._allowedFilters.map((allowedFilter) => {\n return allowedFilter.getName();\n });\n\n const diff = filterNames.diff(allowedFilterNames);\n\n if (diff.isNotEmpty()) {\n throw InvalidFilterQuery.filtersNotAllowed(diff.all(), allowedFilterNames.all());\n }\n };\n\n const isFilterRequested = (\n self: ModelQueryBuilderWithAllowedFilters,\n allowedFilter: AllowedFilter<LucidModel>,\n ): boolean => {\n return self.$apiQueryBuilderRequest.filters().has(allowedFilter.getName());\n };\n\n const addRequestedFiltersToQuery = (query: ModelQueryBuilderWithAllowedFilters): void => {\n query._allowedFilters.each((allowedFilter) => {\n if (isFilterRequested(query, allowedFilter)) {\n const value = query.$apiQueryBuilderRequest.filters().get(allowedFilter.getName());\n allowedFilter.filter(query, value);\n\n return;\n }\n\n if (allowedFilter.hasDefault()) {\n allowedFilter.filter(query, allowedFilter.getDefault());\n }\n });\n };\n\n builder.macro('allowedFilters', function (this: ModelQueryBuilderWithAllowedFilters, ...filters) {\n const arrayFilters = Array.isArray(filters.at(0))\n ? filters.at(0)\n : (filters as (AllowedFilter<LucidModel> | string)[]);\n this._allowedFilters = collect(arrayFilters).map((filter) => {\n if (filter instanceof AllowedFilter) {\n return filter;\n }\n\n return AllowedFilter.partial(filter);\n });\n\n ensureAllFiltersExist(this);\n addRequestedFiltersToQuery(this);\n\n return this;\n });\n};\n"],"mappings":";;;;;;;;AAGA,OAAO,aAAkC;AASlC,IAAM,0CAA0C,SACrD,SACA,QACM;AACN,QAAM,wBAAwB,CAAC,SAAoD;AACjF,QAAI,OAAO,oCAAoC;AAC7C;AAAA,IACF;AAEA,UAAM,cAAc,KAAK,wBAAwB,QAAQ,EAAE,KAAK;AAChE,UAAM,qBAAqB,KAAK,gBAAgB,IAAI,CAAC,kBAAkB;AACrE,aAAO,cAAc,QAAQ;AAAA,IAC/B,CAAC;AAED,UAAM,OAAO,YAAY,KAAK,kBAAkB;AAEhD,QAAI,KAAK,WAAW,GAAG;AACrB,YAAM,mBAAmB,kBAAkB,KAAK,IAAI,GAAG,mBAAmB,IAAI,CAAC;AAAA,IACjF;AAAA,EACF;AAEA,QAAM,oBAAoB,CACxB,MACA,kBACY;AACZ,WAAO,KAAK,wBAAwB,QAAQ,EAAE,IAAI,cAAc,QAAQ,CAAC;AAAA,EAC3E;AAEA,QAAM,6BAA6B,CAAC,UAAqD;AACvF,UAAM,gBAAgB,KAAK,CAAC,kBAAkB;AAC5C,UAAI,kBAAkB,OAAO,aAAa,GAAG;AAC3C,cAAM,QAAQ,MAAM,wBAAwB,QAAQ,EAAE,IAAI,cAAc,QAAQ,CAAC;AACjF,sBAAc,OAAO,OAAO,KAAK;AAEjC;AAAA,MACF;AAEA,UAAI,cAAc,WAAW,GAAG;AAC9B,sBAAc,OAAO,OAAO,cAAc,WAAW,CAAC;AAAA,MACxD;AAAA,IACF,CAAC;AAAA,EACH;AAEA,UAAQ,MAAM,kBAAkB,YAAwD,SAAS;AAC/F,UAAM,eAAe,MAAM,QAAQ,QAAQ,GAAG,CAAC,CAAC,IAC5C,QAAQ,GAAG,CAAC,IACX;AACL,SAAK,kBAAkB,QAAQ,YAAY,EAAE,IAAI,CAAC,WAAW;AAC3D,UAAI,kBAAkB,eAAe;AACnC,eAAO;AAAA,MACT;AAEA,aAAO,cAAc,QAAQ,MAAM;AAAA,IACrC,CAAC;AAED,0BAAsB,IAAI;AAC1B,+BAA2B,IAAI;AAE/B,WAAO;AAAA,EACT,CAAC;AACH;","names":[]}
@@ -1,70 +0,0 @@
1
- import {
2
- AllowedInclude,
3
- InvalidIncludeQuery
4
- } from "./chunk-IV3B5WO7.js";
5
- import "./chunk-XIRHVLVQ.js";
6
-
7
- // src/bindings/includes_query.ts
8
- import { Collection } from "collect.js";
9
- var extendModelQueryBuilderWithIncludesQuery = function(builder, config) {
10
- const ensureAllIncludesExist = (self) => {
11
- if (config.disableInvalidIncludesQueryException) {
12
- return;
13
- }
14
- const includes = self.$apiQueryBuilderRequest.includes();
15
- const allowedIncludeNames = self._allowedIncludes.map((allowedInclude) => {
16
- return allowedInclude.getName();
17
- });
18
- const diff = includes.diff(allowedIncludeNames);
19
- if (diff.isNotEmpty()) {
20
- throw InvalidIncludeQuery.includesNotAllowed(diff.all(), allowedIncludeNames.all());
21
- }
22
- };
23
- const findInclude = (self, include) => {
24
- return self._allowedIncludes.first((included) => included.isForInclude(include));
25
- };
26
- const filterNonExistingIncludes = (self) => {
27
- const includes = self.$apiQueryBuilderRequest.includes();
28
- if (!config.disableInvalidIncludesQueryException) {
29
- return includes;
30
- }
31
- return includes.filter((include) => !findInclude(self, include));
32
- };
33
- const addIncludesToQuery = (self, includes) => {
34
- includes.each((include) => {
35
- const allowedInclude = findInclude(self, include);
36
- allowedInclude?.include(self);
37
- });
38
- };
39
- builder.macro("allowedIncludes", function(...includes) {
40
- const arrayIncludes = Array.isArray(includes.at(0)) ? includes.at(0) : includes;
41
- this._allowedIncludes = new Collection(arrayIncludes).reject((include) => typeof include === "string" && include.length === 0).reduce((result, include) => {
42
- if (include instanceof Collection) {
43
- for (const allowedInclude of include) {
44
- result = result.push(allowedInclude);
45
- }
46
- return result;
47
- }
48
- if (include.endsWith(config.countSuffix)) {
49
- for (const allowedInclude of AllowedInclude.count(include)) {
50
- result = result.push(allowedInclude);
51
- }
52
- return result;
53
- }
54
- for (const allowedInclude of AllowedInclude.relationship(include)) {
55
- result = result.push(allowedInclude);
56
- }
57
- return result;
58
- }, new Collection()).unique((allowedInclude) => {
59
- return allowedInclude.getName();
60
- });
61
- ensureAllIncludesExist(this);
62
- const resultIncludes = filterNonExistingIncludes(this);
63
- addIncludesToQuery(this, resultIncludes);
64
- return this;
65
- });
66
- };
67
- export {
68
- extendModelQueryBuilderWithIncludesQuery
69
- };
70
- //# sourceMappingURL=includes_query-PVONWQMC.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/bindings/includes_query.ts"],"sourcesContent":["import { type ModelQueryBuilder } from '@adonisjs/lucid/orm';\nimport { type LucidModel } from '@adonisjs/lucid/types/model';\nimport { Collection } from 'collect.js';\nimport { AllowedInclude } from '../allowed_include.js';\nimport { InvalidIncludeQuery } from '../exceptions/invalid_include_query.js';\nimport { type ResolvedApiQueryConfig } from '../types.js';\n\ntype ModelQueryBuilderWithAllowedIncludes = ModelQueryBuilder & {\n _allowedIncludes: Collection<AllowedInclude<LucidModel>>;\n};\n\nexport const extendModelQueryBuilderWithIncludesQuery = function (\n builder: typeof ModelQueryBuilder,\n config: ResolvedApiQueryConfig,\n): void {\n const ensureAllIncludesExist = (self: ModelQueryBuilderWithAllowedIncludes): void => {\n if (config.disableInvalidIncludesQueryException) {\n return;\n }\n\n const includes = self.$apiQueryBuilderRequest.includes();\n const allowedIncludeNames = self._allowedIncludes.map((allowedInclude) => {\n return allowedInclude.getName();\n });\n\n const diff = includes.diff(allowedIncludeNames);\n\n if (diff.isNotEmpty()) {\n throw InvalidIncludeQuery.includesNotAllowed(diff.all(), allowedIncludeNames.all());\n }\n };\n\n const findInclude = (\n self: ModelQueryBuilderWithAllowedIncludes,\n include: string,\n ): AllowedInclude<LucidModel> | undefined => {\n return self._allowedIncludes.first((included) => included.isForInclude(include));\n };\n\n const filterNonExistingIncludes = (self: ModelQueryBuilderWithAllowedIncludes) => {\n const includes = self.$apiQueryBuilderRequest.includes();\n\n if (!config.disableInvalidIncludesQueryException) {\n return includes;\n }\n\n return includes.filter((include) => !findInclude(self, include));\n };\n\n const addIncludesToQuery = (self: ModelQueryBuilderWithAllowedIncludes, includes: Collection<string>) => {\n includes.each((include) => {\n const allowedInclude = findInclude(self, include);\n allowedInclude?.include(self);\n });\n };\n\n builder.macro('allowedIncludes', function (this: ModelQueryBuilderWithAllowedIncludes, ...includes) {\n const arrayIncludes = Array.isArray(includes.at(0))\n ? includes.at(0)\n : (includes as (AllowedInclude<LucidModel> | string)[]);\n\n this._allowedIncludes = (\n new Collection(arrayIncludes)\n .reject((include) => typeof include === 'string' && include.length === 0)\n .reduce<Collection<AllowedInclude<LucidModel>>>((result, include) => {\n if (include instanceof Collection) {\n for (const allowedInclude of include) {\n result = result!.push(allowedInclude);\n }\n\n return result!;\n }\n\n if (include.endsWith(config.countSuffix)) {\n for (const allowedInclude of AllowedInclude.count(include)) {\n result = result!.push(allowedInclude);\n }\n\n return result!;\n }\n\n for (const allowedInclude of AllowedInclude.relationship(include)) {\n result = result!.push(allowedInclude);\n }\n\n return result!;\n }, new Collection()) as Collection<AllowedInclude<LucidModel>>\n ).unique((allowedInclude: AllowedInclude<LucidModel>) => {\n return allowedInclude.getName();\n });\n\n ensureAllIncludesExist(this);\n\n const resultIncludes = filterNonExistingIncludes(this);\n addIncludesToQuery(this, resultIncludes);\n\n return this;\n });\n};\n"],"mappings":";;;;;;;AAEA,SAAS,kBAAkB;AASpB,IAAM,2CAA2C,SACtD,SACA,QACM;AACN,QAAM,yBAAyB,CAAC,SAAqD;AACnF,QA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AAO,WAAW,GAAG;AACxC,mBAAW,kBAAkB,eAAe,MAAM,OAAO,GAAG;AAC1D,mBAAS,OAAQ,KAAK,cAAc;AAAA,QACtC;AAEA,eAAO;AAAA,MACT;AAEA,iBAAW,kBAAkB,eAAe,aAAa,OAAO,GAAG;AACjE,iBAAS,OAAQ,KAAK,cAAc;AAAA,MACtC;AAEA,aAAO;AAAA,IACT,GAAG,IAAI,WAAW,CAAC,EACrB,OAAO,CAAC,mBAA+C;AACvD,aAAO,eAAe,QAAQ;AAAA,IAChC,CAAC;AAED,2BAAuB,IAAI;AAE3B,UAAM,iBAAiB,0BAA0B,IAAI;AACrD,uBAAmB,MAAM,cAAc;AAEvC,WAAO;AAAA,EACT,CAAC;AACH;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../stubs/main.ts","../configure.ts","../src/define_config.ts","../src/exceptions/allowed_fields_must_be_called_before_allowed_includes.ts","../src/exceptions/invalid_append_query.ts","../src/exceptions/invalid_filter_value.ts","../src/exceptions/unknown_included_fields_query.ts","../index.ts"],"sourcesContent":["import path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nexport const stubsRoot = path.dirname(fileURLToPath(import.meta.url));\n","import type Configure from '@adonisjs/core/commands/configure';\nimport { stubsRoot } from './stubs/main.js';\n\nexport const configure = async (command: Configure): Promise<void> => {\n const codemods = await command.createCodemods();\n\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@eienjs/adonisjs-api-query/api_query_provider');\n });\n\n await codemods.makeUsingStub(stubsRoot, 'config.stub', {});\n};\n","import { configProvider } from '@adonisjs/core';\nimport { type ConfigProvider } from '@adonisjs/core/types';\nimport { type ApiQueryConfig, type ResolvedApiQueryConfig } from './types.js';\n\nexport const defineConfig = function (config: ApiQueryConfig): ConfigProvider<ResolvedApiQueryConfig> {\n return configProvider.create(async (_) => {\n return {\n parameters: {\n include: config.parameters?.include ?? 'include',\n filter: config.parameters?.filter ?? 'filter',\n sort: config.parameters?.sort ?? 'sort',\n fields: config.parameters?.fields ?? 'fields',\n append: config.parameters?.append ?? 'append',\n },\n countSuffix: config.countSuffix ?? 'Count',\n existsSuffix: config.existsSuffix ?? 'Exists',\n disableInvalidFilterQueryException: config.disableInvalidFilterQueryException ?? false,\n disableInvalidSortQueryException: config.disableInvalidSortQueryException ?? false,\n disableInvalidIncludesQueryException: config.disableInvalidIncludesQueryException ?? false,\n convertRelationNamesToSnakeCasePlural: config.convertRelationNamesToSnakeCasePlural ?? false,\n convertRelationTableNameStrategy: config.convertRelationTableNameStrategy ?? false,\n convertFieldNamesToSnakeCase: config.convertFieldNamesToSnakeCase ?? false,\n };\n });\n};\n","import { Exception } from '@adonisjs/core/exceptions';\n\nexport class AllowedFieldsMustBeCalledBeforeAllowedIncludes extends Exception {\n public static readonly code: 'E_BAD_METHOD_CALL_EXCEPTION';\n\n public static readonly status: 500;\n\n public constructor() {\n super(\"The QueryBuilder's `allowedFields` method must be called before the `allowedIncludes` method\");\n }\n}\n","import { ResponseStatus } from '@adonisjs/core/http';\nimport { InvalidQuery } from './invalid_query.js';\n\nexport class InvalidAppendQuery extends InvalidQuery {\n public constructor(appendsNotAllowed: string[], allowedAppends: string[]) {\n const notAllowed = appendsNotAllowed.join(', ');\n const allowed = allowedAppends.join(', ');\n const message = `Requested append(s) \\`${notAllowed}\\` are not allowed. Allowed append(s) are \\`${allowed}\\``;\n\n super(message, { status: ResponseStatus.BadRequest });\n }\n\n public static appendsNotAllowed(appendsNotAllowed: string[], allowedAppends: string[]): InvalidAppendQuery {\n return new InvalidAppendQuery(appendsNotAllowed, allowedAppends);\n }\n}\n","import { Exception } from '@adonisjs/core/exceptions';\n\nexport class InvalidFilterValue extends Exception {\n public static make(value: unknown): InvalidFilterValue {\n return new InvalidFilterValue(`Filter value \\`${value}\\` is invalid`);\n }\n}\n","import { ResponseStatus } from '@adonisjs/core/http';\nimport { InvalidQuery } from './invalid_query.js';\n\nexport class UnknownIncludedFieldsQuery extends InvalidQuery {\n public readonly unknownFields: string[];\n\n public constructor(unknownFields: string[]) {\n const notAllowed = unknownFields.join(', ');\n const message = [\n `Requested field(s) \\`${notAllowed}\\` are not allowed (yet). `,\n \"If you want to allow these fields, please make sure to call the QueryBuilder's `allowedFields` method before the `allowedIncludes` method\",\n ].join('');\n\n super(message, { status: ResponseStatus.BadRequest });\n\n this.unknownFields = unknownFields;\n }\n}\n","export { configure } from './configure.js';\nexport { AllowedFilter } from './src/allowed_filter.js';\nexport { AllowedInclude } from './src/allowed_include.js';\nexport { AllowedSort } from './src/allowed_sort.js';\nexport { ApiQueryBuilderRequest } from './src/api_query_builder_request.js';\nexport { defineConfig } from './src/define_config.js';\nexport { FilterOperator } from './src/enums/filter_operator.js';\nexport { SortDirection } from './src/enums/sort_direction.js';\nexport { AllowedFieldsMustBeCalledBeforeAllowedIncludes } from './src/exceptions/allowed_fields_must_be_called_before_allowed_includes.js';\nexport { InvalidAppendQuery } from './src/exceptions/invalid_append_query.js';\nexport { InvalidDirection } from './src/exceptions/invalid_direction.js';\nexport { InvalidFilterQuery } from './src/exceptions/invalid_filter_query.js';\nexport { InvalidFilterValue } from './src/exceptions/invalid_filter_value.js';\nexport { InvalidIncludeQuery } from './src/exceptions/invalid_include_query.js';\nexport { InvalidQuery } from './src/exceptions/invalid_query.js';\nexport { InvalidSortQuery } from './src/exceptions/invalid_sort_query.js';\nexport { UnknownIncludedFieldsQuery } from './src/exceptions/unknown_included_fields_query.js';\nexport { stubsRoot } from './stubs/main.js';\nexport * from 'collect.js';\n// Filters\nexport { FiltersBeginWithStrict } from './src/filters/filters_begin_with_strict.js';\nexport { FiltersCallback } from './src/filters/filters_callback.js';\nexport { FiltersEndsWithStrict } from './src/filters/filters_ends_with_strict.js';\nexport { FiltersExact } from './src/filters/filters_exact.js';\nexport { FiltersOperator } from './src/filters/filters_operator.js';\nexport { FiltersPartial } from './src/filters/filters_partial.js';\nexport { FiltersTrashed } from './src/filters/filters_trashed.js';\n// Includes\nexport { IncludedCallback } from './src/includes/included_callback.js';\nexport { IncludedCount } from './src/includes/included_count.js';\nexport { IncludedRelationship } from './src/includes/included_relationship.js';\n// Sorts\nexport { SortsCallback } from './src/sorts/sorts_callback.js';\nexport { SortsField } from './src/sorts/sorts_field.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAEvB,IAAM,YAAY,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;;;ACA7D,IAAM,YAAY,OAAO,YAAsC;AACpE,QAAM,WAAW,MAAM,QAAQ,eAAe;AAE9C,QAAM,SAAS,aAAa,CAAC,WAAW;AACtC,WAAO,YAAY,+CAA+C;AAAA,EACpE,CAAC;AAED,QAAM,SAAS,cAAc,WAAW,eAAe,CAAC,CAAC;AAC3D;;;ACXA,SAAS,sBAAsB;AAIxB,IAAM,eAAe,SAAU,QAAgE;AACpG,SAAO,eAAe,OAAO,OAAO,MAAM;AACxC,WAAO;AAAA,MACL,YAAY;AAAA,QACV,SAAS,OAAO,YAAY,WAAW;AAAA,QACvC,QAAQ,OAAO,YAAY,UAAU;AAAA,QACrC,MAAM,OAAO,YAAY,QAAQ;AAAA,QACjC,QAAQ,OAAO,YAAY,UAAU;AAAA,QACrC,QAAQ,OAAO,YAAY,UAAU;AAAA,MACvC;AAAA,MACA,aAAa,OAAO,eAAe;AAAA,MACnC,cAAc,OAAO,gBAAgB;AAAA,MACrC,oCAAoC,OAAO,sCAAsC;AAAA,MACjF,kCAAkC,OAAO,oCAAoC;AAAA,MAC7E,sCAAsC,OAAO,wCAAwC;AAAA,MACrF,uCAAuC,OAAO,yCAAyC;AAAA,MACvF,kCAAkC,OAAO,oCAAoC;AAAA,MAC7E,8BAA8B,OAAO,gCAAgC;AAAA,IACvE;AAAA,EACF,CAAC;AACH;;;ACxBA,SAAS,iBAAiB;AAEnB,IAAM,iDAAN,cAA6D,UAAU;AAAA,EAC5E,OAAuB;AAAA,EAEvB,OAAuB;AAAA,EAE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