@eienjs/adonisjs-api-query 1.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE.md → LICENSE} +1 -1
- package/README.md +166 -2
- package/build/configure.d.ts +2 -2
- package/build/configure.js +10 -0
- package/build/index.d.ts +38 -31
- package/build/index.js +38 -154
- package/build/providers/api_query_provider.d.ts +48 -37
- package/build/providers/api_query_provider.js +26 -27
- package/build/src/allowed_filter.d.ts +44 -36
- package/build/src/allowed_filter.js +135 -0
- package/build/src/allowed_include.d.ts +15 -16
- package/build/src/allowed_include.js +47 -0
- package/build/src/allowed_sort.d.ts +17 -17
- package/build/src/allowed_sort.js +49 -0
- package/build/src/api_query_builder_request.d.ts +55 -30
- package/build/src/api_query_builder_request.js +200 -0
- package/build/src/base_filterable.d.ts +45 -0
- package/build/src/base_filterable.js +172 -0
- package/build/src/bindings/api_query_request.js +13 -0
- package/build/src/bindings/filterable_query.js +51 -0
- package/build/src/bindings/filters_query.js +38 -0
- package/build/src/bindings/includes_query.js +50 -0
- package/build/src/bindings/sorts_query.js +42 -0
- package/build/src/bindings/validation_query.js +27 -0
- package/build/src/decorators/filterable.d.ts +20 -0
- package/build/src/decorators/filterable.js +24 -0
- package/build/src/define_config.d.ts +3 -3
- package/build/src/define_config.js +25 -0
- package/build/src/enums/filter_operator.d.ts +8 -9
- package/build/src/enums/filter_operator.js +11 -0
- package/build/src/enums/sort_direction.d.ts +3 -4
- package/build/src/enums/sort_direction.js +6 -0
- package/build/src/exceptions/allowed_fields_must_be_called_before_allowed_includes.d.ts +5 -5
- package/build/src/exceptions/allowed_fields_must_be_called_before_allowed_includes.js +10 -0
- package/build/src/exceptions/filterable_not_configured.d.ts +5 -0
- package/build/src/exceptions/filterable_not_configured.js +12 -0
- package/build/src/exceptions/invalid_append_query.d.ts +6 -4
- package/build/src/exceptions/invalid_append_query.js +17 -0
- package/build/src/exceptions/invalid_direction.d.ts +3 -3
- package/build/src/exceptions/invalid_direction.js +9 -0
- package/build/src/exceptions/invalid_field_query.d.ts +6 -4
- package/build/src/exceptions/invalid_field_query.js +17 -0
- package/build/src/exceptions/invalid_filter_query.d.ts +6 -6
- package/build/src/exceptions/invalid_filter_query.js +17 -0
- package/build/src/exceptions/invalid_filter_value.d.ts +3 -3
- package/build/src/exceptions/invalid_filter_value.js +8 -0
- package/build/src/exceptions/invalid_include_query.d.ts +6 -6
- package/build/src/exceptions/invalid_include_query.js +21 -0
- package/build/src/exceptions/invalid_query.d.ts +3 -3
- package/build/{chunk-XIRHVLVQ.js → src/exceptions/invalid_query.js} +3 -7
- package/build/src/exceptions/invalid_sort_query.d.ts +6 -6
- package/build/src/exceptions/invalid_sort_query.js +17 -0
- package/build/src/exceptions/unknown_included_fields_query.d.ts +4 -4
- package/build/src/exceptions/unknown_included_fields_query.js +12 -0
- package/build/src/exceptions/vine_not_installed.d.ts +5 -0
- package/build/src/exceptions/vine_not_installed.js +12 -0
- package/build/src/filters/filters_begin_with_strict.d.ts +6 -6
- package/build/src/filters/filters_begin_with_strict.js +8 -0
- package/build/src/filters/filters_callback.d.ts +6 -6
- package/build/src/filters/filters_callback.js +11 -0
- package/build/src/filters/filters_ends_with_strict.d.ts +6 -6
- package/build/src/filters/filters_ends_with_strict.js +8 -0
- package/build/src/filters/filters_exact.d.ts +11 -11
- package/build/src/filters/filters_exact.js +50 -0
- package/build/src/filters/filters_operator.d.ts +13 -13
- package/build/src/filters/filters_operator.js +52 -0
- package/build/src/filters/filters_partial.d.ts +9 -11
- package/build/src/filters/filters_partial.js +37 -0
- package/build/src/filters/filters_scope.d.ts +12 -0
- package/build/src/filters/filters_scope.js +98 -0
- package/build/src/filters/filters_trashed.d.ts +5 -5
- package/build/src/filters/filters_trashed.js +13 -0
- package/build/src/includes/included_callback.d.ts +7 -7
- package/build/src/includes/included_callback.js +11 -0
- package/build/src/includes/included_count.d.ts +4 -4
- package/build/src/includes/included_count.js +11 -0
- package/build/src/includes/included_relationship.d.ts +8 -8
- package/build/src/includes/included_relationship.js +37 -0
- package/build/src/sorts/sorts_callback.d.ts +6 -6
- package/build/src/sorts/sorts_callback.js +11 -0
- package/build/src/sorts/sorts_field.d.ts +4 -4
- package/build/src/sorts/sorts_field.js +7 -0
- package/build/src/utils/helpers.js +14 -0
- package/build/src/validation/schema_builder.d.ts +3 -0
- package/build/src/validation/schema_builder.js +38 -0
- package/build/src/validation/vine_resolver.js +13 -0
- package/build/stubs/main.d.ts +1 -1
- package/build/stubs/main.js +3 -0
- package/build/types.d.ts +116 -0
- package/build/types.js +1 -0
- package/package.json +101 -88
- package/build/api_query_request-QXOB4BN6.js +0 -18
- package/build/api_query_request-QXOB4BN6.js.map +0 -1
- package/build/chunk-3ITWUZL5.js +0 -108
- package/build/chunk-3ITWUZL5.js.map +0 -1
- package/build/chunk-54HNQTDY.js +0 -348
- package/build/chunk-54HNQTDY.js.map +0 -1
- package/build/chunk-IV3B5WO7.js +0 -160
- package/build/chunk-IV3B5WO7.js.map +0 -1
- package/build/chunk-MKQ3HMMA.js +0 -198
- package/build/chunk-MKQ3HMMA.js.map +0 -1
- package/build/chunk-XIRHVLVQ.js.map +0 -1
- package/build/filters_query-LCFH2F2X.js +0 -55
- package/build/filters_query-LCFH2F2X.js.map +0 -1
- package/build/includes_query-PVONWQMC.js +0 -70
- package/build/includes_query-PVONWQMC.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/metafile-esm.json +0 -1
- package/build/providers/api_query_provider.js.map +0 -1
- package/build/sorts_query-NJTC5UXX.js +0 -63
- package/build/sorts_query-NJTC5UXX.js.map +0 -1
- package/build/src/bindings/api_query_request.d.ts +0 -2
- package/build/src/bindings/filters_query.d.ts +0 -3
- package/build/src/bindings/includes_query.d.ts +0 -3
- package/build/src/bindings/sorts_query.d.ts +0 -3
- package/build/src/types.d.ts +0 -90
- package/build/src/types.js +0 -1
- package/build/src/types.js.map +0 -1
- package/build/src/utils/helpers.d.ts +0 -3
- /package/build/{config.stub → stubs/config.stub} +0 -0
package/build/chunk-MKQ3HMMA.js
DELETED
|
@@ -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;AACv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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,QAAI,OAAO,sCAAsC;AAC/C;AAAA,IACF;AAEA,UAAM,WAAW,KAAK,wBAAwB,SA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BAAS,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":[]}
|
package/build/index.js.map
DELETED
|
@@ -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,EAEhB,cAAc;AACnB,UAAM,8FAA8F;AAAA,EACtG;AACF;;;ACVA,SAAS,sBAAsB;AAGxB,IAAM,qBAAN,MAAM,4BAA2B,aAAa;AAAA,EAC5C,YAAY,mBAA6B,gBAA0B;AACxE,UAAM,aAAa,kBAAkB,KAAK,IAAI;AAC9C,UAAM,UAAU,eAAe,KAAK,IAAI;AACxC,UAAM,UAAU,yBAAyB,UAAU,+CAA+C,OAAO;AAEzG,UAAM,SAAS,EAAE,QAAQ,eAAe,WAAW,CAAC;AAAA,EACtD;AAAA,EAEA,OAAc,kBAAkB,mBAA6B,gBAA8C;AACzG,WAAO,IAAI,oBAAmB,mBAAmB,cAAc;AAAA,EACjE;AACF;;;ACfA,SAAS,aAAAA,kBAAiB;AAEnB,IAAM,qBAAN,MAAM,4BAA2BA,WAAU;AAAA,EAChD,OAAc,KAAK,OAAoC;AACrD,WAAO,IAAI,oBAAmB,kBAAkB,KAAK,eAAe;AAAA,EACtE;AACF;;;ACNA,SAAS,kBAAAC,uBAAsB;AAGxB,IAAM,6BAAN,cAAyC,aAAa;AAAA,EAC3C;AAAA,EAET,YAAY,eAAyB;AAC1C,UAAM,aAAa,cAAc,KAAK,IAAI;AAC1C,UAAM,UAAU;AAAA,MACd,wBAAwB,UAAU;AAAA,MAClC;AAAA,IACF,EAAE,KAAK,EAAE;AAET,UAAM,SAAS,EAAE,QAAQC,gBAAe,WAAW,CAAC;AAEpD,SAAK,gBAAgB;AAAA,EACvB;AACF;;;ACCA,cAAc;","names":["Exception","ResponseStatus","ResponseStatus"]}
|
package/build/metafile-esm.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"inputs":{"stubs/main.ts":{"bytes":144,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"url","kind":"import-statement","external":true}],"format":"esm"},"configure.ts":{"bytes":423,"imports":[{"path":"stubs/main.ts","kind":"import-statement","original":"./stubs/main.js"}],"format":"esm"},"src/utils/helpers.ts":{"bytes":931,"imports":[],"format":"esm"},"src/api_query_builder_request.ts":{"bytes":6640,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/core/services/app","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"src/utils/helpers.ts","kind":"import-statement","original":"./utils/helpers.js"}],"format":"esm"},"src/filters/filters_exact.ts":{"bytes":2571,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/querybuilder","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/relations","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"src/filters/filters_partial.ts":{"bytes":2356,"imports":[{"path":"@adonisjs/lucid/types/database","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/querybuilder","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true},{"path":"src/filters/filters_exact.ts","kind":"import-statement","original":"./filters_exact.js"}],"format":"esm"},"src/filters/filters_begin_with_strict.ts":{"bytes":570,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/querybuilder","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true},{"path":"src/filters/filters_partial.ts","kind":"import-statement","original":"./filters_partial.js"}],"format":"esm"},"src/filters/filters_callback.ts":{"bytes":527,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"src/filters/filters_ends_with_strict.ts":{"bytes":568,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/querybuilder","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true},{"path":"src/filters/filters_partial.ts","kind":"import-statement","original":"./filters_partial.js"}],"format":"esm"},"src/enums/filter_operator.ts":{"bytes":265,"imports":[],"format":"esm"},"src/filters/filters_operator.ts":{"bytes":2380,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/querybuilder","kind":"import-statement","external":true},{"path":"src/enums/filter_operator.ts","kind":"import-statement","original":"../enums/filter_operator.js"},{"path":"../types.js","kind":"import-statement","external":true},{"path":"src/utils/helpers.ts","kind":"import-statement","original":"../utils/helpers.js"},{"path":"src/filters/filters_exact.ts","kind":"import-statement","original":"./filters_exact.js"}],"format":"esm"},"src/filters/filters_trashed.ts":{"bytes":885,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/querybuilder","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"src/allowed_filter.ts":{"bytes":6731,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/querybuilder","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"src/api_query_builder_request.ts","kind":"import-statement","original":"./api_query_builder_request.js"},{"path":"./enums/filter_operator.js","kind":"import-statement","external":true},{"path":"src/filters/filters_begin_with_strict.ts","kind":"import-statement","original":"./filters/filters_begin_with_strict.js"},{"path":"src/filters/filters_callback.ts","kind":"import-statement","original":"./filters/filters_callback.js"},{"path":"src/filters/filters_ends_with_strict.ts","kind":"import-statement","original":"./filters/filters_ends_with_strict.js"},{"path":"src/filters/filters_exact.ts","kind":"import-statement","original":"./filters/filters_exact.js"},{"path":"src/filters/filters_operator.ts","kind":"import-statement","original":"./filters/filters_operator.js"},{"path":"src/filters/filters_partial.ts","kind":"import-statement","original":"./filters/filters_partial.js"},{"path":"src/filters/filters_trashed.ts","kind":"import-statement","original":"./filters/filters_trashed.js"},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"src/includes/included_callback.ts":{"bytes":809,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/relations","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"src/includes/included_count.ts":{"bytes":742,"imports":[{"path":"@adonisjs/core/services/app","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/relations","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"src/includes/included_relationship.ts":{"bytes":2731,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/relations","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"src/allowed_include.ts":{"bytes":3602,"imports":[{"path":"@adonisjs/core/services/app","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/relations","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"src/includes/included_callback.ts","kind":"import-statement","original":"./includes/included_callback.js"},{"path":"src/includes/included_count.ts","kind":"import-statement","original":"./includes/included_count.js"},{"path":"src/includes/included_relationship.ts","kind":"import-statement","original":"./includes/included_relationship.js"},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"src/enums/sort_direction.ts":{"bytes":166,"imports":[],"format":"esm"},"src/exceptions/invalid_direction.ts":{"bytes":387,"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"src/enums/sort_direction.ts","kind":"import-statement","original":"../enums/sort_direction.js"}],"format":"esm"},"src/sorts/sorts_callback.ts":{"bytes":551,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"src/sorts/sorts_field.ts":{"bytes":385,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"src/allowed_sort.ts":{"bytes":2724,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"src/enums/sort_direction.ts","kind":"import-statement","original":"./enums/sort_direction.js"},{"path":"src/exceptions/invalid_direction.ts","kind":"import-statement","original":"./exceptions/invalid_direction.js"},{"path":"src/sorts/sorts_callback.ts","kind":"import-statement","original":"./sorts/sorts_callback.js"},{"path":"src/sorts/sorts_field.ts","kind":"import-statement","original":"./sorts/sorts_field.js"},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"src/define_config.ts":{"bytes":1326,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"src/exceptions/allowed_fields_must_be_called_before_allowed_includes.ts":{"bytes":376,"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true}],"format":"esm"},"src/exceptions/invalid_query.ts":{"bytes":174,"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true}],"format":"esm"},"src/exceptions/invalid_append_query.ts":{"bytes":706,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"src/exceptions/invalid_query.ts","kind":"import-statement","original":"./invalid_query.js"}],"format":"esm"},"src/exceptions/invalid_filter_query.ts":{"bytes":739,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"src/exceptions/invalid_query.ts","kind":"import-statement","original":"./invalid_query.js"}],"format":"esm"},"src/exceptions/invalid_filter_value.ts":{"bytes":248,"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true}],"format":"esm"},"src/exceptions/invalid_include_query.ts":{"bytes":900,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"src/exceptions/invalid_query.ts","kind":"import-statement","original":"./invalid_query.js"}],"format":"esm"},"src/exceptions/invalid_sort_query.ts":{"bytes":710,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"src/exceptions/invalid_query.ts","kind":"import-statement","original":"./invalid_query.js"}],"format":"esm"},"src/exceptions/unknown_included_fields_query.ts":{"bytes":672,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"src/exceptions/invalid_query.ts","kind":"import-statement","original":"./invalid_query.js"}],"format":"esm"},"index.ts":{"bytes":2188,"imports":[{"path":"configure.ts","kind":"import-statement","original":"./configure.js"},{"path":"src/allowed_filter.ts","kind":"import-statement","original":"./src/allowed_filter.js"},{"path":"src/allowed_include.ts","kind":"import-statement","original":"./src/allowed_include.js"},{"path":"src/allowed_sort.ts","kind":"import-statement","original":"./src/allowed_sort.js"},{"path":"src/api_query_builder_request.ts","kind":"import-statement","original":"./src/api_query_builder_request.js"},{"path":"src/define_config.ts","kind":"import-statement","original":"./src/define_config.js"},{"path":"src/enums/filter_operator.ts","kind":"import-statement","original":"./src/enums/filter_operator.js"},{"path":"src/enums/sort_direction.ts","kind":"import-statement","original":"./src/enums/sort_direction.js"},{"path":"src/exceptions/allowed_fields_must_be_called_before_allowed_includes.ts","kind":"import-statement","original":"./src/exceptions/allowed_fields_must_be_called_before_allowed_includes.js"},{"path":"src/exceptions/invalid_append_query.ts","kind":"import-statement","original":"./src/exceptions/invalid_append_query.js"},{"path":"src/exceptions/invalid_direction.ts","kind":"import-statement","original":"./src/exceptions/invalid_direction.js"},{"path":"src/exceptions/invalid_filter_query.ts","kind":"import-statement","original":"./src/exceptions/invalid_filter_query.js"},{"path":"src/exceptions/invalid_filter_value.ts","kind":"import-statement","original":"./src/exceptions/invalid_filter_value.js"},{"path":"src/exceptions/invalid_include_query.ts","kind":"import-statement","original":"./src/exceptions/invalid_include_query.js"},{"path":"src/exceptions/invalid_query.ts","kind":"import-statement","original":"./src/exceptions/invalid_query.js"},{"path":"src/exceptions/invalid_sort_query.ts","kind":"import-statement","original":"./src/exceptions/invalid_sort_query.js"},{"path":"src/exceptions/unknown_included_fields_query.ts","kind":"import-statement","original":"./src/exceptions/unknown_included_fields_query.js"},{"path":"stubs/main.ts","kind":"import-statement","original":"./stubs/main.js"},{"path":"collect.js","kind":"import-statement","external":true},{"path":"src/filters/filters_begin_with_strict.ts","kind":"import-statement","original":"./src/filters/filters_begin_with_strict.js"},{"path":"src/filters/filters_callback.ts","kind":"import-statement","original":"./src/filters/filters_callback.js"},{"path":"src/filters/filters_ends_with_strict.ts","kind":"import-statement","original":"./src/filters/filters_ends_with_strict.js"},{"path":"src/filters/filters_exact.ts","kind":"import-statement","original":"./src/filters/filters_exact.js"},{"path":"src/filters/filters_operator.ts","kind":"import-statement","original":"./src/filters/filters_operator.js"},{"path":"src/filters/filters_partial.ts","kind":"import-statement","original":"./src/filters/filters_partial.js"},{"path":"src/filters/filters_trashed.ts","kind":"import-statement","original":"./src/filters/filters_trashed.js"},{"path":"src/includes/included_callback.ts","kind":"import-statement","original":"./src/includes/included_callback.js"},{"path":"src/includes/included_count.ts","kind":"import-statement","original":"./src/includes/included_count.js"},{"path":"src/includes/included_relationship.ts","kind":"import-statement","original":"./src/includes/included_relationship.js"},{"path":"src/sorts/sorts_callback.ts","kind":"import-statement","original":"./src/sorts/sorts_callback.js"},{"path":"src/sorts/sorts_field.ts","kind":"import-statement","original":"./src/sorts/sorts_field.js"}],"format":"esm"},"src/bindings/api_query_request.ts":{"bytes":770,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/orm","kind":"import-statement","external":true},{"path":"src/api_query_builder_request.ts","kind":"import-statement","original":"../api_query_builder_request.js"}],"format":"esm"},"src/bindings/sorts_query.ts":{"bytes":2829,"imports":[{"path":"@adonisjs/lucid/orm","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"src/allowed_sort.ts","kind":"import-statement","original":"../allowed_sort.js"},{"path":"src/exceptions/invalid_sort_query.ts","kind":"import-statement","original":"../exceptions/invalid_sort_query.js"},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"src/bindings/filters_query.ts":{"bytes":2528,"imports":[{"path":"@adonisjs/lucid/orm","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"src/allowed_filter.ts","kind":"import-statement","original":"../allowed_filter.js"},{"path":"src/exceptions/invalid_filter_query.ts","kind":"import-statement","original":"../exceptions/invalid_filter_query.js"},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"src/bindings/includes_query.ts":{"bytes":3412,"imports":[{"path":"@adonisjs/lucid/orm","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"src/allowed_include.ts","kind":"import-statement","original":"../allowed_include.js"},{"path":"src/exceptions/invalid_include_query.ts","kind":"import-statement","original":"../exceptions/invalid_include_query.js"},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"providers/api_query_provider.ts":{"bytes":4117,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/orm","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/relations","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"../src/allowed_filter.js","kind":"import-statement","external":true},{"path":"../src/allowed_include.js","kind":"import-statement","external":true},{"path":"../src/allowed_sort.js","kind":"import-statement","external":true},{"path":"../src/api_query_builder_request.js","kind":"import-statement","external":true},{"path":"../src/types.js","kind":"import-statement","external":true},{"path":"src/bindings/api_query_request.ts","kind":"dynamic-import","original":"../src/bindings/api_query_request.js"},{"path":"src/bindings/sorts_query.ts","kind":"dynamic-import","original":"../src/bindings/sorts_query.js"},{"path":"src/bindings/filters_query.ts","kind":"dynamic-import","original":"../src/bindings/filters_query.js"},{"path":"src/bindings/includes_query.ts","kind":"dynamic-import","original":"../src/bindings/includes_query.js"}],"format":"esm"},"src/types.ts":{"bytes":4261,"imports":[{"path":"@adonisjs/lucid/types/model","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/types/querybuilder","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"build/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":8395},"build/index.js":{"imports":[{"path":"build/chunk-3ITWUZL5.js","kind":"import-statement"},{"path":"build/chunk-54HNQTDY.js","kind":"import-statement"},{"path":"build/chunk-MKQ3HMMA.js","kind":"import-statement"},{"path":"build/chunk-IV3B5WO7.js","kind":"import-statement"},{"path":"build/chunk-XIRHVLVQ.js","kind":"import-statement"},{"path":"path","kind":"import-statement","external":true},{"path":"url","kind":"import-statement","external":true},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true}],"exports":["AllowedFieldsMustBeCalledBeforeAllowedIncludes","AllowedFilter","AllowedInclude","AllowedSort","ApiQueryBuilderRequest","FilterOperator","FiltersBeginWithStrict","FiltersCallback","FiltersEndsWithStrict","FiltersExact","FiltersOperator","FiltersPartial","FiltersTrashed","IncludedCallback","IncludedCount","IncludedRelationship","InvalidAppendQuery","InvalidDirection","InvalidFilterQuery","InvalidFilterValue","InvalidIncludeQuery","InvalidQuery","InvalidSortQuery","SortDirection","SortsCallback","SortsField","UnknownIncludedFieldsQuery","configure","defineConfig","stubsRoot"],"entryPoint":"index.ts","inputs":{"stubs/main.ts":{"bytesInOutput":124},"configure.ts":{"bytesInOutput":276},"index.ts":{"bytesInOutput":28},"src/define_config.ts":{"bytesInOutput":1118},"src/exceptions/allowed_fields_must_be_called_before_allowed_includes.ts":{"bytesInOutput":298},"src/exceptions/invalid_append_query.ts":{"bytesInOutput":599},"src/exceptions/invalid_filter_value.ts":{"bytesInOutput":247},"src/exceptions/unknown_included_fields_query.ts":{"bytesInOutput":593}},"bytes":4827},"build/providers/api_query_provider.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":4933},"build/providers/api_query_provider.js":{"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/lucid/orm","kind":"import-statement","external":true},{"path":"build/api_query_request-QXOB4BN6.js","kind":"dynamic-import"},{"path":"build/sorts_query-NJTC5UXX.js","kind":"dynamic-import"},{"path":"build/filters_query-LCFH2F2X.js","kind":"dynamic-import"},{"path":"build/includes_query-PVONWQMC.js","kind":"dynamic-import"}],"exports":["default"],"entryPoint":"providers/api_query_provider.ts","inputs":{"providers/api_query_provider.ts":{"bytesInOutput":1261}},"bytes":1338},"build/src/types.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/src/types.js":{"imports":[],"exports":[],"entryPoint":"src/types.ts","inputs":{"src/types.ts":{"bytesInOutput":0}},"bytes":0},"build/api_query_request-QXOB4BN6.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":1131},"build/api_query_request-QXOB4BN6.js":{"imports":[{"path":"build/chunk-MKQ3HMMA.js","kind":"import-statement"}],"exports":["extendModelQueryBuilderWithRequest"],"entryPoint":"src/bindings/api_query_request.ts","inputs":{"src/bindings/api_query_request.ts":{"bytesInOutput":348}},"bytes":499},"build/sorts_query-NJTC5UXX.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":4447},"build/sorts_query-NJTC5UXX.js":{"imports":[{"path":"build/chunk-3ITWUZL5.js","kind":"import-statement"},{"path":"build/chunk-XIRHVLVQ.js","kind":"import-statement"},{"path":"collect.js","kind":"import-statement","external":true}],"exports":["extendModelQueryBuilderWithSortsQuery"],"entryPoint":"src/bindings/sorts_query.ts","inputs":{"src/bindings/sorts_query.ts":{"bytesInOutput":1877}},"bytes":2064},"build/chunk-3ITWUZL5.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":7217},"build/chunk-3ITWUZL5.js":{"imports":[{"path":"build/chunk-XIRHVLVQ.js","kind":"import-statement"},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/http","kind":"import-statement","external":true}],"exports":["AllowedSort","InvalidDirection","InvalidSortQuery","SortDirection","SortsCallback","SortsField"],"inputs":{"src/enums/sort_direction.ts":{"bytesInOutput":66},"src/exceptions/invalid_direction.ts":{"bytesInOutput":311},"src/sorts/sorts_callback.ts":{"bytesInOutput":187},"src/sorts/sorts_field.ts":{"bytesInOutput":135},"src/allowed_sort.ts":{"bytesInOutput":1415},"src/exceptions/invalid_sort_query.ts":{"bytesInOutput":634}},"bytes":3115},"build/filters_query-LCFH2F2X.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":3812},"build/filters_query-LCFH2F2X.js":{"imports":[{"path":"build/chunk-54HNQTDY.js","kind":"import-statement"},{"path":"build/chunk-MKQ3HMMA.js","kind":"import-statement"},{"path":"build/chunk-XIRHVLVQ.js","kind":"import-statement"},{"path":"collect.js","kind":"import-statement","external":true}],"exports":["extendModelQueryBuilderWithFiltersQuery"],"entryPoint":"src/bindings/filters_query.ts","inputs":{"src/bindings/filters_query.ts":{"bytesInOutput":1613}},"bytes":1838},"build/chunk-54HNQTDY.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":25748},"build/chunk-54HNQTDY.js":{"imports":[{"path":"build/chunk-MKQ3HMMA.js","kind":"import-statement"},{"path":"build/chunk-XIRHVLVQ.js","kind":"import-statement"},{"path":"collect.js","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"@adonisjs/core/http","kind":"import-statement","external":true}],"exports":["AllowedFilter","FilterOperator","FiltersBeginWithStrict","FiltersCallback","FiltersEndsWithStrict","FiltersExact","FiltersOperator","FiltersPartial","FiltersTrashed","InvalidFilterQuery"],"inputs":{"src/filters/filters_exact.ts":{"bytesInOutput":1677},"src/filters/filters_partial.ts":{"bytesInOutput":1536},"src/filters/filters_begin_with_strict.ts":{"bytesInOutput":231},"src/filters/filters_callback.ts":{"bytesInOutput":175},"src/filters/filters_ends_with_strict.ts":{"bytesInOutput":228},"src/enums/filter_operator.ts":{"bytesInOutput":162},"src/filters/filters_operator.ts":{"bytesInOutput":1750},"src/filters/filters_trashed.ts":{"bytesInOutput":371},"src/allowed_filter.ts":{"bytesInOutput":3816},"src/exceptions/invalid_filter_query.ts":{"bytesInOutput":671}},"bytes":11328},"build/chunk-MKQ3HMMA.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":12289},"build/chunk-MKQ3HMMA.js":{"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/core/services/app","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true}],"exports":["ApiQueryBuilderRequest","substrReplace"],"inputs":{"src/api_query_builder_request.ts":{"bytesInOutput":5775},"src/utils/helpers.ts":{"bytesInOutput":804}},"bytes":6732},"build/includes_query-PVONWQMC.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":5167},"build/includes_query-PVONWQMC.js":{"imports":[{"path":"build/chunk-IV3B5WO7.js","kind":"import-statement"},{"path":"build/chunk-XIRHVLVQ.js","kind":"import-statement"},{"path":"collect.js","kind":"import-statement","external":true}],"exports":["extendModelQueryBuilderWithIncludesQuery"],"entryPoint":"src/bindings/includes_query.ts","inputs":{"src/bindings/includes_query.ts":{"bytesInOutput":2315}},"bytes":2514},"build/chunk-IV3B5WO7.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":12701},"build/chunk-IV3B5WO7.js":{"imports":[{"path":"build/chunk-XIRHVLVQ.js","kind":"import-statement"},{"path":"@adonisjs/core/services/app","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"@adonisjs/core/services/app","kind":"import-statement","external":true},{"path":"collect.js","kind":"import-statement","external":true},{"path":"@adonisjs/core/http","kind":"import-statement","external":true}],"exports":["AllowedInclude","IncludedCallback","IncludedCount","IncludedRelationship","InvalidIncludeQuery"],"inputs":{"src/includes/included_callback.ts":{"bytesInOutput":173},"src/includes/included_count.ts":{"bytesInOutput":297},"src/includes/included_relationship.ts":{"bytesInOutput":1845},"src/allowed_include.ts":{"bytesInOutput":1841},"src/exceptions/invalid_include_query.ts":{"bytesInOutput":835}},"bytes":5345},"build/chunk-XIRHVLVQ.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":383},"build/chunk-XIRHVLVQ.js":{"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true}],"exports":["InvalidQuery"],"inputs":{"src/exceptions/invalid_query.ts":{"bytesInOutput":148}},"bytes":211}}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../providers/api_query_provider.ts"],"sourcesContent":["import { configProvider } from '@adonisjs/core';\nimport { RuntimeException } from '@adonisjs/core/exceptions';\nimport { type Request } from '@adonisjs/core/http';\nimport { type ApplicationService } from '@adonisjs/core/types';\nimport { ModelQueryBuilder } from '@adonisjs/lucid/orm';\nimport { type LucidModel } from '@adonisjs/lucid/types/model';\nimport { type ExtractModelRelations } from '@adonisjs/lucid/types/relations';\nimport { type Collection } from 'collect.js';\nimport { type AllowedFilter } from '../src/allowed_filter.js';\nimport { type AllowedInclude } from '../src/allowed_include.js';\nimport { type AllowedSort } from '../src/allowed_sort.js';\nimport { type ApiQueryBuilderRequest } from '../src/api_query_builder_request.js';\nimport {\n type ApiQueryConfig,\n type ExtractKeys,\n type HintedString,\n type ResolvedApiQueryConfig,\n type SortUnionKeyParams,\n} from '../src/types.js';\n\nexport default class ApiQueryProvider {\n public constructor(protected app: ApplicationService) {}\n\n public async boot(): Promise<void> {\n const { extendModelQueryBuilderWithRequest } = await import('../src/bindings/api_query_request.js');\n const { extendModelQueryBuilderWithSortsQuery } = await import('../src/bindings/sorts_query.js');\n const { extendModelQueryBuilderWithFiltersQuery } = await import('../src/bindings/filters_query.js');\n const { extendModelQueryBuilderWithIncludesQuery } = await import('../src/bindings/includes_query.js');\n const apiQueryConfigProvider = this.app.config.get<ApiQueryConfig>('apiquery');\n const config = await configProvider.resolve<ResolvedApiQueryConfig>(this.app, apiQueryConfigProvider);\n\n if (!config) {\n throw new RuntimeException(\n 'Invalid \"config/apiquery.ts\" file. Make sure you are using the \"defineConfig\" method',\n );\n }\n\n extendModelQueryBuilderWithRequest(ModelQueryBuilder);\n extendModelQueryBuilderWithSortsQuery(ModelQueryBuilder, config);\n extendModelQueryBuilderWithFiltersQuery(ModelQueryBuilder, config);\n extendModelQueryBuilderWithIncludesQuery(ModelQueryBuilder, config);\n }\n}\n\ndeclare module '@adonisjs/lucid/orm' {\n interface ModelQueryBuilder {\n withRequest(request: Request): this;\n $apiQueryBuilderRequest: ApiQueryBuilderRequest;\n\n allowedSorts(...sorts: (AllowedSort<LucidModel> | string)[]): this;\n allowedSorts(sorts: (AllowedSort<LucidModel> | string)[]): this;\n defaultSort(...sorts: (AllowedSort<LucidModel> | string)[]): this;\n defaultSort(sorts: (AllowedSort<LucidModel> | string)[]): this;\n\n allowedFilters(...filters: (AllowedFilter<LucidModel> | string)[]): this;\n allowedFilters(filters: (AllowedFilter<LucidModel> | string)[]): this;\n\n allowedIncludes(...includes: (Collection<AllowedInclude<LucidModel>> | string)[]): this;\n allowedIncludes(includes: (Collection<AllowedInclude<LucidModel>> | string)[]): this;\n }\n}\n\ndeclare module '@adonisjs/lucid/types/model' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface ModelQueryBuilderContract<Model extends LucidModel, Result = InstanceType<Model>> {\n withRequest(request: Request): this;\n\n allowedSorts(...sorts: (AllowedSort<Model> | HintedString<SortUnionKeyParams<Model>>)[]): this;\n allowedSorts(sorts: (AllowedSort<Model> | HintedString<SortUnionKeyParams<Model>>)[]): this;\n defaultSort(...sorts: (AllowedSort<Model> | HintedString<SortUnionKeyParams<Model>>)[]): this;\n defaultSort(sorts: (AllowedSort<Model> | HintedString<SortUnionKeyParams<Model>>)[]): this;\n\n allowedFilters(\n ...filters: (AllowedFilter<Model> | HintedString<ExtractKeys<ModelAttributes<InstanceType<Model>>>>)[]\n ): this;\n allowedFilters(\n filters: (AllowedFilter<Model> | HintedString<ExtractKeys<ModelAttributes<InstanceType<Model>>>>)[],\n ): this;\n\n allowedIncludes(\n ...includes: (Collection<AllowedInclude<Model>> | HintedString<ExtractModelRelations<InstanceType<Model>>>)[]\n ): this;\n allowedIncludes(\n includes: (Collection<AllowedInclude<Model>> | HintedString<ExtractModelRelations<InstanceType<Model>>>)[],\n ): this;\n }\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAGjC,SAAS,yBAAyB;AAgBlC,IAAqB,mBAArB,MAAsC;AAAA,EAC7B,YAAsB,KAAyB;AAAzB;AAAA,EAA0B;AAAA,EAEvD,MAAa,OAAsB;AACjC,UAAM,EAAE,mCAAmC,IAAI,MAAM,OAAO,kCAAsC;AAClG,UAAM,EAAE,sCAAsC,IAAI,MAAM,OAAO,4BAAgC;AAC/F,UAAM,EAAE,wCAAwC,IAAI,MAAM,OAAO,8BAAkC;AACnG,UAAM,EAAE,yCAAyC,IAAI,MAAM,OAAO,+BAAmC;AACrG,UAAM,yBAAyB,KAAK,IAAI,OAAO,IAAoB,UAAU;AAC7E,UAAM,SAAS,MAAM,eAAe,QAAgC,KAAK,KAAK,sBAAsB;AAEpG,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,uCAAmC,iBAAiB;AACpD,0CAAsC,mBAAmB,MAAM;AAC/D,4CAAwC,mBAAmB,MAAM;AACjE,6CAAyC,mBAAmB,MAAM;AAAA,EACpE;AACF;","names":[]}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AllowedSort,
|
|
3
|
-
InvalidSortQuery
|
|
4
|
-
} from "./chunk-3ITWUZL5.js";
|
|
5
|
-
import "./chunk-XIRHVLVQ.js";
|
|
6
|
-
|
|
7
|
-
// src/bindings/sorts_query.ts
|
|
8
|
-
import { collect } from "collect.js";
|
|
9
|
-
var extendModelQueryBuilderWithSortsQuery = function(builder, config) {
|
|
10
|
-
const ensureAllSortsExist = (self) => {
|
|
11
|
-
if (config.disableInvalidSortQueryException) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const requestedSortNames = self.$apiQueryBuilderRequest.sorts().map((sort) => sort.replace(/^-+/, ""));
|
|
15
|
-
const allowedSortNames = self._allowedSorts.map((sort) => sort.getName());
|
|
16
|
-
const unknownSort = requestedSortNames.diff(allowedSortNames);
|
|
17
|
-
if (unknownSort.isNotEmpty()) {
|
|
18
|
-
throw InvalidSortQuery.sortsNotAllowed(unknownSort.all(), allowedSortNames.all());
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const findSort = (self, property) => {
|
|
22
|
-
return self._allowedSorts.first((sort) => sort.isSort(property));
|
|
23
|
-
};
|
|
24
|
-
const addRequestedSortsToQuery = (self) => {
|
|
25
|
-
self.$apiQueryBuilderRequest.sorts().each((property) => {
|
|
26
|
-
const descending = property.startsWith("-");
|
|
27
|
-
const key = property.replace(/^-+/, "");
|
|
28
|
-
const sort = findSort(self, key);
|
|
29
|
-
sort?.sort(self, descending);
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
builder.macro("allowedSorts", function(...sorts) {
|
|
33
|
-
const arraySorts = Array.isArray(sorts.at(0)) ? sorts.at(0) : sorts;
|
|
34
|
-
this._allowedSorts = collect(arraySorts).map((sort) => {
|
|
35
|
-
if (sort instanceof AllowedSort) {
|
|
36
|
-
return sort;
|
|
37
|
-
}
|
|
38
|
-
return AllowedSort.field(sort.replace(/^-+/, ""));
|
|
39
|
-
});
|
|
40
|
-
ensureAllSortsExist(this);
|
|
41
|
-
addRequestedSortsToQuery(this);
|
|
42
|
-
return this;
|
|
43
|
-
});
|
|
44
|
-
builder.macro("defaultSort", function(...sorts) {
|
|
45
|
-
if (this.$apiQueryBuilderRequest.sorts().isNotEmpty()) {
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
const arraySorts = Array.isArray(sorts.at(0)) ? sorts.at(0) : sorts;
|
|
49
|
-
collect(arraySorts).map((sort) => {
|
|
50
|
-
if (sort instanceof AllowedSort) {
|
|
51
|
-
return sort;
|
|
52
|
-
}
|
|
53
|
-
return AllowedSort.field(sort);
|
|
54
|
-
}).each((sort) => {
|
|
55
|
-
sort.sort(this);
|
|
56
|
-
});
|
|
57
|
-
return this;
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
export {
|
|
61
|
-
extendModelQueryBuilderWithSortsQuery
|
|
62
|
-
};
|
|
63
|
-
//# sourceMappingURL=sorts_query-NJTC5UXX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bindings/sorts_query.ts"],"sourcesContent":["import { type ModelQueryBuilder } from '@adonisjs/lucid/orm';\nimport { type LucidModel } from '@adonisjs/lucid/types/model';\nimport { collect, type Collection } from 'collect.js';\nimport { AllowedSort } from '../allowed_sort.js';\nimport { InvalidSortQuery } from '../exceptions/invalid_sort_query.js';\nimport { type ResolvedApiQueryConfig } from '../types.js';\n\ntype ModelQueryBuilderWithAllowedSorts = ModelQueryBuilder & { _allowedSorts: Collection<AllowedSort<LucidModel>> };\n\nexport const extendModelQueryBuilderWithSortsQuery = function (\n builder: typeof ModelQueryBuilder,\n config: ResolvedApiQueryConfig,\n): void {\n const ensureAllSortsExist = (self: ModelQueryBuilderWithAllowedSorts): void => {\n if (config.disableInvalidSortQueryException) {\n return;\n }\n\n const requestedSortNames = self.$apiQueryBuilderRequest.sorts().map((sort) => sort.replace(/^-+/, ''));\n const allowedSortNames = self._allowedSorts.map((sort) => sort.getName());\n const unknownSort = requestedSortNames.diff(allowedSortNames);\n\n if (unknownSort.isNotEmpty()) {\n throw InvalidSortQuery.sortsNotAllowed(unknownSort.all(), allowedSortNames.all());\n }\n };\n\n const findSort = (self: ModelQueryBuilderWithAllowedSorts, property: string): AllowedSort<LucidModel> | undefined => {\n return self._allowedSorts.first((sort) => sort.isSort(property));\n };\n\n const addRequestedSortsToQuery = (self: ModelQueryBuilderWithAllowedSorts): void => {\n self.$apiQueryBuilderRequest.sorts().each((property) => {\n const descending = property.startsWith('-');\n const key = property.replace(/^-+/, '');\n const sort = findSort(self, key);\n\n sort?.sort(self, descending);\n });\n };\n\n builder.macro('allowedSorts', function (this: ModelQueryBuilderWithAllowedSorts, ...sorts) {\n const arraySorts = Array.isArray(sorts.at(0)) ? sorts.at(0) : (sorts as (AllowedSort<LucidModel> | string)[]);\n\n this._allowedSorts = collect(arraySorts).map((sort) => {\n if (sort instanceof AllowedSort) {\n return sort;\n }\n\n return AllowedSort.field(sort.replace(/^-+/, ''));\n });\n\n ensureAllSortsExist(this);\n addRequestedSortsToQuery(this);\n\n return this;\n });\n\n builder.macro('defaultSort', function (this: ModelQueryBuilderWithAllowedSorts, ...sorts) {\n if (this.$apiQueryBuilderRequest.sorts().isNotEmpty()) {\n // We've got requested sorts. No need to parse defaults.\n\n return this;\n }\n\n const arraySorts = Array.isArray(sorts.at(0)) ? sorts.at(0) : (sorts as (AllowedSort<LucidModel> | string)[]);\n\n collect(arraySorts)\n .map((sort) => {\n if (sort instanceof AllowedSort) {\n return sort;\n }\n\n return AllowedSort.field(sort);\n })\n .each((sort) => {\n sort.sort(this);\n });\n\n return this;\n });\n};\n"],"mappings":";;;;;;;AAEA,SAAS,eAAgC;AAOlC,IAAM,wCAAwC,SACnD,SACA,QACM;AACN,QAAM,sBAAsB,CAAC,SAAkD;AAC7E,QAAI,OAAO,kCAAkC;AAC3C;AAAA,IACF;AAEA,UAAM,qBAAqB,KAAK,wBAAwB,MAAM,EAAE,IAAI,CAAC,SAAS,KAAK,QAAQ,OAAO,EAAE,CAAC;AACrG,UAAM,mBAAmB,KAAK,cAAc,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC;AACx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