@querykitjs/class-validator 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +68 -15
- package/README.md +68 -15
- package/dist/chunk-BZRPXHJC.cjs +81 -0
- package/dist/chunk-BZRPXHJC.cjs.map +1 -0
- package/dist/chunk-F3KZNLYZ.js +76 -0
- package/dist/chunk-F3KZNLYZ.js.map +1 -0
- package/dist/chunk-KT5JRG6S.js +194 -0
- package/dist/chunk-KT5JRG6S.js.map +1 -0
- package/dist/chunk-KXCJO556.cjs +207 -0
- package/dist/chunk-KXCJO556.cjs.map +1 -0
- package/dist/chunk-UICYH7OH.js +85 -0
- package/dist/chunk-UICYH7OH.js.map +1 -0
- package/dist/chunk-X7HMP7H7.cjs +89 -0
- package/dist/chunk-X7HMP7H7.cjs.map +1 -0
- package/dist/decorators.cjs +33 -0
- package/dist/decorators.cjs.map +1 -0
- package/dist/decorators.js +4 -0
- package/dist/decorators.js.map +1 -0
- package/dist/index.cjs +94 -408
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +82 -10
- package/dist/index.d.ts +82 -10
- package/dist/index.js +20 -394
- package/dist/index.js.map +1 -1
- package/dist/legacy-dto.cjs +26 -0
- package/dist/legacy-dto.cjs.map +1 -0
- package/dist/legacy-dto.js +5 -0
- package/dist/legacy-dto.js.map +1 -0
- package/dist/validate.cjs +20 -0
- package/dist/validate.cjs.map +1 -0
- package/dist/validate.js +3 -0
- package/dist/validate.js.map +1 -0
- package/package.json +20 -11
- package/skills/querykit-class-validator/SKILL.md +124 -0
package/dist/index.cjs
CHANGED
|
@@ -1,431 +1,117 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkBZRPXHJC_cjs = require('./chunk-BZRPXHJC.cjs');
|
|
4
|
+
var chunkX7HMP7H7_cjs = require('./chunk-X7HMP7H7.cjs');
|
|
5
|
+
var chunkKXCJO556_cjs = require('./chunk-KXCJO556.cjs');
|
|
5
6
|
var classTransformer = require('class-transformer');
|
|
7
|
+
var classValidator = require('class-validator');
|
|
8
|
+
var core = require('@querykitjs/core');
|
|
6
9
|
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
10
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
11
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
12
|
-
if (decorator = decorators[i])
|
|
13
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
14
|
-
if (kind && result) __defProp(target, key, result);
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// src/locales.ts
|
|
19
|
-
var QUERYKIT_MESSAGES_EN = {
|
|
20
|
-
"querykit.filter.invalid_node": "{path} must be a filter condition or an and/or/not group",
|
|
21
|
-
"querykit.filter.missing_key": "{path} is missing the required `key` string",
|
|
22
|
-
"querykit.filter.unknown_key": "{path}: `{key}` is not an allowed filter key",
|
|
23
|
-
"querykit.filter.invalid_operator": "{path}: `{operation}` is not a supported filter operator",
|
|
24
|
-
"querykit.filter.invalid_value": "{path} must be a string, number, boolean, null, or an array of those",
|
|
25
|
-
"querykit.filter.invalid_group": "{path} must be an array of filter nodes",
|
|
26
|
-
"querykit.filter.max_depth": "{path} exceeds the maximum filter depth of {max}",
|
|
27
|
-
"querykit.filter.value_requires_array": "{path}: `{operation}` requires an array value",
|
|
28
|
-
"querykit.filter.value_requires_tuple": "{path}: `{operation}` requires exactly two values",
|
|
29
|
-
"querykit.filter.value_forbidden": "{path}: `{operation}` must not carry a value",
|
|
30
|
-
"querykit.sort.not_array": "{path} must be an array of { key, direction } items",
|
|
31
|
-
"querykit.sort.invalid_item": "{path} must be an object with a `key` string",
|
|
32
|
-
"querykit.sort.missing_key": "{path} is missing the required `key` string",
|
|
33
|
-
"querykit.sort.unknown_key": "{path}: `{key}` is not an allowed sort key",
|
|
34
|
-
"querykit.sort.invalid_direction": "{path}: direction must be `asc` or `desc`"
|
|
35
|
-
};
|
|
36
|
-
var QUERYKIT_MESSAGES_UZ = {
|
|
37
|
-
"querykit.filter.invalid_node": "{path} filter sharti yoki and/or/not guruhi bo'lishi kerak",
|
|
38
|
-
"querykit.filter.missing_key": "{path} da majburiy `key` (string) yo'q",
|
|
39
|
-
"querykit.filter.unknown_key": "{path}: `{key}` ruxsat etilgan filter kaliti emas",
|
|
40
|
-
"querykit.filter.invalid_operator": "{path}: `{operation}` qo'llab-quvvatlanadigan filter operatori emas",
|
|
41
|
-
"querykit.filter.invalid_value": "{path} string, raqam, boolean, null yoki shularning massivi bo'lishi kerak",
|
|
42
|
-
"querykit.filter.invalid_group": "{path} filter tugunlari massivi bo'lishi kerak",
|
|
43
|
-
"querykit.filter.max_depth": "{path} ruxsat etilgan filter chuqurligidan ({max}) oshib ketdi",
|
|
44
|
-
"querykit.filter.value_requires_array": "{path}: `{operation}` massiv qiymat talab qiladi",
|
|
45
|
-
"querykit.filter.value_requires_tuple": "{path}: `{operation}` aynan ikkita qiymat talab qiladi",
|
|
46
|
-
"querykit.filter.value_forbidden": "{path}: `{operation}` qiymat qabul qilmaydi",
|
|
47
|
-
"querykit.sort.not_array": "{path} `{ key, direction }` elementlaridan iborat massiv bo'lishi kerak",
|
|
48
|
-
"querykit.sort.invalid_item": "{path} `key` (string) maydoniga ega obyekt bo'lishi kerak",
|
|
49
|
-
"querykit.sort.missing_key": "{path} da majburiy `key` (string) yo'q",
|
|
50
|
-
"querykit.sort.unknown_key": "{path}: `{key}` ruxsat etilgan sort kaliti emas",
|
|
51
|
-
"querykit.sort.invalid_direction": "{path}: direction `asc` yoki `desc` bo'lishi kerak"
|
|
52
|
-
};
|
|
53
|
-
var QUERYKIT_MESSAGES_RU = {
|
|
54
|
-
"querykit.filter.invalid_node": "{path} \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C \u0443\u0441\u043B\u043E\u0432\u0438\u0435\u043C \u0444\u0438\u043B\u044C\u0442\u0440\u0430 \u0438\u043B\u0438 \u0433\u0440\u0443\u043F\u043F\u043E\u0439 and/or/not",
|
|
55
|
-
"querykit.filter.missing_key": "\u0432 {path} \u043E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435 \u043F\u043E\u043B\u0435 `key` (\u0441\u0442\u0440\u043E\u043A\u0430)",
|
|
56
|
-
"querykit.filter.unknown_key": "{path}: `{key}` \u2014 \u043D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u044B\u0439 \u043A\u043B\u044E\u0447 \u0444\u0438\u043B\u044C\u0442\u0440\u0430",
|
|
57
|
-
"querykit.filter.invalid_operator": "{path}: `{operation}` \u2014 \u043D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440 \u0444\u0438\u043B\u044C\u0442\u0440\u0430",
|
|
58
|
-
"querykit.filter.invalid_value": "{path} \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u043E\u0439, \u0447\u0438\u0441\u043B\u043E\u043C, boolean, null \u0438\u043B\u0438 \u043C\u0430\u0441\u0441\u0438\u0432\u043E\u043C \u0438\u0437 \u043D\u0438\u0445",
|
|
59
|
-
"querykit.filter.invalid_group": "{path} \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C \u043C\u0430\u0441\u0441\u0438\u0432\u043E\u043C \u0443\u0437\u043B\u043E\u0432 \u0444\u0438\u043B\u044C\u0442\u0440\u0430",
|
|
60
|
-
"querykit.filter.max_depth": "{path} \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u0435\u0442 \u043C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u0443\u044E \u0433\u043B\u0443\u0431\u0438\u043D\u0443 \u0444\u0438\u043B\u044C\u0442\u0440\u0430 ({max})",
|
|
61
|
-
"querykit.filter.value_requires_array": "{path}: `{operation}` \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435-\u043C\u0430\u0441\u0441\u0438\u0432",
|
|
62
|
-
"querykit.filter.value_requires_tuple": "{path}: `{operation}` \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u043E\u0432\u043D\u043E \u0434\u0432\u0430 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u044F",
|
|
63
|
-
"querykit.filter.value_forbidden": "{path}: `{operation}` \u043D\u0435 \u0434\u043E\u043B\u0436\u0435\u043D \u0441\u043E\u0434\u0435\u0440\u0436\u0430\u0442\u044C \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435",
|
|
64
|
-
"querykit.sort.not_array": "{path} \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C \u043C\u0430\u0441\u0441\u0438\u0432\u043E\u043C \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432 `{ key, direction }`",
|
|
65
|
-
"querykit.sort.invalid_item": "{path} \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C \u043E\u0431\u044A\u0435\u043A\u0442\u043E\u043C \u0441 \u043F\u043E\u043B\u0435\u043C `key` (\u0441\u0442\u0440\u043E\u043A\u0430)",
|
|
66
|
-
"querykit.sort.missing_key": "\u0432 {path} \u043E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E\u0435 \u043F\u043E\u043B\u0435 `key` (\u0441\u0442\u0440\u043E\u043A\u0430)",
|
|
67
|
-
"querykit.sort.unknown_key": "{path}: `{key}` \u2014 \u043D\u0435\u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u044B\u0439 \u043A\u043B\u044E\u0447 \u0441\u043E\u0440\u0442\u0438\u0440\u043E\u0432\u043A\u0438",
|
|
68
|
-
"querykit.sort.invalid_direction": "{path}: direction \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C `asc` \u0438\u043B\u0438 `desc`"
|
|
69
|
-
};
|
|
70
|
-
var QUERYKIT_LOCALES = {
|
|
71
|
-
en: QUERYKIT_MESSAGES_EN,
|
|
72
|
-
uz: QUERYKIT_MESSAGES_UZ,
|
|
73
|
-
ru: QUERYKIT_MESSAGES_RU
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// src/messages.ts
|
|
77
|
-
var PLACEHOLDER = /\{(\w+)\}/g;
|
|
78
|
-
function formatMessage(key, args = {}, catalog = QUERYKIT_MESSAGES_EN) {
|
|
79
|
-
return catalog[key].replace(PLACEHOLDER, (match, name) => {
|
|
80
|
-
const value = args[name];
|
|
81
|
-
return value === void 0 ? match : String(value);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function localizeIssue(issue2, catalog) {
|
|
85
|
-
return formatMessage(issue2.key, issue2.args, catalog);
|
|
86
|
-
}
|
|
87
|
-
var DEFAULT_MAX_FILTER_DEPTH = 5;
|
|
88
|
-
var ALL_OPERATORS = new Set(core.FILTER_OPERATORS);
|
|
89
|
-
var ARRAY_OPERATORS = /* @__PURE__ */ new Set(["in", "notIn"]);
|
|
90
|
-
var TUPLE_OPERATORS = /* @__PURE__ */ new Set(["between", "notBetween"]);
|
|
91
|
-
var NULLARY_OPERATORS = /* @__PURE__ */ new Set(["isNull", "isNotNull"]);
|
|
92
|
-
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
93
|
-
var isScalar = (value) => value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
94
|
-
var isFilterValue = (value) => Array.isArray(value) ? value.every(isScalar) : isScalar(value);
|
|
95
|
-
var label = (value) => {
|
|
96
|
-
try {
|
|
97
|
-
return String(value);
|
|
98
|
-
} catch {
|
|
99
|
-
return Object.prototype.toString.call(value);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
var issue = (key, path, extra = {}) => {
|
|
103
|
-
const args = { path, ...extra };
|
|
104
|
-
return { path, key, message: formatMessage(key, args), args };
|
|
105
|
-
};
|
|
106
|
-
function checkCondition(node, path, ctx) {
|
|
107
|
-
if (!isRecord(node)) {
|
|
108
|
-
ctx.issues.push(issue("querykit.filter.invalid_node", path));
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const { key, operation, value } = node;
|
|
112
|
-
if (typeof key !== "string") {
|
|
113
|
-
ctx.issues.push(issue("querykit.filter.missing_key", path));
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (ctx.allowedKeys && !ctx.allowedKeys.has(key)) {
|
|
117
|
-
ctx.issues.push(issue("querykit.filter.unknown_key", path, { key }));
|
|
118
|
-
}
|
|
119
|
-
let operator;
|
|
120
|
-
if (operation !== void 0) {
|
|
121
|
-
if (typeof operation === "string" && ctx.operators.has(operation)) {
|
|
122
|
-
operator = operation;
|
|
123
|
-
} else {
|
|
124
|
-
ctx.issues.push(issue("querykit.filter.invalid_operator", `${path}.operation`, { operation: label(operation) }));
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (value !== void 0 && !isFilterValue(value)) {
|
|
128
|
-
ctx.issues.push(issue("querykit.filter.invalid_value", `${path}.value`));
|
|
129
|
-
}
|
|
130
|
-
if (ctx.strictValue && operator !== void 0) {
|
|
131
|
-
checkValueShape(operator, value, path, ctx);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function checkValueShape(operator, value, path, ctx) {
|
|
135
|
-
const valuePath = `${path}.value`;
|
|
136
|
-
if (ARRAY_OPERATORS.has(operator)) {
|
|
137
|
-
if (!Array.isArray(value)) {
|
|
138
|
-
ctx.issues.push(issue("querykit.filter.value_requires_array", valuePath, { operation: operator }));
|
|
139
|
-
}
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (TUPLE_OPERATORS.has(operator)) {
|
|
143
|
-
if (!Array.isArray(value) || value.length !== 2) {
|
|
144
|
-
ctx.issues.push(issue("querykit.filter.value_requires_tuple", valuePath, { operation: operator }));
|
|
145
|
-
}
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
if (NULLARY_OPERATORS.has(operator) && value !== void 0) {
|
|
149
|
-
ctx.issues.push(issue("querykit.filter.value_forbidden", valuePath, { operation: operator }));
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
function walkGroup(group, depth, path, ctx) {
|
|
153
|
-
if (!Array.isArray(group)) {
|
|
154
|
-
ctx.issues.push(issue("querykit.filter.invalid_group", path));
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
group.forEach((child, index) => walkNode(child, depth + 1, `${path}[${index}]`, ctx));
|
|
158
|
-
}
|
|
159
|
-
function walkNode(node, depth, path, ctx) {
|
|
160
|
-
if (depth > ctx.maxDepth) {
|
|
161
|
-
ctx.issues.push(issue("querykit.filter.max_depth", path, { max: ctx.maxDepth }));
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
if (!isRecord(node)) {
|
|
165
|
-
ctx.issues.push(issue("querykit.filter.invalid_node", path));
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if ("key" in node) {
|
|
169
|
-
checkCondition(node, path, ctx);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
if ("and" in node) {
|
|
173
|
-
walkGroup(node.and, depth, `${path}.and`, ctx);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if ("or" in node) {
|
|
177
|
-
walkGroup(node.or, depth, `${path}.or`, ctx);
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
if ("not" in node) {
|
|
181
|
-
walkNode(node.not, depth + 1, `${path}.not`, ctx);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
ctx.issues.push(issue("querykit.filter.missing_key", path));
|
|
185
|
-
}
|
|
186
|
-
function validateFilter(value, options = {}) {
|
|
187
|
-
if (value === void 0) return [];
|
|
188
|
-
const root = options.rootPath ?? "filter";
|
|
189
|
-
const ctx = {
|
|
190
|
-
issues: [],
|
|
191
|
-
allowedKeys: options.allowedKeys ? new Set(options.allowedKeys) : void 0,
|
|
192
|
-
operators: options.allowedOperators ? new Set(options.allowedOperators) : ALL_OPERATORS,
|
|
193
|
-
maxDepth: options.maxDepth ?? DEFAULT_MAX_FILTER_DEPTH,
|
|
194
|
-
strictValue: options.strictValue ?? false
|
|
195
|
-
};
|
|
196
|
-
if (Array.isArray(value)) {
|
|
197
|
-
value.forEach((item, index) => checkCondition(item, `${root}[${index}]`, ctx));
|
|
198
|
-
return ctx.issues;
|
|
199
|
-
}
|
|
200
|
-
walkNode(value, 1, root, ctx);
|
|
201
|
-
return ctx.issues;
|
|
202
|
-
}
|
|
203
|
-
function validateSort(value, options = {}) {
|
|
204
|
-
if (value === void 0) return [];
|
|
205
|
-
const root = options.rootPath ?? "sort";
|
|
206
|
-
if (!Array.isArray(value)) return [issue("querykit.sort.not_array", root)];
|
|
207
|
-
const allowedKeys = options.allowedKeys ? new Set(options.allowedKeys) : void 0;
|
|
208
|
-
const issues = [];
|
|
209
|
-
value.forEach((item, index) => {
|
|
210
|
-
const path = `${root}[${index}]`;
|
|
211
|
-
if (!isRecord(item)) {
|
|
212
|
-
issues.push(issue("querykit.sort.invalid_item", path));
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const { key, direction } = item;
|
|
216
|
-
if (typeof key !== "string") {
|
|
217
|
-
issues.push(issue("querykit.sort.missing_key", path));
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
if (allowedKeys && !allowedKeys.has(key)) {
|
|
221
|
-
issues.push(issue("querykit.sort.unknown_key", path, { key }));
|
|
222
|
-
}
|
|
223
|
-
if (direction !== void 0 && direction !== "asc" && direction !== "desc") {
|
|
224
|
-
issues.push(issue("querykit.sort.invalid_direction", `${path}.direction`));
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
return issues;
|
|
228
|
-
}
|
|
229
|
-
var optionsOf = (args, fallbackPath) => {
|
|
230
|
-
const given = args?.constraints?.[0] ?? {};
|
|
231
|
-
return { rootPath: args?.property ?? fallbackPath, ...given };
|
|
232
|
-
};
|
|
233
|
-
var firstMessage = (issues, options, args, fallback) => {
|
|
234
|
-
const first = issues[0];
|
|
235
|
-
if (!first) return `${args?.property ?? "value"} ${fallback}`;
|
|
236
|
-
return options.messageStyle === "key" ? first.key : first.message;
|
|
237
|
-
};
|
|
238
|
-
exports.IsQueryFilterConstraint = class IsQueryFilterConstraint {
|
|
239
|
-
validate(value, args) {
|
|
240
|
-
return validateFilter(value, optionsOf(args, "filter")).length === 0;
|
|
241
|
-
}
|
|
242
|
-
defaultMessage(args) {
|
|
243
|
-
const options = optionsOf(args, "filter");
|
|
244
|
-
return firstMessage(validateFilter(args?.value, options), options, args, "is not a valid querykit filter");
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
exports.IsQueryFilterConstraint = __decorateClass([
|
|
248
|
-
classValidator.ValidatorConstraint({ name: "isQueryFilter", async: false })
|
|
249
|
-
], exports.IsQueryFilterConstraint);
|
|
250
|
-
exports.IsQuerySortConstraint = class IsQuerySortConstraint {
|
|
251
|
-
validate(value, args) {
|
|
252
|
-
return validateSort(value, optionsOf(args, "sort")).length === 0;
|
|
253
|
-
}
|
|
254
|
-
defaultMessage(args) {
|
|
255
|
-
const options = optionsOf(args, "sort");
|
|
256
|
-
return firstMessage(validateSort(args?.value, options), options, args, "is not a valid querykit sort");
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
exports.IsQuerySortConstraint = __decorateClass([
|
|
260
|
-
classValidator.ValidatorConstraint({ name: "isQuerySort", async: false })
|
|
261
|
-
], exports.IsQuerySortConstraint);
|
|
262
|
-
function IsQueryFilter(options, validationOptions) {
|
|
263
|
-
return (target, propertyName) => {
|
|
264
|
-
classValidator.registerDecorator({
|
|
265
|
-
target: target.constructor,
|
|
266
|
-
propertyName,
|
|
267
|
-
options: validationOptions,
|
|
268
|
-
constraints: [options],
|
|
269
|
-
validator: exports.IsQueryFilterConstraint
|
|
270
|
-
});
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
function IsQuerySort(options, validationOptions) {
|
|
274
|
-
return (target, propertyName) => {
|
|
275
|
-
classValidator.registerDecorator({
|
|
276
|
-
target: target.constructor,
|
|
277
|
-
propertyName,
|
|
278
|
-
options: validationOptions,
|
|
279
|
-
constraints: [options],
|
|
280
|
-
validator: exports.IsQuerySortConstraint
|
|
281
|
-
});
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
var BaseParamsDto = class {
|
|
285
|
-
};
|
|
286
|
-
__decorateClass([
|
|
287
|
-
classValidator.IsOptional(),
|
|
288
|
-
IsQueryFilter()
|
|
289
|
-
], BaseParamsDto.prototype, "filter", 2);
|
|
290
|
-
__decorateClass([
|
|
291
|
-
classValidator.IsOptional(),
|
|
292
|
-
IsQuerySort()
|
|
293
|
-
], BaseParamsDto.prototype, "sort", 2);
|
|
294
|
-
var OffsetParamsDto = class extends BaseParamsDto {
|
|
295
|
-
};
|
|
296
|
-
__decorateClass([
|
|
297
|
-
classValidator.IsOptional(),
|
|
298
|
-
classTransformer.Type(() => Number),
|
|
299
|
-
classValidator.IsInt(),
|
|
300
|
-
classValidator.IsPositive()
|
|
301
|
-
], OffsetParamsDto.prototype, "page", 2);
|
|
302
|
-
__decorateClass([
|
|
303
|
-
classValidator.IsOptional(),
|
|
304
|
-
classTransformer.Type(() => Number),
|
|
305
|
-
classValidator.IsInt(),
|
|
306
|
-
classValidator.IsPositive(),
|
|
307
|
-
classValidator.Max(core.DEFAULT_MAX_PER_PAGE)
|
|
308
|
-
], OffsetParamsDto.prototype, "perPage", 2);
|
|
309
|
-
var InfiniteParamsDto = class extends BaseParamsDto {
|
|
310
|
-
};
|
|
311
|
-
__decorateClass([
|
|
312
|
-
classValidator.IsOptional(),
|
|
313
|
-
classTransformer.Type(() => Number),
|
|
314
|
-
classValidator.IsInt(),
|
|
315
|
-
classValidator.IsPositive(),
|
|
316
|
-
classValidator.Max(core.DEFAULT_MAX_LIMIT)
|
|
317
|
-
], InfiniteParamsDto.prototype, "limit", 2);
|
|
318
|
-
__decorateClass([
|
|
319
|
-
classValidator.IsOptional(),
|
|
320
|
-
classTransformer.Type(() => Number),
|
|
321
|
-
classValidator.IsInt(),
|
|
322
|
-
classValidator.Min(0)
|
|
323
|
-
], InfiniteParamsDto.prototype, "offset", 2);
|
|
324
|
-
var CursorParamsDto = class {
|
|
325
|
-
};
|
|
326
|
-
__decorateClass([
|
|
327
|
-
classValidator.IsOptional(),
|
|
328
|
-
IsQueryFilter()
|
|
329
|
-
], CursorParamsDto.prototype, "filter", 2);
|
|
330
|
-
__decorateClass([
|
|
331
|
-
classValidator.IsOptional(),
|
|
332
|
-
classTransformer.Type(() => Number),
|
|
333
|
-
classValidator.IsInt(),
|
|
334
|
-
classValidator.IsPositive(),
|
|
335
|
-
classValidator.Max(core.DEFAULT_MAX_LIMIT)
|
|
336
|
-
], CursorParamsDto.prototype, "limit", 2);
|
|
337
|
-
__decorateClass([
|
|
338
|
-
classValidator.IsOptional(),
|
|
339
|
-
classValidator.IsString()
|
|
340
|
-
], CursorParamsDto.prototype, "cursor", 2);
|
|
341
|
-
__decorateClass([
|
|
342
|
-
classValidator.IsOptional(),
|
|
343
|
-
classValidator.IsString()
|
|
344
|
-
], CursorParamsDto.prototype, "cursorKey", 2);
|
|
345
|
-
__decorateClass([
|
|
346
|
-
classValidator.IsOptional(),
|
|
347
|
-
classValidator.IsIn(["asc", "desc"])
|
|
348
|
-
], CursorParamsDto.prototype, "order", 2);
|
|
349
|
-
__decorateClass([
|
|
350
|
-
classValidator.IsOptional(),
|
|
351
|
-
classValidator.IsIn(["forward", "backward"])
|
|
352
|
-
], CursorParamsDto.prototype, "direction", 2);
|
|
353
10
|
var applyNumber = (proto, property, bounds) => {
|
|
354
|
-
classValidator.IsOptional()(proto, property);
|
|
355
|
-
|
|
356
|
-
classValidator.
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
};
|
|
361
|
-
var applyServerOwned = (proto, field) => {
|
|
362
|
-
classValidator.IsOptional()(proto, field);
|
|
363
|
-
if (field === "withDeleted") classValidator.IsBoolean()(proto, field);
|
|
364
|
-
else classValidator.IsObject()(proto, field);
|
|
365
|
-
};
|
|
366
|
-
var applyFilterAndSort = (proto, options, withSort) => {
|
|
367
|
-
classValidator.IsOptional()(proto, "filter");
|
|
368
|
-
IsQueryFilter({ ...options.filter, allowedKeys: options.filter?.allowedKeys ?? options.allowedKeys })(proto, "filter");
|
|
369
|
-
if (withSort) {
|
|
370
|
-
classValidator.IsOptional()(proto, "sort");
|
|
371
|
-
IsQuerySort({ ...options.sort, allowedKeys: options.sort?.allowedKeys ?? options.allowedKeys })(proto, "sort");
|
|
372
|
-
}
|
|
373
|
-
for (const field of options.allow ?? []) applyServerOwned(proto, field);
|
|
374
|
-
};
|
|
375
|
-
var nameClass = (cls, name) => {
|
|
376
|
-
Object.defineProperty(cls, "name", { value: name, configurable: true });
|
|
377
|
-
return cls;
|
|
378
|
-
};
|
|
11
|
+
classValidator.IsOptional()(proto, property), classTransformer.Type(() => Number)(proto, property), classValidator.IsInt()(proto, property), bounds.positive && classValidator.IsPositive()(proto, property), bounds.min !== void 0 && classValidator.Min(bounds.min)(proto, property), bounds.max !== void 0 && Number.isFinite(bounds.max) && classValidator.Max(bounds.max)(proto, property);
|
|
12
|
+
}, applyServerOwned = (proto, field) => {
|
|
13
|
+
classValidator.IsOptional()(proto, field), field === "withDeleted" ? classValidator.IsBoolean()(proto, field) : classValidator.IsObject()(proto, field);
|
|
14
|
+
}, applyFilterAndSort = (proto, options, limits, withSort) => {
|
|
15
|
+
classValidator.IsOptional()(proto, "filter"), chunkX7HMP7H7_cjs.IsQueryFilter({ ...limits, ...options.filter, allowedKeys: options.filter?.allowedKeys ?? options.allowedKeys })(proto, "filter"), withSort && (classValidator.IsOptional()(proto, "sort"), chunkX7HMP7H7_cjs.IsQuerySort({ ...limits, ...options.sort, allowedKeys: options.sort?.allowedKeys ?? options.allowedKeys })(proto, "sort"));
|
|
16
|
+
for (let field of options.allow ?? []) applyServerOwned(proto, field);
|
|
17
|
+
}, nameClass = (cls, name) => (Object.defineProperty(cls, "name", { value: name, configurable: true }), cls);
|
|
379
18
|
function makeOffsetParamsDto(options = {}) {
|
|
380
19
|
class OffsetParams {
|
|
381
20
|
}
|
|
382
|
-
|
|
383
|
-
applyNumber(OffsetParams.prototype, "page", { positive: true });
|
|
384
|
-
applyNumber(OffsetParams.prototype, "perPage", { positive: true, max: options.maxPerPage ?? core.DEFAULT_MAX_PER_PAGE });
|
|
385
|
-
return nameClass(OffsetParams, "OffsetParamsDto");
|
|
21
|
+
let limits = core.resolveLimits(options.limits);
|
|
22
|
+
return applyFilterAndSort(OffsetParams.prototype, options, limits, true), applyNumber(OffsetParams.prototype, "page", { positive: true }), chunkX7HMP7H7_cjs.IsWithinMaxOffset({ mode: "page", maxOffset: limits.maxOffset })(OffsetParams.prototype, "page"), applyNumber(OffsetParams.prototype, "perPage", { positive: true, max: options.maxPerPage ?? core.DEFAULT_MAX_PER_PAGE }), classValidator.IsOptional()(OffsetParams.prototype, "withTotal"), classValidator.IsBoolean()(OffsetParams.prototype, "withTotal"), nameClass(OffsetParams, "OffsetParamsDto");
|
|
386
23
|
}
|
|
387
24
|
function makeInfiniteParamsDto(options = {}) {
|
|
388
25
|
class InfiniteParams {
|
|
389
26
|
}
|
|
390
|
-
|
|
391
|
-
applyNumber(InfiniteParams.prototype, "limit", { positive: true, max: options.maxLimit ?? core.DEFAULT_MAX_LIMIT });
|
|
392
|
-
applyNumber(InfiniteParams.prototype, "offset", { min: 0 });
|
|
393
|
-
return nameClass(InfiniteParams, "InfiniteParamsDto");
|
|
27
|
+
let limits = core.resolveLimits(options.limits);
|
|
28
|
+
return applyFilterAndSort(InfiniteParams.prototype, options, limits, true), applyNumber(InfiniteParams.prototype, "limit", { positive: true, max: options.maxLimit ?? core.DEFAULT_MAX_LIMIT }), applyNumber(InfiniteParams.prototype, "offset", { min: 0 }), chunkX7HMP7H7_cjs.IsWithinMaxOffset({ mode: "offset", maxOffset: limits.maxOffset })(InfiniteParams.prototype, "offset"), nameClass(InfiniteParams, "InfiniteParamsDto");
|
|
394
29
|
}
|
|
395
30
|
function makeCursorParamsDto(options = {}) {
|
|
396
31
|
class CursorParams {
|
|
397
32
|
}
|
|
398
|
-
|
|
399
|
-
applyFilterAndSort(proto, options, false);
|
|
400
|
-
applyNumber(proto, "limit", { positive: true, max: options.maxLimit ?? core.DEFAULT_MAX_LIMIT });
|
|
401
|
-
classValidator.IsOptional()(proto, "cursor");
|
|
402
|
-
classValidator.IsString()(proto, "cursor");
|
|
403
|
-
classValidator.IsOptional()(proto, "cursorKey");
|
|
404
|
-
classValidator.IsString()(proto, "cursorKey");
|
|
405
|
-
classValidator.IsOptional()(proto, "order");
|
|
406
|
-
classValidator.IsIn(["asc", "desc"])(proto, "order");
|
|
407
|
-
classValidator.IsOptional()(proto, "direction");
|
|
408
|
-
classValidator.IsIn(["forward", "backward"])(proto, "direction");
|
|
409
|
-
return nameClass(CursorParams, "CursorParamsDto");
|
|
33
|
+
let proto = CursorParams.prototype;
|
|
34
|
+
return applyFilterAndSort(proto, options, core.resolveLimits(options.limits), false), applyNumber(proto, "limit", { positive: true, max: options.maxLimit ?? core.DEFAULT_MAX_LIMIT }), classValidator.IsOptional()(proto, "cursor"), classValidator.IsString()(proto, "cursor"), classValidator.IsOptional()(proto, "cursorKey"), classValidator.IsString()(proto, "cursorKey"), classValidator.IsOptional()(proto, "order"), classValidator.IsIn(["asc", "desc"])(proto, "order"), classValidator.IsOptional()(proto, "direction"), classValidator.IsIn(["forward", "backward"])(proto, "direction"), nameClass(CursorParams, "CursorParamsDto");
|
|
410
35
|
}
|
|
411
36
|
|
|
412
|
-
exports
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
exports
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
exports
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
exports
|
|
37
|
+
Object.defineProperty(exports, "BaseParamsDto", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () { return chunkBZRPXHJC_cjs.BaseParamsDto; }
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, "CursorParamsDto", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () { return chunkBZRPXHJC_cjs.CursorParamsDto; }
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "InfiniteParamsDto", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () { return chunkBZRPXHJC_cjs.InfiniteParamsDto; }
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, "OffsetParamsDto", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () { return chunkBZRPXHJC_cjs.OffsetParamsDto; }
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(exports, "IsQueryFilter", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function () { return chunkX7HMP7H7_cjs.IsQueryFilter; }
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "IsQueryFilterConstraint", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function () { return chunkX7HMP7H7_cjs.IsQueryFilterConstraint; }
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "IsQuerySort", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () { return chunkX7HMP7H7_cjs.IsQuerySort; }
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(exports, "IsQuerySortConstraint", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () { return chunkX7HMP7H7_cjs.IsQuerySortConstraint; }
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, "IsWithinMaxOffset", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function () { return chunkX7HMP7H7_cjs.IsWithinMaxOffset; }
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "IsWithinMaxOffsetConstraint", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () { return chunkX7HMP7H7_cjs.IsWithinMaxOffsetConstraint; }
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(exports, "DEFAULT_MAX_FILTER_DEPTH", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () { return chunkKXCJO556_cjs.DEFAULT_MAX_FILTER_DEPTH; }
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, "QUERYKIT_LOCALES", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function () { return chunkKXCJO556_cjs.QUERYKIT_LOCALES; }
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(exports, "QUERYKIT_MESSAGES_EN", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () { return chunkKXCJO556_cjs.QUERYKIT_MESSAGES_EN; }
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, "QUERYKIT_MESSAGES_RU", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function () { return chunkKXCJO556_cjs.QUERYKIT_MESSAGES_RU; }
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(exports, "QUERYKIT_MESSAGES_UZ", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function () { return chunkKXCJO556_cjs.QUERYKIT_MESSAGES_UZ; }
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(exports, "formatMessage", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () { return chunkKXCJO556_cjs.formatMessage; }
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, "localizeIssue", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function () { return chunkKXCJO556_cjs.localizeIssue; }
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(exports, "validateFilter", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () { return chunkKXCJO556_cjs.validateFilter; }
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, "validateSort", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () { return chunkKXCJO556_cjs.validateSort; }
|
|
112
|
+
});
|
|
425
113
|
exports.makeCursorParamsDto = makeCursorParamsDto;
|
|
426
114
|
exports.makeInfiniteParamsDto = makeInfiniteParamsDto;
|
|
427
115
|
exports.makeOffsetParamsDto = makeOffsetParamsDto;
|
|
428
|
-
exports.validateFilter = validateFilter;
|
|
429
|
-
exports.validateSort = validateSort;
|
|
430
116
|
//# sourceMappingURL=index.cjs.map
|
|
431
117
|
//# sourceMappingURL=index.cjs.map
|