@querykitjs/class-validator 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +68 -15
- package/README.md +68 -15
- package/dist/chunk-AX53IY63.cjs +89 -0
- package/dist/chunk-AX53IY63.cjs.map +1 -0
- package/dist/chunk-HKLXL3NW.cjs +42 -0
- package/dist/chunk-HKLXL3NW.cjs.map +1 -0
- package/dist/chunk-PKGWV2JC.cjs +81 -0
- package/dist/chunk-PKGWV2JC.cjs.map +1 -0
- package/dist/chunk-QMFPUYJO.js +30 -0
- package/dist/chunk-QMFPUYJO.js.map +1 -0
- package/dist/chunk-V4E73HMQ.js +85 -0
- package/dist/chunk-V4E73HMQ.js.map +1 -0
- package/dist/chunk-XF6C4EG2.js +76 -0
- package/dist/chunk-XF6C4EG2.js.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 +92 -375
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -73
- package/dist/index.d.ts +101 -73
- package/dist/index.js +30 -363
- 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,38 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkPKGWV2JC_cjs = require('./chunk-PKGWV2JC.cjs');
|
|
4
|
+
var chunkAX53IY63_cjs = require('./chunk-AX53IY63.cjs');
|
|
5
|
+
var chunkHKLXL3NW_cjs = require('./chunk-HKLXL3NW.cjs');
|
|
6
|
+
var internal = require('@querykitjs/core/internal');
|
|
5
7
|
var classTransformer = require('class-transformer');
|
|
8
|
+
var classValidator = require('class-validator');
|
|
9
|
+
var core = require('@querykitjs/core');
|
|
6
10
|
|
|
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
11
|
var QUERYKIT_MESSAGES_UZ = {
|
|
37
12
|
"querykit.filter.invalid_node": "{path} filter sharti yoki and/or/not guruhi bo'lishi kerak",
|
|
38
13
|
"querykit.filter.missing_key": "{path} da majburiy `key` (string) yo'q",
|
|
@@ -40,7 +15,7 @@ var QUERYKIT_MESSAGES_UZ = {
|
|
|
40
15
|
"querykit.filter.invalid_operator": "{path}: `{operation}` qo'llab-quvvatlanadigan filter operatori emas",
|
|
41
16
|
"querykit.filter.invalid_value": "{path} string, raqam, boolean, null yoki shularning massivi bo'lishi kerak",
|
|
42
17
|
"querykit.filter.invalid_group": "{path} filter tugunlari massivi bo'lishi kerak",
|
|
43
|
-
"querykit.filter.max_depth": "{path}
|
|
18
|
+
"querykit.filter.max_depth": "{path} limitdan oshdi: maxDepth ({max})",
|
|
44
19
|
"querykit.filter.value_requires_array": "{path}: `{operation}` massiv qiymat talab qiladi",
|
|
45
20
|
"querykit.filter.value_requires_tuple": "{path}: `{operation}` aynan ikkita qiymat talab qiladi",
|
|
46
21
|
"querykit.filter.value_forbidden": "{path}: `{operation}` qiymat qabul qilmaydi",
|
|
@@ -48,16 +23,16 @@ var QUERYKIT_MESSAGES_UZ = {
|
|
|
48
23
|
"querykit.sort.invalid_item": "{path} `key` (string) maydoniga ega obyekt bo'lishi kerak",
|
|
49
24
|
"querykit.sort.missing_key": "{path} da majburiy `key` (string) yo'q",
|
|
50
25
|
"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
|
-
|
|
26
|
+
"querykit.sort.invalid_direction": "{path}: direction `asc` yoki `desc` bo'lishi kerak",
|
|
27
|
+
"querykit.limit.exceeded": "{path} limitdan oshdi: {limit} ({max})"
|
|
28
|
+
}, QUERYKIT_MESSAGES_RU = {
|
|
54
29
|
"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
30
|
"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
31
|
"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
32
|
"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
33
|
"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
34
|
"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 \
|
|
35
|
+
"querykit.filter.max_depth": "{path} \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u0435\u0442 \u043B\u0438\u043C\u0438\u0442 maxDepth ({max})",
|
|
61
36
|
"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
37
|
"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
38
|
"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",
|
|
@@ -65,367 +40,109 @@ var QUERYKIT_MESSAGES_RU = {
|
|
|
65
40
|
"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
41
|
"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
42
|
"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
|
-
|
|
71
|
-
en: QUERYKIT_MESSAGES_EN,
|
|
43
|
+
"querykit.sort.invalid_direction": "{path}: direction \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C `asc` \u0438\u043B\u0438 `desc`",
|
|
44
|
+
"querykit.limit.exceeded": "{path} \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u0435\u0442 \u043B\u0438\u043C\u0438\u0442 {limit} ({max})"
|
|
45
|
+
}, QUERYKIT_LOCALES = {
|
|
46
|
+
en: internal.QUERYKIT_MESSAGES_EN,
|
|
72
47
|
uz: QUERYKIT_MESSAGES_UZ,
|
|
73
48
|
ru: QUERYKIT_MESSAGES_RU
|
|
74
49
|
};
|
|
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
50
|
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
|
-
};
|
|
51
|
+
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);
|
|
52
|
+
}, applyServerOwned = (proto, field) => {
|
|
53
|
+
classValidator.IsOptional()(proto, field), field === "withDeleted" ? classValidator.IsBoolean()(proto, field) : classValidator.IsObject()(proto, field);
|
|
54
|
+
}, applyFilterAndSort = (proto, options, limits, withSort) => {
|
|
55
|
+
classValidator.IsOptional()(proto, "filter"), chunkAX53IY63_cjs.IsQueryFilter({ ...limits, ...options.filter, allowedKeys: options.filter?.allowedKeys ?? options.allowedKeys })(proto, "filter"), withSort && (classValidator.IsOptional()(proto, "sort"), chunkAX53IY63_cjs.IsQuerySort({ ...limits, ...options.sort, allowedKeys: options.sort?.allowedKeys ?? options.allowedKeys })(proto, "sort"));
|
|
56
|
+
for (let field of options.allow ?? []) applyServerOwned(proto, field);
|
|
57
|
+
}, nameClass = (cls, name) => (Object.defineProperty(cls, "name", { value: name, configurable: true }), cls);
|
|
379
58
|
function makeOffsetParamsDto(options = {}) {
|
|
380
59
|
class OffsetParams {
|
|
381
60
|
}
|
|
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");
|
|
61
|
+
let limits = core.resolveLimits(options.limits);
|
|
62
|
+
return applyFilterAndSort(OffsetParams.prototype, options, limits, true), applyNumber(OffsetParams.prototype, "page", { positive: true }), chunkAX53IY63_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
63
|
}
|
|
387
64
|
function makeInfiniteParamsDto(options = {}) {
|
|
388
65
|
class InfiniteParams {
|
|
389
66
|
}
|
|
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");
|
|
67
|
+
let limits = core.resolveLimits(options.limits);
|
|
68
|
+
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 }), chunkAX53IY63_cjs.IsWithinMaxOffset({ mode: "offset", maxOffset: limits.maxOffset })(InfiniteParams.prototype, "offset"), nameClass(InfiniteParams, "InfiniteParamsDto");
|
|
394
69
|
}
|
|
395
70
|
function makeCursorParamsDto(options = {}) {
|
|
396
71
|
class CursorParams {
|
|
397
72
|
}
|
|
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");
|
|
73
|
+
let proto = CursorParams.prototype;
|
|
74
|
+
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
75
|
}
|
|
411
76
|
|
|
412
|
-
exports
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
exports
|
|
417
|
-
|
|
418
|
-
|
|
77
|
+
Object.defineProperty(exports, "BaseParamsDto", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () { return chunkPKGWV2JC_cjs.BaseParamsDto; }
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, "CursorParamsDto", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function () { return chunkPKGWV2JC_cjs.CursorParamsDto; }
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(exports, "InfiniteParamsDto", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () { return chunkPKGWV2JC_cjs.InfiniteParamsDto; }
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, "OffsetParamsDto", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function () { return chunkPKGWV2JC_cjs.OffsetParamsDto; }
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(exports, "IsQueryFilter", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function () { return chunkAX53IY63_cjs.IsQueryFilter; }
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(exports, "IsQueryFilterConstraint", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () { return chunkAX53IY63_cjs.IsQueryFilterConstraint; }
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, "IsQuerySort", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function () { return chunkAX53IY63_cjs.IsQuerySort; }
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(exports, "IsQuerySortConstraint", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () { return chunkAX53IY63_cjs.IsQuerySortConstraint; }
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, "IsWithinMaxOffset", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () { return chunkAX53IY63_cjs.IsWithinMaxOffset; }
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(exports, "IsWithinMaxOffsetConstraint", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
get: function () { return chunkAX53IY63_cjs.IsWithinMaxOffsetConstraint; }
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(exports, "DEFAULT_MAX_FILTER_DEPTH", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function () { return chunkHKLXL3NW_cjs.DEFAULT_MAX_FILTER_DEPTH; }
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(exports, "formatMessage", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () { return chunkHKLXL3NW_cjs.formatMessage; }
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(exports, "localizeIssue", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get: function () { return chunkHKLXL3NW_cjs.localizeIssue; }
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(exports, "validateFilter", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function () { return chunkHKLXL3NW_cjs.validateFilter; }
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(exports, "validateSort", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function () { return chunkHKLXL3NW_cjs.validateSort; }
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(exports, "QUERYKIT_MESSAGES_EN", {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
get: function () { return internal.QUERYKIT_MESSAGES_EN; }
|
|
140
|
+
});
|
|
419
141
|
exports.QUERYKIT_LOCALES = QUERYKIT_LOCALES;
|
|
420
|
-
exports.QUERYKIT_MESSAGES_EN = QUERYKIT_MESSAGES_EN;
|
|
421
142
|
exports.QUERYKIT_MESSAGES_RU = QUERYKIT_MESSAGES_RU;
|
|
422
143
|
exports.QUERYKIT_MESSAGES_UZ = QUERYKIT_MESSAGES_UZ;
|
|
423
|
-
exports.formatMessage = formatMessage;
|
|
424
|
-
exports.localizeIssue = localizeIssue;
|
|
425
144
|
exports.makeCursorParamsDto = makeCursorParamsDto;
|
|
426
145
|
exports.makeInfiniteParamsDto = makeInfiniteParamsDto;
|
|
427
146
|
exports.makeOffsetParamsDto = makeOffsetParamsDto;
|
|
428
|
-
exports.validateFilter = validateFilter;
|
|
429
|
-
exports.validateSort = validateSort;
|
|
430
147
|
//# sourceMappingURL=index.cjs.map
|
|
431
148
|
//# sourceMappingURL=index.cjs.map
|