validup 0.1.5 → 0.1.7
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/dist/constants.d.ts +14 -0
- package/dist/helpers/index.d.ts +1 -3
- package/dist/helpers/optional-value.d.ts +8 -0
- package/dist/index.cjs +65 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +65 -176
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +23 -0
- package/package.json +2 -1
- package/dist/helpers/array-to-property-path.d.ts +0 -5
- package/dist/helpers/expand-property-path.d.ts +0 -1
- package/dist/helpers/get-property-path-value.d.ts +0 -2
- package/dist/helpers/property-path-to-array.d.ts +0 -7
package/dist/constants.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
export declare enum GroupKey {
|
|
2
2
|
WILDCARD = "*"
|
|
3
3
|
}
|
|
4
|
+
export declare enum OptionalValue {
|
|
5
|
+
/**
|
|
6
|
+
* value: undefined
|
|
7
|
+
*/
|
|
8
|
+
UNDEFINED = "undefined",
|
|
9
|
+
/**
|
|
10
|
+
* value: null & undefined
|
|
11
|
+
*/
|
|
12
|
+
NULL = "null",
|
|
13
|
+
/**
|
|
14
|
+
* value: empty string, false, 0
|
|
15
|
+
*/
|
|
16
|
+
FALSY = "falsy"
|
|
17
|
+
}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OptionalValue } from '../constants';
|
|
2
|
+
/**
|
|
3
|
+
* Check if input value (type of) satisfies optional value type constraint.
|
|
4
|
+
*
|
|
5
|
+
* @param value
|
|
6
|
+
* @param optionalValue
|
|
7
|
+
*/
|
|
8
|
+
export declare function isOptionalValue(value: unknown, optionalValue?: `${OptionalValue}`): boolean;
|
package/dist/index.cjs
CHANGED
|
@@ -1,36 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var smob = require('smob');
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Copyright (c) 2024.
|
|
7
|
-
* Author Peter Placzek (tada5hi)
|
|
8
|
-
* For the full copyright and license information,
|
|
9
|
-
* view the LICENSE file that was distributed with this source code.
|
|
10
|
-
*/ /**
|
|
11
|
-
* @see https://github.com/express-validator/express-validator/blob/bec1dcbaa29002dcd21093ec84818c4671063b5d/src/field-selection.ts#L214
|
|
12
|
-
* @param parts
|
|
13
|
-
*/ function arrayToPropertyPath(parts) {
|
|
14
|
-
return parts.reduce((prev, segment)=>{
|
|
15
|
-
let part = '';
|
|
16
|
-
segment = segment === '\\*' ? '*' : segment;
|
|
17
|
-
// TODO: Handle brackets?
|
|
18
|
-
if (segment.includes('.')) {
|
|
19
|
-
// Special char key access
|
|
20
|
-
part = `["${segment}"]`;
|
|
21
|
-
} else if (/^\d+$/.test(segment)) {
|
|
22
|
-
// Index access
|
|
23
|
-
part = `[${segment}]`;
|
|
24
|
-
} else if (prev) {
|
|
25
|
-
// Object key access
|
|
26
|
-
part = `.${segment}`;
|
|
27
|
-
} else {
|
|
28
|
-
// Top level key
|
|
29
|
-
part = segment;
|
|
30
|
-
}
|
|
31
|
-
return prev + part;
|
|
32
|
-
}, '');
|
|
33
|
-
}
|
|
4
|
+
var pathtrace = require('pathtrace');
|
|
34
5
|
|
|
35
6
|
function buildErrorMessageForAttributes(input) {
|
|
36
7
|
let names;
|
|
@@ -53,105 +24,39 @@ function buildErrorMessageForAttributes(input) {
|
|
|
53
24
|
* Author Peter Placzek (tada5hi)
|
|
54
25
|
* For the full copyright and license information,
|
|
55
26
|
* view the LICENSE file that was distributed with this source code.
|
|
56
|
-
*/
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
27
|
+
*/ exports.GroupKey = void 0;
|
|
28
|
+
(function(GroupKey) {
|
|
29
|
+
GroupKey["WILDCARD"] = "*";
|
|
30
|
+
})(exports.GroupKey || (exports.GroupKey = {}));
|
|
31
|
+
exports.OptionalValue = void 0;
|
|
32
|
+
(function(OptionalValue) {
|
|
33
|
+
/**
|
|
34
|
+
* value: undefined
|
|
35
|
+
*/ OptionalValue["UNDEFINED"] = "undefined";
|
|
36
|
+
/**
|
|
37
|
+
* value: null & undefined
|
|
38
|
+
*/ OptionalValue["NULL"] = "null";
|
|
39
|
+
/**
|
|
40
|
+
* value: empty string, false, 0
|
|
41
|
+
*/ OptionalValue["FALSY"] = "falsy";
|
|
42
|
+
})(exports.OptionalValue || (exports.OptionalValue = {}));
|
|
69
43
|
|
|
70
|
-
/*
|
|
71
|
-
* Copyright (c) 2024.
|
|
72
|
-
* Author Peter Placzek (tada5hi)
|
|
73
|
-
* For the full copyright and license information,
|
|
74
|
-
* view the LICENSE file that was distributed with this source code.
|
|
75
|
-
*/ /**
|
|
76
|
-
* Match property names within property paths.
|
|
77
|
-
*
|
|
78
|
-
* @see https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L146C7-L146C118
|
|
79
|
-
*/ const rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
|
80
|
-
/**
|
|
81
|
-
* Match backslashes in property paths.
|
|
82
|
-
*
|
|
83
|
-
* @see https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L168C1-L168C54
|
|
84
|
-
*/ const reEscapeChar = /\\(\\)?/g;
|
|
85
44
|
/**
|
|
86
|
-
*
|
|
45
|
+
* Check if input value (type of) satisfies optional value type constraint.
|
|
87
46
|
*
|
|
88
|
-
* @
|
|
89
|
-
* @param
|
|
90
|
-
*/ function
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
93
|
-
|
|
47
|
+
* @param value
|
|
48
|
+
* @param optionalValue
|
|
49
|
+
*/ function isOptionalValue(value, optionalValue) {
|
|
50
|
+
const optionValueNormalized = optionalValue || exports.OptionalValue.UNDEFINED;
|
|
51
|
+
if (optionValueNormalized === exports.OptionalValue.NULL) {
|
|
52
|
+
return value === null;
|
|
94
53
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return match;
|
|
98
|
-
});
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function getPropertyPathValue(data, path) {
|
|
103
|
-
const parts = propertyPathToArray(path);
|
|
104
|
-
let temp = data;
|
|
105
|
-
let index = 0;
|
|
106
|
-
while(index < parts.length){
|
|
107
|
-
if (!isObject(temp) && !Array.isArray(temp)) {
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
temp = temp[parts[index]];
|
|
111
|
-
index++;
|
|
112
|
-
}
|
|
113
|
-
return temp;
|
|
114
|
-
}
|
|
115
|
-
function isIndex(input) {
|
|
116
|
-
return typeof input === 'number' || !Number.isNaN(Number.parseInt(input, 10));
|
|
117
|
-
}
|
|
118
|
-
function setPropertyPathValue(data, path, value) {
|
|
119
|
-
const parts = Array.isArray(path) ? path : propertyPathToArray(path);
|
|
120
|
-
let temp = data;
|
|
121
|
-
let index = 0;
|
|
122
|
-
while(index < parts.length){
|
|
123
|
-
if (!Array.isArray(temp) && !isObject(temp)) {
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
const key = parts[index];
|
|
127
|
-
// [foo, '0']
|
|
128
|
-
if (typeof temp[key] === 'undefined') {
|
|
129
|
-
if (isIndex(key + 1)) {
|
|
130
|
-
temp[key] = [];
|
|
131
|
-
} else {
|
|
132
|
-
temp[key] = {};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (index === parts.length - 1) {
|
|
136
|
-
temp[key] = value;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
index++;
|
|
140
|
-
temp = temp[key];
|
|
54
|
+
if (optionValueNormalized === exports.OptionalValue.UNDEFINED) {
|
|
55
|
+
return typeof value === 'undefined';
|
|
141
56
|
}
|
|
142
|
-
return
|
|
57
|
+
return !value;
|
|
143
58
|
}
|
|
144
59
|
|
|
145
|
-
/*
|
|
146
|
-
* Copyright (c) 2024.
|
|
147
|
-
* Author Peter Placzek (tada5hi)
|
|
148
|
-
* For the full copyright and license information,
|
|
149
|
-
* view the LICENSE file that was distributed with this source code.
|
|
150
|
-
*/ exports.GroupKey = void 0;
|
|
151
|
-
(function(GroupKey) {
|
|
152
|
-
GroupKey["WILDCARD"] = "*";
|
|
153
|
-
})(exports.GroupKey || (exports.GroupKey = {}));
|
|
154
|
-
|
|
155
60
|
/*
|
|
156
61
|
* Copyright (c) 2024-2024.
|
|
157
62
|
* Author Peter Placzek (tada5hi)
|
|
@@ -186,47 +91,23 @@ class ValidupNestedError extends ValidupError {
|
|
|
186
91
|
}
|
|
187
92
|
}
|
|
188
93
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
// there still are paths to traverse, but value is a primitive, stop
|
|
207
|
-
return [];
|
|
208
|
-
}
|
|
209
|
-
// Use a non-null value so that non-existing fields are still selected
|
|
210
|
-
data = data || {};
|
|
211
|
-
if (key === '*') {
|
|
212
|
-
return Object.keys(data).flatMap((key)=>expandPropertyPath(data[key], rest, currPath.concat(key)));
|
|
213
|
-
}
|
|
214
|
-
if (key === '**') {
|
|
215
|
-
return Object.keys(data).flatMap((key)=>{
|
|
216
|
-
const nextPath = currPath.concat(key);
|
|
217
|
-
const value = data[key];
|
|
218
|
-
const set = new Set([
|
|
219
|
-
// recursively find matching sub-paths
|
|
220
|
-
...expandPropertyPath(value, segments, nextPath),
|
|
221
|
-
// skip the first remaining segment, if it matches the current key
|
|
222
|
-
...rest[0] === key ? expandPropertyPath(value, rest.slice(1), nextPath) : []
|
|
223
|
-
]);
|
|
224
|
-
return [
|
|
225
|
-
...set
|
|
226
|
-
];
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
return expandPropertyPath(data[key], rest, currPath.concat(key));
|
|
94
|
+
/*
|
|
95
|
+
* Copyright (c) 2024.
|
|
96
|
+
* Author Peter Placzek (tada5hi)
|
|
97
|
+
* For the full copyright and license information,
|
|
98
|
+
* view the LICENSE file that was distributed with this source code.
|
|
99
|
+
*/ // eslint-disable-next-line @typescript-eslint/ban-types
|
|
100
|
+
function hasOwnProperty(obj, prop) {
|
|
101
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
* Copyright (c) 2024.
|
|
106
|
+
* Author Peter Placzek (tada5hi)
|
|
107
|
+
* For the full copyright and license information,
|
|
108
|
+
* view the LICENSE file that was distributed with this source code.
|
|
109
|
+
*/ function isObject(input) {
|
|
110
|
+
return !!input && typeof input === 'object' && !Array.isArray(input);
|
|
230
111
|
}
|
|
231
112
|
|
|
232
113
|
class Container {
|
|
@@ -288,7 +169,7 @@ class Container {
|
|
|
288
169
|
let pathsCount = 0;
|
|
289
170
|
let paths;
|
|
290
171
|
if (item.path) {
|
|
291
|
-
paths =
|
|
172
|
+
paths = pathtrace.expandPath(data, item.path);
|
|
292
173
|
} else {
|
|
293
174
|
paths = [
|
|
294
175
|
''
|
|
@@ -300,23 +181,31 @@ class Container {
|
|
|
300
181
|
let value;
|
|
301
182
|
if (hasOwnProperty(output, path)) {
|
|
302
183
|
value = output[path];
|
|
184
|
+
} else if (path.length > 0) {
|
|
185
|
+
value = pathtrace.getPathValue(data, path);
|
|
303
186
|
} else {
|
|
304
|
-
value =
|
|
187
|
+
value = data;
|
|
305
188
|
}
|
|
306
189
|
if (typeof pathsToInclude !== 'undefined' && pathsToInclude.indexOf(path) === -1) {
|
|
307
190
|
continue;
|
|
308
191
|
}
|
|
309
192
|
try {
|
|
310
193
|
if (item.data instanceof Container) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
194
|
+
if (item.optional && isOptionalValue(value, item.optionalValue)) {
|
|
195
|
+
if (item.optionalInclude) {
|
|
196
|
+
output[path] = value;
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
const tmp = await item.data.run(isObject(value) ? value : {}, {
|
|
200
|
+
group: options.group,
|
|
201
|
+
flat: true,
|
|
202
|
+
path: pathAbsolute,
|
|
203
|
+
pathsToInclude: options.pathsToInclude
|
|
204
|
+
});
|
|
205
|
+
const tmpKeys = Object.keys(tmp);
|
|
206
|
+
for(let k = 0; k < tmpKeys.length; k++){
|
|
207
|
+
output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];
|
|
208
|
+
}
|
|
320
209
|
}
|
|
321
210
|
} else {
|
|
322
211
|
output[path] = await item.data({
|
|
@@ -379,7 +268,7 @@ class Container {
|
|
|
379
268
|
const temp = {};
|
|
380
269
|
const keys = Object.keys(output);
|
|
381
270
|
for(let i = 0; i < keys.length; i++){
|
|
382
|
-
|
|
271
|
+
pathtrace.setPathValue(temp, keys[i], output[keys[i]]);
|
|
383
272
|
}
|
|
384
273
|
return temp;
|
|
385
274
|
}
|
|
@@ -435,11 +324,8 @@ exports.Container = Container;
|
|
|
435
324
|
exports.ValidupError = ValidupError;
|
|
436
325
|
exports.ValidupNestedError = ValidupNestedError;
|
|
437
326
|
exports.ValidupValidatorError = ValidupValidatorError;
|
|
438
|
-
exports.arrayToPropertyPath = arrayToPropertyPath;
|
|
439
327
|
exports.buildErrorMessageForAttributes = buildErrorMessageForAttributes;
|
|
440
|
-
exports.getPropertyPathValue = getPropertyPathValue;
|
|
441
328
|
exports.hasOwnProperty = hasOwnProperty;
|
|
442
329
|
exports.isObject = isObject;
|
|
443
|
-
exports.
|
|
444
|
-
exports.setPropertyPathValue = setPropertyPathValue;
|
|
330
|
+
exports.isOptionalValue = isOptionalValue;
|
|
445
331
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/helpers/array-to-property-path.ts","../src/helpers/error.ts","../src/utils/has-own-property.ts","../src/utils/object.ts","../src/helpers/property-path-to-array.ts","../src/helpers/get-property-path-value.ts","../src/constants.ts","../src/errors/validator.ts","../src/errors/base.ts","../src/errors/nested.ts","../src/helpers/expand-property-path.ts","../src/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n/**\n * @see https://github.com/express-validator/express-validator/blob/bec1dcbaa29002dcd21093ec84818c4671063b5d/src/field-selection.ts#L214\n * @param parts\n */\nexport function arrayToPropertyPath(parts: readonly string[]) : string {\n return parts.reduce((prev, segment) => {\n let part = '';\n segment = segment === '\\\\*' ? '*' : segment;\n\n // TODO: Handle brackets?\n if (segment.includes('.')) {\n // Special char key access\n part = `[\"${segment}\"]`;\n } else if (/^\\d+$/.test(segment)) {\n // Index access\n part = `[${segment}]`;\n } else if (prev) {\n // Object key access\n part = `.${segment}`;\n } else {\n // Top level key\n part = segment;\n }\n\n return prev + part;\n }, '');\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { distinctArray } from 'smob';\n\nexport function buildErrorMessageForAttributes(input: (number | string)[] | Record<string, any>) {\n let names: string[];\n if (Array.isArray(input)) {\n names = distinctArray(input);\n } else {\n names = Object.keys(input);\n }\n\n if (names.length === 0) {\n return 'An unexpected error occurred.';\n }\n\n if (names.length > 1) {\n return `The attributes ${names.join(', ')} are invalid.`;\n }\n\n return `The attribute ${String(names[0])} is invalid.`;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(input: unknown) : input is Record<string, any> {\n return !!input &&\n typeof input === 'object' &&\n !Array.isArray(input);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n/**\n * Match property names within property paths.\n *\n * @see https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L146C7-L146C118\n */\nconst rePropName = /[^.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))/g;\n\n/**\n * Match backslashes in property paths.\n *\n * @see https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L168C1-L168C54\n */\nconst reEscapeChar = /\\\\(\\\\)?/g;\n\n/**\n * Convert string to property path array.\n *\n * @see https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L6735\n * @param segment\n */\nexport function propertyPathToArray(segment: string) : string[] {\n const result = [];\n if (segment.charCodeAt(0) === 46 /* . */) {\n result.push('');\n }\n segment.replace(rePropName, (match, number, quote, subString) => {\n result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));\n\n return match;\n });\n\n return result;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from '../utils';\nimport { propertyPathToArray } from './property-path-to-array';\n\nexport function getPropertyPathValue(\n data: Record<string, any>,\n path: string,\n): unknown {\n const parts = propertyPathToArray(path);\n\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n if (!isObject(temp) && !Array.isArray(temp)) {\n break;\n }\n\n temp = temp[parts[index]];\n index++;\n }\n\n return temp;\n}\n\nfunction isIndex(input: string | number) : input is number {\n return typeof input === 'number' || !Number.isNaN(Number.parseInt(input, 10));\n}\n\nexport function setPropertyPathValue(\n data: Record<string, any> | Record<string, any>[],\n path: string | string[],\n value: unknown,\n) {\n const parts = Array.isArray(path) ? path : propertyPathToArray(path);\n\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n if (!Array.isArray(temp) && !isObject(temp)) {\n break;\n }\n\n const key = parts[index] as keyof typeof temp;\n // [foo, '0']\n if (typeof temp[key] === 'undefined') {\n if (isIndex(key + 1)) {\n (temp as Record<string, any>)[key] = [];\n } else {\n temp[key] = {};\n }\n }\n\n if (index === parts.length - 1) {\n temp[key] = value;\n break;\n }\n\n index++;\n temp = temp[key];\n }\n\n return data;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum GroupKey {\n WILDCARD = '*',\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport type ValidupValidatorErrorOptions = {\n path: string,\n pathAbsolute?: string,\n message?: string,\n code?: string | null,\n received?: unknown,\n expected?: unknown\n};\n\nexport class ValidupValidatorError extends Error {\n readonly path: string;\n\n readonly pathAbsolute : string;\n\n readonly code?: string | null;\n\n readonly received?: unknown;\n\n readonly expected?: unknown;\n\n constructor(options: ValidupValidatorErrorOptions) {\n super(options.message);\n\n this.path = options.path;\n this.pathAbsolute = options.pathAbsolute ?? options.path;\n this.code = options.code;\n this.received = options.received;\n this.expected = options.expected;\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport class ValidupError extends Error {\n\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { ValidupValidatorError } from './validator';\nimport { ValidupError } from './base';\n\nexport type ValidupNestedErrorOptions = {\n children?: ValidupValidatorError[],\n message?: string\n};\n\nexport class ValidupNestedError extends ValidupError {\n children: ValidupValidatorError[];\n\n constructor(options: ValidupNestedErrorOptions = {}) {\n super(options.message || 'One or many attributes may be invalid.');\n\n this.children = options.children || [];\n }\n\n addChild(child: ValidupValidatorError) {\n this.children.push(child);\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from '../utils';\nimport { arrayToPropertyPath } from './array-to-property-path';\nimport { propertyPathToArray } from './property-path-to-array';\n\nexport function expandPropertyPath(\n data: Record<string, any>,\n path: string | string[],\n currPath: readonly string[],\n): string[] {\n const segments = Array.isArray(path) ? path : propertyPathToArray(path);\n if (!segments.length) {\n // no more paths to traverse\n return [arrayToPropertyPath(currPath)];\n }\n\n const key = segments[0];\n const rest = segments.slice(1);\n\n if (\n typeof data !== 'undefined' &&\n data !== null &&\n !isObject(data) &&\n !Array.isArray(data)\n ) {\n if (key === '**' && !rest.length) {\n // globstar leaves are always selected\n return [arrayToPropertyPath(currPath)];\n }\n\n // there still are paths to traverse, but value is a primitive, stop\n return [];\n }\n\n // Use a non-null value so that non-existing fields are still selected\n data = data || {};\n\n if (key === '*') {\n return Object.keys(data)\n .flatMap((key) => expandPropertyPath(data[key], rest, currPath.concat(key)));\n }\n\n if (key === '**') {\n return Object.keys(data)\n .flatMap((key) => {\n const nextPath = currPath.concat(key);\n const value = data[key];\n const set = new Set([\n // recursively find matching sub-paths\n ...expandPropertyPath(value, segments, nextPath),\n // skip the first remaining segment, if it matches the current key\n ...(rest[0] === key ? expandPropertyPath(value, rest.slice(1), nextPath) : []),\n ]);\n\n return [...set];\n });\n }\n\n return expandPropertyPath(data[key], rest, currPath.concat(key));\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { GroupKey } from './constants';\nimport { ValidupNestedError, ValidupValidatorError } from './errors';\nimport { buildErrorMessageForAttributes, getPropertyPathValue, setPropertyPathValue } from './helpers';\nimport { expandPropertyPath } from './helpers/expand-property-path';\nimport type {\n ContainerItem,\n ContainerMountOptions,\n ContainerOptions,\n ContainerRunOptions,\n ObjectPropertyPath,\n ObjectPropertyPathExtended,\n Validator,\n} from './types';\nimport { hasOwnProperty, isObject } from './utils';\n\nexport class Container<\n T extends Record<string, any> = Record<string, any>,\n> {\n protected options : ContainerOptions<T>;\n\n protected items : ContainerItem[];\n\n // ----------------------------------------------\n\n constructor(options: ContainerOptions<T> = {}) {\n this.options = options;\n this.items = [];\n\n this.initialize();\n }\n\n // ----------------------------------------------\n\n mount(container: Container) : void;\n\n mount(\n options: ContainerMountOptions,\n container: Container\n ): void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n data: Container | Validator\n ) : void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n options: ContainerMountOptions,\n data: Container | Validator\n ) : void;\n\n mount(...args: any[]) : void {\n if (args.length < 1) {\n throw new SyntaxError('The mount method requires at least one argument');\n }\n\n let path : string | undefined;\n\n let data: Container | Validator | undefined;\n let dataIsContainer : boolean = false;\n\n let options: ContainerMountOptions = {};\n\n for (let i = 0; i < args.length; i++) {\n if (typeof args[i] === 'string') {\n path = args[i];\n continue;\n }\n\n if (typeof args[i] === 'function') {\n data = args[i];\n continue;\n }\n\n if (args[i] instanceof Container) {\n data = args[i];\n dataIsContainer = true;\n continue;\n }\n\n if (isObject(args[i])) {\n options = args[i];\n }\n }\n\n if (\n !dataIsContainer &&\n (typeof path === 'undefined' || path.length === 0)\n ) {\n throw new SyntaxError('Only a container can be mounted without a key.');\n }\n\n if (typeof data === 'undefined') {\n throw new SyntaxError('No container/validator could be extracted from the fn arguments.');\n }\n\n this.items.push({\n ...options,\n data,\n path,\n });\n }\n\n // ----------------------------------------------\n\n async run(\n data: Record<string, any> = {},\n options: ContainerRunOptions<T> = {},\n ): Promise<T> {\n const output: Record<string, any> = {};\n\n const errors: ValidupValidatorError[] = [];\n const errorKeys : string[] = [];\n\n let pathsToInclude : string[] | undefined;\n if (options.pathsToInclude) {\n pathsToInclude = options.pathsToInclude as string[];\n } else if (this.options.pathsToInclude) {\n pathsToInclude = this.options.pathsToInclude as string[];\n }\n\n let itemCount = 0;\n for (let i = 0; i < this.items.length; i++) {\n const item = this.items[i];\n\n if (!this.isItemGroupIncluded(item, options.group)) {\n continue;\n }\n\n let pathsCount = 0;\n\n let paths : string[];\n if (item.path) {\n paths = expandPropertyPath(data, item.path, []);\n } else {\n paths = [''];\n }\n\n for (let j = 0; j < paths.length; j++) {\n const path = paths[j];\n const pathAbsolute = this.mergePaths(options.path, paths[j]);\n\n let value : unknown;\n if (hasOwnProperty(output, path)) {\n value = output[path];\n } else {\n value = getPropertyPathValue(data, path);\n }\n\n if (\n typeof pathsToInclude !== 'undefined' &&\n pathsToInclude.indexOf(path) === -1\n ) {\n continue;\n }\n\n try {\n if (item.data instanceof Container) {\n const tmp = await item.data.run(\n isObject(value) ? value : {},\n {\n group: options.group,\n flat: true,\n path: pathAbsolute,\n pathsToInclude: options.pathsToInclude,\n // todo: extract defaults for container\n },\n );\n\n const tmpKeys = Object.keys(tmp);\n for (let k = 0; k < tmpKeys.length; k++) {\n output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];\n }\n } else {\n output[path] = await item.data({\n path,\n pathRaw: item.path ?? '',\n\n pathAbsolute,\n value,\n data,\n });\n }\n } catch (e) {\n if (e instanceof ValidupValidatorError) {\n errors.push(e);\n } else if (e instanceof ValidupNestedError) {\n errors.push(...e.children);\n } else {\n const error = new ValidupValidatorError({\n path,\n pathAbsolute,\n received: value,\n });\n\n if (e instanceof Error) {\n error.cause = e;\n error.message = e.message;\n }\n\n errors.push(error);\n }\n\n errorKeys.push(pathAbsolute);\n }\n\n pathsCount++;\n }\n\n if (pathsCount > 0) {\n itemCount++;\n }\n }\n\n if (this.options.oneOf) {\n if (errors.length === itemCount) {\n throw new ValidupNestedError({ message: buildErrorMessageForAttributes(errorKeys), children: errors });\n }\n } else if (errors.length > 0) {\n throw new ValidupNestedError({ message: buildErrorMessageForAttributes(errorKeys), children: errors });\n }\n\n if (options.defaults) {\n const defaultKeys = Object.keys(options.defaults);\n for (let i = 0; i < defaultKeys.length; i++) {\n if (\n !hasOwnProperty(output, defaultKeys[i]) ||\n typeof output[defaultKeys[i]] === 'undefined'\n ) {\n output[defaultKeys[i]] = options.defaults[defaultKeys[i] as unknown as ObjectPropertyPath<T>];\n }\n }\n }\n\n if (options.flat) {\n return output as T;\n }\n\n const temp : Record<string, any> = {};\n\n const keys = Object.keys(output);\n for (let i = 0; i < keys.length; i++) {\n setPropertyPathValue(temp, keys[i], output[keys[i]]);\n }\n\n return temp as T;\n }\n\n private isItemGroupIncluded(\n item: ContainerItem,\n group?: string,\n ) : boolean {\n if (group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.group) {\n if (Array.isArray(item.group)) {\n if (item.group.indexOf(GroupKey.WILDCARD) !== -1) {\n return true;\n }\n\n if (group && item.group.indexOf(group) !== -1) {\n return true;\n }\n } else {\n if (item.group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.group === group) {\n return true;\n }\n }\n\n return false;\n }\n\n return true;\n }\n\n private mergePaths(...args: (string | undefined)[]) {\n let output : string = '';\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (!arg || arg.length === 0) {\n continue;\n }\n\n if (arg.at(0) === '.') {\n output += arg;\n } else {\n output += output.length > 0 ? `.${arg}` : arg;\n }\n }\n\n return output;\n }\n\n protected initialize() : void {\n\n }\n}\n"],"names":["arrayToPropertyPath","parts","reduce","prev","segment","part","includes","test","buildErrorMessageForAttributes","input","names","Array","isArray","distinctArray","Object","keys","length","join","String","hasOwnProperty","obj","prop","prototype","call","isObject","rePropName","reEscapeChar","propertyPathToArray","result","charCodeAt","push","replace","match","number","quote","subString","getPropertyPathValue","data","path","temp","index","isIndex","Number","isNaN","parseInt","setPropertyPathValue","value","key","GroupKey","ValidupValidatorError","Error","constructor","options","message","pathAbsolute","code","received","expected","ValidupError","ValidupNestedError","addChild","child","children","expandPropertyPath","currPath","segments","rest","slice","flatMap","concat","nextPath","set","Set","Container","mount","args","SyntaxError","dataIsContainer","i","items","run","output","errors","errorKeys","pathsToInclude","itemCount","item","isItemGroupIncluded","group","pathsCount","paths","j","mergePaths","indexOf","tmp","flat","tmpKeys","k","pathRaw","e","error","cause","oneOf","defaults","defaultKeys","WILDCARD","arg","at","initialize"],"mappings":";;;;AAAA;;;;;;;;IAWO,SAASA,mBAAAA,CAAoBC,KAAwB,EAAA;AACxD,IAAA,OAAOA,KAAMC,CAAAA,MAAM,CAAC,CAACC,IAAMC,EAAAA,OAAAA,GAAAA;AACvB,QAAA,IAAIC,IAAO,GAAA,EAAA,CAAA;QACXD,OAAUA,GAAAA,OAAAA,KAAY,QAAQ,GAAMA,GAAAA,OAAAA,CAAAA;;QAGpC,IAAIA,OAAAA,CAAQE,QAAQ,CAAC,GAAM,CAAA,EAAA;;AAEvBD,YAAAA,IAAAA,GAAO,CAAC,EAAE,EAAED,OAAAA,CAAQ,EAAE,CAAC,CAAA;AAC3B,SAAA,MAAO,IAAI,OAAA,CAAQG,IAAI,CAACH,OAAU,CAAA,EAAA;;AAE9BC,YAAAA,IAAAA,GAAO,CAAC,CAAC,EAAED,OAA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A,CAAA;YAClC,MAAM4B,GAAAA,GAAM/B,IAAI,CAACG,CAAE,CAAA,CAAA;AACnB,YAAA,IAAI,CAAC4B,GAAAA,IAAOA,GAAI1F,CAAAA,MAAM,KAAK,CAAG,EAAA;AAC1B,gBAAA,SAAA;AACJ,aAAA;AAEA,YAAA,IAAI0F,GAAIC,CAAAA,EAAE,CAAC,CAAA,CAAA,KAAO,GAAK,EAAA;gBACnB1B,MAAUyB,IAAAA,GAAAA,CAAAA;aACP,MAAA;gBACHzB,MAAUA,IAAAA,MAAAA,CAAOjE,MAAM,GAAG,CAAA,GAAI,CAAC,CAAC,EAAE0F,GAAI,CAAA,CAAC,GAAGA,GAAAA,CAAAA;AAC9C,aAAA;AACJ,SAAA;QAEA,OAAOzB,MAAAA,CAAAA;AACX,KAAA;AAEU2B,IAAAA,UAAAA,GAAoB,EAE9B;;IAtRAzD,WAAYC,CAAAA,OAAAA,GAA+B,EAAE,CAAE;QAC3C,IAAI,CAACA,OAAO,GAAGA,OAAAA,CAAAA;QACf,IAAI,CAAC2B,KAAK,GAAG,EAAE,CAAA;AAEf,QAAA,IAAI,CAAC6B,UAAU,EAAA,CAAA;AACnB,KAAA;AAkRJ;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/helpers/error.ts","../src/constants.ts","../src/helpers/optional-value.ts","../src/errors/validator.ts","../src/errors/base.ts","../src/errors/nested.ts","../src/utils/has-own-property.ts","../src/utils/object.ts","../src/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { distinctArray } from 'smob';\n\nexport function buildErrorMessageForAttributes(input: (number | string)[] | Record<string, any>) {\n let names: string[];\n if (Array.isArray(input)) {\n names = distinctArray(input);\n } else {\n names = Object.keys(input);\n }\n\n if (names.length === 0) {\n return 'An unexpected error occurred.';\n }\n\n if (names.length > 1) {\n return `The attributes ${names.join(', ')} are invalid.`;\n }\n\n return `The attribute ${String(names[0])} is invalid.`;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum GroupKey {\n WILDCARD = '*',\n}\n\nexport enum OptionalValue {\n /**\n * value: undefined\n */\n UNDEFINED = 'undefined',\n /**\n * value: null & undefined\n */\n NULL = 'null',\n /**\n * value: empty string, false, 0\n */\n FALSY = 'falsy',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { OptionalValue } from '../constants';\n\n/**\n * Check if input value (type of) satisfies optional value type constraint.\n *\n * @param value\n * @param optionalValue\n */\nexport function isOptionalValue(\n value: unknown,\n optionalValue?: `${OptionalValue}`,\n) {\n const optionValueNormalized = optionalValue || OptionalValue.UNDEFINED;\n\n if (optionValueNormalized === OptionalValue.NULL) {\n return value === null;\n }\n\n if (optionValueNormalized === OptionalValue.UNDEFINED) {\n return typeof value === 'undefined';\n }\n\n return !value;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport type ValidupValidatorErrorOptions = {\n path: string,\n pathAbsolute?: string,\n message?: string,\n code?: string | null,\n received?: unknown,\n expected?: unknown\n};\n\nexport class ValidupValidatorError extends Error {\n readonly path: string;\n\n readonly pathAbsolute : string;\n\n readonly code?: string | null;\n\n readonly received?: unknown;\n\n readonly expected?: unknown;\n\n constructor(options: ValidupValidatorErrorOptions) {\n super(options.message);\n\n this.path = options.path;\n this.pathAbsolute = options.pathAbsolute ?? options.path;\n this.code = options.code;\n this.received = options.received;\n this.expected = options.expected;\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport class ValidupError extends Error {\n\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { ValidupValidatorError } from './validator';\nimport { ValidupError } from './base';\n\nexport type ValidupNestedErrorOptions = {\n children?: ValidupValidatorError[],\n message?: string\n};\n\nexport class ValidupNestedError extends ValidupError {\n children: ValidupValidatorError[];\n\n constructor(options: ValidupNestedErrorOptions = {}) {\n super(options.message || 'One or many attributes may be invalid.');\n\n this.children = options.children || [];\n }\n\n addChild(child: ValidupValidatorError) {\n this.children.push(child);\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(input: unknown) : input is Record<string, any> {\n return !!input &&\n typeof input === 'object' &&\n !Array.isArray(input);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { expandPath, getPathValue, setPathValue } from 'pathtrace';\nimport { GroupKey } from './constants';\nimport { ValidupNestedError, ValidupValidatorError } from './errors';\nimport { buildErrorMessageForAttributes, isOptionalValue } from './helpers';\nimport type {\n ContainerItem,\n ContainerMountOptions,\n ContainerOptions,\n ContainerRunOptions,\n ObjectPropertyPath,\n ObjectPropertyPathExtended,\n Validator,\n} from './types';\nimport { hasOwnProperty, isObject } from './utils';\n\nexport class Container<\n T extends Record<string, any> = Record<string, any>,\n> {\n protected options : ContainerOptions<T>;\n\n protected items : ContainerItem[];\n\n // ----------------------------------------------\n\n constructor(options: ContainerOptions<T> = {}) {\n this.options = options;\n this.items = [];\n\n this.initialize();\n }\n\n // ----------------------------------------------\n\n mount(container: Container) : void;\n\n mount(\n options: ContainerMountOptions,\n container: Container\n ): void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n data: Container | Validator\n ) : void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n options: ContainerMountOptions,\n data: Container | Validator\n ) : void;\n\n mount(...args: any[]) : void {\n if (args.length < 1) {\n throw new SyntaxError('The mount method requires at least one argument');\n }\n\n let path : string | undefined;\n\n let data: Container | Validator | undefined;\n let dataIsContainer : boolean = false;\n\n let options: ContainerMountOptions = {};\n\n for (let i = 0; i < args.length; i++) {\n if (typeof args[i] === 'string') {\n path = args[i];\n continue;\n }\n\n if (typeof args[i] === 'function') {\n data = args[i];\n continue;\n }\n\n if (args[i] instanceof Container) {\n data = args[i];\n dataIsContainer = true;\n continue;\n }\n\n if (isObject(args[i])) {\n options = args[i];\n }\n }\n\n if (\n !dataIsContainer &&\n (typeof path === 'undefined' || path.length === 0)\n ) {\n throw new SyntaxError('Only a container can be mounted without a key.');\n }\n\n if (typeof data === 'undefined') {\n throw new SyntaxError('No container/validator could be extracted from the fn arguments.');\n }\n\n this.items.push({\n ...options,\n data,\n path,\n });\n }\n\n // ----------------------------------------------\n\n async run(\n data: Record<string, any> = {},\n options: ContainerRunOptions<T> = {},\n ): Promise<T> {\n const output: Record<string, any> = {};\n\n const errors: ValidupValidatorError[] = [];\n const errorKeys : string[] = [];\n\n let pathsToInclude : string[] | undefined;\n if (options.pathsToInclude) {\n pathsToInclude = options.pathsToInclude as string[];\n } else if (this.options.pathsToInclude) {\n pathsToInclude = this.options.pathsToInclude as string[];\n }\n\n let itemCount = 0;\n for (let i = 0; i < this.items.length; i++) {\n const item = this.items[i];\n\n if (!this.isItemGroupIncluded(item, options.group)) {\n continue;\n }\n\n let pathsCount = 0;\n\n let paths : string[];\n if (item.path) {\n paths = expandPath(data, item.path);\n } else {\n paths = [''];\n }\n\n for (let j = 0; j < paths.length; j++) {\n const path = paths[j];\n const pathAbsolute = this.mergePaths(options.path, paths[j]);\n\n let value : unknown;\n if (hasOwnProperty(output, path)) {\n value = output[path];\n } else if (path.length > 0) {\n value = getPathValue(data, path);\n } else {\n value = data;\n }\n\n if (\n typeof pathsToInclude !== 'undefined' &&\n pathsToInclude.indexOf(path) === -1\n ) {\n continue;\n }\n\n try {\n if (item.data instanceof Container) {\n if (\n item.optional &&\n isOptionalValue(value, item.optionalValue)\n ) {\n if (item.optionalInclude) {\n output[path] = value;\n }\n } else {\n const tmp = await item.data.run(\n isObject(value) ? value : {},\n {\n group: options.group,\n flat: true,\n path: pathAbsolute,\n pathsToInclude: options.pathsToInclude,\n // todo: extract defaults for container\n },\n );\n\n const tmpKeys = Object.keys(tmp);\n for (let k = 0; k < tmpKeys.length; k++) {\n output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];\n }\n }\n } else {\n output[path] = await item.data({\n path,\n pathRaw: item.path ?? '',\n\n pathAbsolute,\n value,\n data,\n });\n }\n } catch (e) {\n if (e instanceof ValidupValidatorError) {\n errors.push(e);\n } else if (e instanceof ValidupNestedError) {\n errors.push(...e.children);\n } else {\n const error = new ValidupValidatorError({\n path,\n pathAbsolute,\n received: value,\n });\n\n if (e instanceof Error) {\n error.cause = e;\n error.message = e.message;\n }\n\n errors.push(error);\n }\n\n errorKeys.push(pathAbsolute);\n }\n\n pathsCount++;\n }\n\n if (pathsCount > 0) {\n itemCount++;\n }\n }\n\n if (this.options.oneOf) {\n if (errors.length === itemCount) {\n throw new ValidupNestedError({ message: buildErrorMessageForAttributes(errorKeys), children: errors });\n }\n } else if (errors.length > 0) {\n throw new ValidupNestedError({ message: buildErrorMessageForAttributes(errorKeys), children: errors });\n }\n\n if (options.defaults) {\n const defaultKeys = Object.keys(options.defaults);\n for (let i = 0; i < defaultKeys.length; i++) {\n if (\n !hasOwnProperty(output, defaultKeys[i]) ||\n typeof output[defaultKeys[i]] === 'undefined'\n ) {\n output[defaultKeys[i]] = options.defaults[defaultKeys[i] as unknown as ObjectPropertyPath<T>];\n }\n }\n }\n\n if (options.flat) {\n return output as T;\n }\n\n const temp : Record<string, any> = {};\n\n const keys = Object.keys(output);\n for (let i = 0; i < keys.length; i++) {\n setPathValue(temp, keys[i], output[keys[i]]);\n }\n\n return temp as T;\n }\n\n private isItemGroupIncluded(\n item: ContainerItem,\n group?: string,\n ) : boolean {\n if (group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.group) {\n if (Array.isArray(item.group)) {\n if (item.group.indexOf(GroupKey.WILDCARD) !== -1) {\n return true;\n }\n\n if (group && item.group.indexOf(group) !== -1) {\n return true;\n }\n } else {\n if (item.group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.group === group) {\n return true;\n }\n }\n\n return false;\n }\n\n return true;\n }\n\n private mergePaths(...args: (string | undefined)[]) {\n let output : string = '';\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (!arg || arg.length === 0) {\n continue;\n }\n\n if (arg.at(0) === '.') {\n output += arg;\n } else {\n output += output.length > 0 ? `.${arg}` : arg;\n }\n }\n\n return output;\n }\n\n protected initialize() : void {\n\n }\n}\n"],"names":["buildErrorMessageForAttributes","input","names","Array","isArray","distinctArray","Object","keys","length","join","String","GroupKey","OptionalValue","isOptionalValue","value","optionalValue","optionValueNormalized","UNDEFINED","NULL","ValidupValidatorError","Error","constructor","options","message","path","pathAbsolute","code","received","expected","ValidupError","ValidupNestedError","addChild","child","children","push","hasOwnProperty","obj","prop","prototype","call","isObject","Container","mount","args","SyntaxError","data","dataIsContainer","i","items","run","output","errors","errorKeys","pathsToInclude","itemCount","item","isItemGroupIncluded","group","pathsCount","paths","expandPath","j","mergePaths","getPathValue","indexOf","optional","optionalInclude","tmp","flat","tmpKeys","k","pathRaw","e","error","cause","oneOf","defaults","defaultKeys","temp","setPathValue","WILDCARD","arg","at","initialize"],"mappings":";;;;;AASO,S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,IAAOA,GAAIzE,CAAAA,MAAM,KAAK,CAAG,EAAA;AAC1B,gBAAA,SAAA;AACJ,aAAA;AAEA,YAAA,IAAIyE,GAAIC,CAAAA,EAAE,CAAC,CAAA,CAAA,KAAO,GAAK,EAAA;gBACnBhC,MAAU+B,IAAAA,GAAAA,CAAAA;aACP,MAAA;gBACH/B,MAAUA,IAAAA,MAAAA,CAAO1C,MAAM,GAAG,CAAA,GAAI,CAAC,CAAC,EAAEyE,GAAI,CAAA,CAAC,GAAGA,GAAAA,CAAAA;AAC9C,aAAA;AACJ,SAAA;QAEA,OAAO/B,MAAAA,CAAAA;AACX,KAAA;AAEUiC,IAAAA,UAAAA,GAAoB,EAE9B;;IAjSA9D,WAAYC,CAAAA,OAAAA,GAA+B,EAAE,CAAE;QAC3C,IAAI,CAACA,OAAO,GAAGA,OAAAA,CAAAA;QACf,IAAI,CAAC0B,KAAK,GAAG,EAAE,CAAA;AAEf,QAAA,IAAI,CAACmC,UAAU,EAAA,CAAA;AACnB,KAAA;AA6RJ;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,34 +1,5 @@
|
|
|
1
1
|
import { distinctArray } from 'smob';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright (c) 2024.
|
|
5
|
-
* Author Peter Placzek (tada5hi)
|
|
6
|
-
* For the full copyright and license information,
|
|
7
|
-
* view the LICENSE file that was distributed with this source code.
|
|
8
|
-
*/ /**
|
|
9
|
-
* @see https://github.com/express-validator/express-validator/blob/bec1dcbaa29002dcd21093ec84818c4671063b5d/src/field-selection.ts#L214
|
|
10
|
-
* @param parts
|
|
11
|
-
*/ function arrayToPropertyPath(parts) {
|
|
12
|
-
return parts.reduce((prev, segment)=>{
|
|
13
|
-
let part = '';
|
|
14
|
-
segment = segment === '\\*' ? '*' : segment;
|
|
15
|
-
// TODO: Handle brackets?
|
|
16
|
-
if (segment.includes('.')) {
|
|
17
|
-
// Special char key access
|
|
18
|
-
part = `["${segment}"]`;
|
|
19
|
-
} else if (/^\d+$/.test(segment)) {
|
|
20
|
-
// Index access
|
|
21
|
-
part = `[${segment}]`;
|
|
22
|
-
} else if (prev) {
|
|
23
|
-
// Object key access
|
|
24
|
-
part = `.${segment}`;
|
|
25
|
-
} else {
|
|
26
|
-
// Top level key
|
|
27
|
-
part = segment;
|
|
28
|
-
}
|
|
29
|
-
return prev + part;
|
|
30
|
-
}, '');
|
|
31
|
-
}
|
|
2
|
+
import { expandPath, getPathValue, setPathValue } from 'pathtrace';
|
|
32
3
|
|
|
33
4
|
function buildErrorMessageForAttributes(input) {
|
|
34
5
|
let names;
|
|
@@ -51,105 +22,39 @@ function buildErrorMessageForAttributes(input) {
|
|
|
51
22
|
* Author Peter Placzek (tada5hi)
|
|
52
23
|
* For the full copyright and license information,
|
|
53
24
|
* view the LICENSE file that was distributed with this source code.
|
|
54
|
-
*/
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
25
|
+
*/ var GroupKey;
|
|
26
|
+
(function(GroupKey) {
|
|
27
|
+
GroupKey["WILDCARD"] = "*";
|
|
28
|
+
})(GroupKey || (GroupKey = {}));
|
|
29
|
+
var OptionalValue;
|
|
30
|
+
(function(OptionalValue) {
|
|
31
|
+
/**
|
|
32
|
+
* value: undefined
|
|
33
|
+
*/ OptionalValue["UNDEFINED"] = "undefined";
|
|
34
|
+
/**
|
|
35
|
+
* value: null & undefined
|
|
36
|
+
*/ OptionalValue["NULL"] = "null";
|
|
37
|
+
/**
|
|
38
|
+
* value: empty string, false, 0
|
|
39
|
+
*/ OptionalValue["FALSY"] = "falsy";
|
|
40
|
+
})(OptionalValue || (OptionalValue = {}));
|
|
67
41
|
|
|
68
|
-
/*
|
|
69
|
-
* Copyright (c) 2024.
|
|
70
|
-
* Author Peter Placzek (tada5hi)
|
|
71
|
-
* For the full copyright and license information,
|
|
72
|
-
* view the LICENSE file that was distributed with this source code.
|
|
73
|
-
*/ /**
|
|
74
|
-
* Match property names within property paths.
|
|
75
|
-
*
|
|
76
|
-
* @see https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L146C7-L146C118
|
|
77
|
-
*/ const rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
|
78
|
-
/**
|
|
79
|
-
* Match backslashes in property paths.
|
|
80
|
-
*
|
|
81
|
-
* @see https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L168C1-L168C54
|
|
82
|
-
*/ const reEscapeChar = /\\(\\)?/g;
|
|
83
42
|
/**
|
|
84
|
-
*
|
|
43
|
+
* Check if input value (type of) satisfies optional value type constraint.
|
|
85
44
|
*
|
|
86
|
-
* @
|
|
87
|
-
* @param
|
|
88
|
-
*/ function
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
|
|
45
|
+
* @param value
|
|
46
|
+
* @param optionalValue
|
|
47
|
+
*/ function isOptionalValue(value, optionalValue) {
|
|
48
|
+
const optionValueNormalized = optionalValue || OptionalValue.UNDEFINED;
|
|
49
|
+
if (optionValueNormalized === OptionalValue.NULL) {
|
|
50
|
+
return value === null;
|
|
92
51
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return match;
|
|
96
|
-
});
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function getPropertyPathValue(data, path) {
|
|
101
|
-
const parts = propertyPathToArray(path);
|
|
102
|
-
let temp = data;
|
|
103
|
-
let index = 0;
|
|
104
|
-
while(index < parts.length){
|
|
105
|
-
if (!isObject(temp) && !Array.isArray(temp)) {
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
temp = temp[parts[index]];
|
|
109
|
-
index++;
|
|
110
|
-
}
|
|
111
|
-
return temp;
|
|
112
|
-
}
|
|
113
|
-
function isIndex(input) {
|
|
114
|
-
return typeof input === 'number' || !Number.isNaN(Number.parseInt(input, 10));
|
|
115
|
-
}
|
|
116
|
-
function setPropertyPathValue(data, path, value) {
|
|
117
|
-
const parts = Array.isArray(path) ? path : propertyPathToArray(path);
|
|
118
|
-
let temp = data;
|
|
119
|
-
let index = 0;
|
|
120
|
-
while(index < parts.length){
|
|
121
|
-
if (!Array.isArray(temp) && !isObject(temp)) {
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
const key = parts[index];
|
|
125
|
-
// [foo, '0']
|
|
126
|
-
if (typeof temp[key] === 'undefined') {
|
|
127
|
-
if (isIndex(key + 1)) {
|
|
128
|
-
temp[key] = [];
|
|
129
|
-
} else {
|
|
130
|
-
temp[key] = {};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (index === parts.length - 1) {
|
|
134
|
-
temp[key] = value;
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
index++;
|
|
138
|
-
temp = temp[key];
|
|
52
|
+
if (optionValueNormalized === OptionalValue.UNDEFINED) {
|
|
53
|
+
return typeof value === 'undefined';
|
|
139
54
|
}
|
|
140
|
-
return
|
|
55
|
+
return !value;
|
|
141
56
|
}
|
|
142
57
|
|
|
143
|
-
/*
|
|
144
|
-
* Copyright (c) 2024.
|
|
145
|
-
* Author Peter Placzek (tada5hi)
|
|
146
|
-
* For the full copyright and license information,
|
|
147
|
-
* view the LICENSE file that was distributed with this source code.
|
|
148
|
-
*/ var GroupKey;
|
|
149
|
-
(function(GroupKey) {
|
|
150
|
-
GroupKey["WILDCARD"] = "*";
|
|
151
|
-
})(GroupKey || (GroupKey = {}));
|
|
152
|
-
|
|
153
58
|
/*
|
|
154
59
|
* Copyright (c) 2024-2024.
|
|
155
60
|
* Author Peter Placzek (tada5hi)
|
|
@@ -184,47 +89,23 @@ class ValidupNestedError extends ValidupError {
|
|
|
184
89
|
}
|
|
185
90
|
}
|
|
186
91
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// there still are paths to traverse, but value is a primitive, stop
|
|
205
|
-
return [];
|
|
206
|
-
}
|
|
207
|
-
// Use a non-null value so that non-existing fields are still selected
|
|
208
|
-
data = data || {};
|
|
209
|
-
if (key === '*') {
|
|
210
|
-
return Object.keys(data).flatMap((key)=>expandPropertyPath(data[key], rest, currPath.concat(key)));
|
|
211
|
-
}
|
|
212
|
-
if (key === '**') {
|
|
213
|
-
return Object.keys(data).flatMap((key)=>{
|
|
214
|
-
const nextPath = currPath.concat(key);
|
|
215
|
-
const value = data[key];
|
|
216
|
-
const set = new Set([
|
|
217
|
-
// recursively find matching sub-paths
|
|
218
|
-
...expandPropertyPath(value, segments, nextPath),
|
|
219
|
-
// skip the first remaining segment, if it matches the current key
|
|
220
|
-
...rest[0] === key ? expandPropertyPath(value, rest.slice(1), nextPath) : []
|
|
221
|
-
]);
|
|
222
|
-
return [
|
|
223
|
-
...set
|
|
224
|
-
];
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
return expandPropertyPath(data[key], rest, currPath.concat(key));
|
|
92
|
+
/*
|
|
93
|
+
* Copyright (c) 2024.
|
|
94
|
+
* Author Peter Placzek (tada5hi)
|
|
95
|
+
* For the full copyright and license information,
|
|
96
|
+
* view the LICENSE file that was distributed with this source code.
|
|
97
|
+
*/ // eslint-disable-next-line @typescript-eslint/ban-types
|
|
98
|
+
function hasOwnProperty(obj, prop) {
|
|
99
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
* Copyright (c) 2024.
|
|
104
|
+
* Author Peter Placzek (tada5hi)
|
|
105
|
+
* For the full copyright and license information,
|
|
106
|
+
* view the LICENSE file that was distributed with this source code.
|
|
107
|
+
*/ function isObject(input) {
|
|
108
|
+
return !!input && typeof input === 'object' && !Array.isArray(input);
|
|
228
109
|
}
|
|
229
110
|
|
|
230
111
|
class Container {
|
|
@@ -286,7 +167,7 @@ class Container {
|
|
|
286
167
|
let pathsCount = 0;
|
|
287
168
|
let paths;
|
|
288
169
|
if (item.path) {
|
|
289
|
-
paths =
|
|
170
|
+
paths = expandPath(data, item.path);
|
|
290
171
|
} else {
|
|
291
172
|
paths = [
|
|
292
173
|
''
|
|
@@ -298,23 +179,31 @@ class Container {
|
|
|
298
179
|
let value;
|
|
299
180
|
if (hasOwnProperty(output, path)) {
|
|
300
181
|
value = output[path];
|
|
182
|
+
} else if (path.length > 0) {
|
|
183
|
+
value = getPathValue(data, path);
|
|
301
184
|
} else {
|
|
302
|
-
value =
|
|
185
|
+
value = data;
|
|
303
186
|
}
|
|
304
187
|
if (typeof pathsToInclude !== 'undefined' && pathsToInclude.indexOf(path) === -1) {
|
|
305
188
|
continue;
|
|
306
189
|
}
|
|
307
190
|
try {
|
|
308
191
|
if (item.data instanceof Container) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
192
|
+
if (item.optional && isOptionalValue(value, item.optionalValue)) {
|
|
193
|
+
if (item.optionalInclude) {
|
|
194
|
+
output[path] = value;
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
const tmp = await item.data.run(isObject(value) ? value : {}, {
|
|
198
|
+
group: options.group,
|
|
199
|
+
flat: true,
|
|
200
|
+
path: pathAbsolute,
|
|
201
|
+
pathsToInclude: options.pathsToInclude
|
|
202
|
+
});
|
|
203
|
+
const tmpKeys = Object.keys(tmp);
|
|
204
|
+
for(let k = 0; k < tmpKeys.length; k++){
|
|
205
|
+
output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];
|
|
206
|
+
}
|
|
318
207
|
}
|
|
319
208
|
} else {
|
|
320
209
|
output[path] = await item.data({
|
|
@@ -377,7 +266,7 @@ class Container {
|
|
|
377
266
|
const temp = {};
|
|
378
267
|
const keys = Object.keys(output);
|
|
379
268
|
for(let i = 0; i < keys.length; i++){
|
|
380
|
-
|
|
269
|
+
setPathValue(temp, keys[i], output[keys[i]]);
|
|
381
270
|
}
|
|
382
271
|
return temp;
|
|
383
272
|
}
|
|
@@ -429,5 +318,5 @@ class Container {
|
|
|
429
318
|
}
|
|
430
319
|
}
|
|
431
320
|
|
|
432
|
-
export { Container, GroupKey, ValidupError, ValidupNestedError, ValidupValidatorError,
|
|
321
|
+
export { Container, GroupKey, OptionalValue, ValidupError, ValidupNestedError, ValidupValidatorError, buildErrorMessageForAttributes, hasOwnProperty, isObject, isOptionalValue };
|
|
433
322
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/helpers/array-to-property-path.ts","../src/helpers/error.ts","../src/utils/has-own-property.ts","../src/utils/object.ts","../src/helpers/property-path-to-array.ts","../src/helpers/get-property-path-value.ts","../src/constants.ts","../src/errors/validator.ts","../src/errors/base.ts","../src/errors/nested.ts","../src/helpers/expand-property-path.ts","../src/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n/**\n * @see https://github.com/express-validator/express-validator/blob/bec1dcbaa29002dcd21093ec84818c4671063b5d/src/field-selection.ts#L214\n * @param parts\n */\nexport function arrayToPropertyPath(parts: readonly string[]) : string {\n return parts.reduce((prev, segment) => {\n let part = '';\n segment = segment === '\\\\*' ? '*' : segment;\n\n // TODO: Handle brackets?\n if (segment.includes('.')) {\n // Special char key access\n part = `[\"${segment}\"]`;\n } else if (/^\\d+$/.test(segment)) {\n // Index access\n part = `[${segment}]`;\n } else if (prev) {\n // Object key access\n part = `.${segment}`;\n } else {\n // Top level key\n part = segment;\n }\n\n return prev + part;\n }, '');\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { distinctArray } from 'smob';\n\nexport function buildErrorMessageForAttributes(input: (number | string)[] | Record<string, any>) {\n let names: string[];\n if (Array.isArray(input)) {\n names = distinctArray(input);\n } else {\n names = Object.keys(input);\n }\n\n if (names.length === 0) {\n return 'An unexpected error occurred.';\n }\n\n if (names.length > 1) {\n return `The attributes ${names.join(', ')} are invalid.`;\n }\n\n return `The attribute ${String(names[0])} is invalid.`;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(input: unknown) : input is Record<string, any> {\n return !!input &&\n typeof input === 'object' &&\n !Array.isArray(input);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n/**\n * Match property names within property paths.\n *\n * @see https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L146C7-L146C118\n */\nconst rePropName = /[^.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))/g;\n\n/**\n * Match backslashes in property paths.\n *\n * @see https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L168C1-L168C54\n */\nconst reEscapeChar = /\\\\(\\\\)?/g;\n\n/**\n * Convert string to property path array.\n *\n * @see https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L6735\n * @param segment\n */\nexport function propertyPathToArray(segment: string) : string[] {\n const result = [];\n if (segment.charCodeAt(0) === 46 /* . */) {\n result.push('');\n }\n segment.replace(rePropName, (match, number, quote, subString) => {\n result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));\n\n return match;\n });\n\n return result;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from '../utils';\nimport { propertyPathToArray } from './property-path-to-array';\n\nexport function getPropertyPathValue(\n data: Record<string, any>,\n path: string,\n): unknown {\n const parts = propertyPathToArray(path);\n\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n if (!isObject(temp) && !Array.isArray(temp)) {\n break;\n }\n\n temp = temp[parts[index]];\n index++;\n }\n\n return temp;\n}\n\nfunction isIndex(input: string | number) : input is number {\n return typeof input === 'number' || !Number.isNaN(Number.parseInt(input, 10));\n}\n\nexport function setPropertyPathValue(\n data: Record<string, any> | Record<string, any>[],\n path: string | string[],\n value: unknown,\n) {\n const parts = Array.isArray(path) ? path : propertyPathToArray(path);\n\n let temp = data;\n let index = 0;\n while (index < parts.length) {\n if (!Array.isArray(temp) && !isObject(temp)) {\n break;\n }\n\n const key = parts[index] as keyof typeof temp;\n // [foo, '0']\n if (typeof temp[key] === 'undefined') {\n if (isIndex(key + 1)) {\n (temp as Record<string, any>)[key] = [];\n } else {\n temp[key] = {};\n }\n }\n\n if (index === parts.length - 1) {\n temp[key] = value;\n break;\n }\n\n index++;\n temp = temp[key];\n }\n\n return data;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum GroupKey {\n WILDCARD = '*',\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport type ValidupValidatorErrorOptions = {\n path: string,\n pathAbsolute?: string,\n message?: string,\n code?: string | null,\n received?: unknown,\n expected?: unknown\n};\n\nexport class ValidupValidatorError extends Error {\n readonly path: string;\n\n readonly pathAbsolute : string;\n\n readonly code?: string | null;\n\n readonly received?: unknown;\n\n readonly expected?: unknown;\n\n constructor(options: ValidupValidatorErrorOptions) {\n super(options.message);\n\n this.path = options.path;\n this.pathAbsolute = options.pathAbsolute ?? options.path;\n this.code = options.code;\n this.received = options.received;\n this.expected = options.expected;\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport class ValidupError extends Error {\n\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { ValidupValidatorError } from './validator';\nimport { ValidupError } from './base';\n\nexport type ValidupNestedErrorOptions = {\n children?: ValidupValidatorError[],\n message?: string\n};\n\nexport class ValidupNestedError extends ValidupError {\n children: ValidupValidatorError[];\n\n constructor(options: ValidupNestedErrorOptions = {}) {\n super(options.message || 'One or many attributes may be invalid.');\n\n this.children = options.children || [];\n }\n\n addChild(child: ValidupValidatorError) {\n this.children.push(child);\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from '../utils';\nimport { arrayToPropertyPath } from './array-to-property-path';\nimport { propertyPathToArray } from './property-path-to-array';\n\nexport function expandPropertyPath(\n data: Record<string, any>,\n path: string | string[],\n currPath: readonly string[],\n): string[] {\n const segments = Array.isArray(path) ? path : propertyPathToArray(path);\n if (!segments.length) {\n // no more paths to traverse\n return [arrayToPropertyPath(currPath)];\n }\n\n const key = segments[0];\n const rest = segments.slice(1);\n\n if (\n typeof data !== 'undefined' &&\n data !== null &&\n !isObject(data) &&\n !Array.isArray(data)\n ) {\n if (key === '**' && !rest.length) {\n // globstar leaves are always selected\n return [arrayToPropertyPath(currPath)];\n }\n\n // there still are paths to traverse, but value is a primitive, stop\n return [];\n }\n\n // Use a non-null value so that non-existing fields are still selected\n data = data || {};\n\n if (key === '*') {\n return Object.keys(data)\n .flatMap((key) => expandPropertyPath(data[key], rest, currPath.concat(key)));\n }\n\n if (key === '**') {\n return Object.keys(data)\n .flatMap((key) => {\n const nextPath = currPath.concat(key);\n const value = data[key];\n const set = new Set([\n // recursively find matching sub-paths\n ...expandPropertyPath(value, segments, nextPath),\n // skip the first remaining segment, if it matches the current key\n ...(rest[0] === key ? expandPropertyPath(value, rest.slice(1), nextPath) : []),\n ]);\n\n return [...set];\n });\n }\n\n return expandPropertyPath(data[key], rest, currPath.concat(key));\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { GroupKey } from './constants';\nimport { ValidupNestedError, ValidupValidatorError } from './errors';\nimport { buildErrorMessageForAttributes, getPropertyPathValue, setPropertyPathValue } from './helpers';\nimport { expandPropertyPath } from './helpers/expand-property-path';\nimport type {\n ContainerItem,\n ContainerMountOptions,\n ContainerOptions,\n ContainerRunOptions,\n ObjectPropertyPath,\n ObjectPropertyPathExtended,\n Validator,\n} from './types';\nimport { hasOwnProperty, isObject } from './utils';\n\nexport class Container<\n T extends Record<string, any> = Record<string, any>,\n> {\n protected options : ContainerOptions<T>;\n\n protected items : ContainerItem[];\n\n // ----------------------------------------------\n\n constructor(options: ContainerOptions<T> = {}) {\n this.options = options;\n this.items = [];\n\n this.initialize();\n }\n\n // ----------------------------------------------\n\n mount(container: Container) : void;\n\n mount(\n options: ContainerMountOptions,\n container: Container\n ): void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n data: Container | Validator\n ) : void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n options: ContainerMountOptions,\n data: Container | Validator\n ) : void;\n\n mount(...args: any[]) : void {\n if (args.length < 1) {\n throw new SyntaxError('The mount method requires at least one argument');\n }\n\n let path : string | undefined;\n\n let data: Container | Validator | undefined;\n let dataIsContainer : boolean = false;\n\n let options: ContainerMountOptions = {};\n\n for (let i = 0; i < args.length; i++) {\n if (typeof args[i] === 'string') {\n path = args[i];\n continue;\n }\n\n if (typeof args[i] === 'function') {\n data = args[i];\n continue;\n }\n\n if (args[i] instanceof Container) {\n data = args[i];\n dataIsContainer = true;\n continue;\n }\n\n if (isObject(args[i])) {\n options = args[i];\n }\n }\n\n if (\n !dataIsContainer &&\n (typeof path === 'undefined' || path.length === 0)\n ) {\n throw new SyntaxError('Only a container can be mounted without a key.');\n }\n\n if (typeof data === 'undefined') {\n throw new SyntaxError('No container/validator could be extracted from the fn arguments.');\n }\n\n this.items.push({\n ...options,\n data,\n path,\n });\n }\n\n // ----------------------------------------------\n\n async run(\n data: Record<string, any> = {},\n options: ContainerRunOptions<T> = {},\n ): Promise<T> {\n const output: Record<string, any> = {};\n\n const errors: ValidupValidatorError[] = [];\n const errorKeys : string[] = [];\n\n let pathsToInclude : string[] | undefined;\n if (options.pathsToInclude) {\n pathsToInclude = options.pathsToInclude as string[];\n } else if (this.options.pathsToInclude) {\n pathsToInclude = this.options.pathsToInclude as string[];\n }\n\n let itemCount = 0;\n for (let i = 0; i < this.items.length; i++) {\n const item = this.items[i];\n\n if (!this.isItemGroupIncluded(item, options.group)) {\n continue;\n }\n\n let pathsCount = 0;\n\n let paths : string[];\n if (item.path) {\n paths = expandPropertyPath(data, item.path, []);\n } else {\n paths = [''];\n }\n\n for (let j = 0; j < paths.length; j++) {\n const path = paths[j];\n const pathAbsolute = this.mergePaths(options.path, paths[j]);\n\n let value : unknown;\n if (hasOwnProperty(output, path)) {\n value = output[path];\n } else {\n value = getPropertyPathValue(data, path);\n }\n\n if (\n typeof pathsToInclude !== 'undefined' &&\n pathsToInclude.indexOf(path) === -1\n ) {\n continue;\n }\n\n try {\n if (item.data instanceof Container) {\n const tmp = await item.data.run(\n isObject(value) ? value : {},\n {\n group: options.group,\n flat: true,\n path: pathAbsolute,\n pathsToInclude: options.pathsToInclude,\n // todo: extract defaults for container\n },\n );\n\n const tmpKeys = Object.keys(tmp);\n for (let k = 0; k < tmpKeys.length; k++) {\n output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];\n }\n } else {\n output[path] = await item.data({\n path,\n pathRaw: item.path ?? '',\n\n pathAbsolute,\n value,\n data,\n });\n }\n } catch (e) {\n if (e instanceof ValidupValidatorError) {\n errors.push(e);\n } else if (e instanceof ValidupNestedError) {\n errors.push(...e.children);\n } else {\n const error = new ValidupValidatorError({\n path,\n pathAbsolute,\n received: value,\n });\n\n if (e instanceof Error) {\n error.cause = e;\n error.message = e.message;\n }\n\n errors.push(error);\n }\n\n errorKeys.push(pathAbsolute);\n }\n\n pathsCount++;\n }\n\n if (pathsCount > 0) {\n itemCount++;\n }\n }\n\n if (this.options.oneOf) {\n if (errors.length === itemCount) {\n throw new ValidupNestedError({ message: buildErrorMessageForAttributes(errorKeys), children: errors });\n }\n } else if (errors.length > 0) {\n throw new ValidupNestedError({ message: buildErrorMessageForAttributes(errorKeys), children: errors });\n }\n\n if (options.defaults) {\n const defaultKeys = Object.keys(options.defaults);\n for (let i = 0; i < defaultKeys.length; i++) {\n if (\n !hasOwnProperty(output, defaultKeys[i]) ||\n typeof output[defaultKeys[i]] === 'undefined'\n ) {\n output[defaultKeys[i]] = options.defaults[defaultKeys[i] as unknown as ObjectPropertyPath<T>];\n }\n }\n }\n\n if (options.flat) {\n return output as T;\n }\n\n const temp : Record<string, any> = {};\n\n const keys = Object.keys(output);\n for (let i = 0; i < keys.length; i++) {\n setPropertyPathValue(temp, keys[i], output[keys[i]]);\n }\n\n return temp as T;\n }\n\n private isItemGroupIncluded(\n item: ContainerItem,\n group?: string,\n ) : boolean {\n if (group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.group) {\n if (Array.isArray(item.group)) {\n if (item.group.indexOf(GroupKey.WILDCARD) !== -1) {\n return true;\n }\n\n if (group && item.group.indexOf(group) !== -1) {\n return true;\n }\n } else {\n if (item.group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.group === group) {\n return true;\n }\n }\n\n return false;\n }\n\n return true;\n }\n\n private mergePaths(...args: (string | undefined)[]) {\n let output : string = '';\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (!arg || arg.length === 0) {\n continue;\n }\n\n if (arg.at(0) === '.') {\n output += arg;\n } else {\n output += output.length > 0 ? `.${arg}` : arg;\n }\n }\n\n return output;\n }\n\n protected initialize() : void {\n\n }\n}\n"],"names":["arrayToPropertyPath","parts","reduce","prev","segment","part","includes","test","buildErrorMessageForAttributes","input","names","Array","isArray","distinctArray","Object","keys","length","join","String","hasOwnProperty","obj","prop","prototype","call","isObject","rePropName","reEscapeChar","propertyPathToArray","result","charCodeAt","push","replace","match","number","quote","subString","getPropertyPathValue","data","path","temp","index","isIndex","Number","isNaN","parseInt","setPropertyPathValue","value","key","GroupKey","ValidupValidatorError","Error","constructor","options","message","pathAbsolute","code","received","expected","ValidupError","ValidupNestedError","addChild","child","children","expandPropertyPath","currPath","segments","rest","slice","flatMap","concat","nextPath","set","Set","Container","mount","args","SyntaxError","dataIsContainer","i","items","run","output","errors","errorKeys","pathsToInclude","itemCount","item","isItemGroupIncluded","group","pathsCount","paths","j","mergePaths","indexOf","tmp","flat","tmpKeys","k","pathRaw","e","error","cause","oneOf","defaults","defaultKeys","WILDCARD","arg","at","initialize"],"mappings":";;AAAA;;;;;;;;IAWO,SAASA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|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/helpers/error.ts","../src/constants.ts","../src/helpers/optional-value.ts","../src/errors/validator.ts","../src/errors/base.ts","../src/errors/nested.ts","../src/utils/has-own-property.ts","../src/utils/object.ts","../src/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { distinctArray } from 'smob';\n\nexport function buildErrorMessageForAttributes(input: (number | string)[] | Record<string, any>) {\n let names: string[];\n if (Array.isArray(input)) {\n names = distinctArray(input);\n } else {\n names = Object.keys(input);\n }\n\n if (names.length === 0) {\n return 'An unexpected error occurred.';\n }\n\n if (names.length > 1) {\n return `The attributes ${names.join(', ')} are invalid.`;\n }\n\n return `The attribute ${String(names[0])} is invalid.`;\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum GroupKey {\n WILDCARD = '*',\n}\n\nexport enum OptionalValue {\n /**\n * value: undefined\n */\n UNDEFINED = 'undefined',\n /**\n * value: null & undefined\n */\n NULL = 'null',\n /**\n * value: empty string, false, 0\n */\n FALSY = 'falsy',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { OptionalValue } from '../constants';\n\n/**\n * Check if input value (type of) satisfies optional value type constraint.\n *\n * @param value\n * @param optionalValue\n */\nexport function isOptionalValue(\n value: unknown,\n optionalValue?: `${OptionalValue}`,\n) {\n const optionValueNormalized = optionalValue || OptionalValue.UNDEFINED;\n\n if (optionValueNormalized === OptionalValue.NULL) {\n return value === null;\n }\n\n if (optionValueNormalized === OptionalValue.UNDEFINED) {\n return typeof value === 'undefined';\n }\n\n return !value;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport type ValidupValidatorErrorOptions = {\n path: string,\n pathAbsolute?: string,\n message?: string,\n code?: string | null,\n received?: unknown,\n expected?: unknown\n};\n\nexport class ValidupValidatorError extends Error {\n readonly path: string;\n\n readonly pathAbsolute : string;\n\n readonly code?: string | null;\n\n readonly received?: unknown;\n\n readonly expected?: unknown;\n\n constructor(options: ValidupValidatorErrorOptions) {\n super(options.message);\n\n this.path = options.path;\n this.pathAbsolute = options.pathAbsolute ?? options.path;\n this.code = options.code;\n this.received = options.received;\n this.expected = options.expected;\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport class ValidupError extends Error {\n\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { ValidupValidatorError } from './validator';\nimport { ValidupError } from './base';\n\nexport type ValidupNestedErrorOptions = {\n children?: ValidupValidatorError[],\n message?: string\n};\n\nexport class ValidupNestedError extends ValidupError {\n children: ValidupValidatorError[];\n\n constructor(options: ValidupNestedErrorOptions = {}) {\n super(options.message || 'One or many attributes may be invalid.');\n\n this.children = options.children || [];\n }\n\n addChild(child: ValidupValidatorError) {\n this.children.push(child);\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(input: unknown) : input is Record<string, any> {\n return !!input &&\n typeof input === 'object' &&\n !Array.isArray(input);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { expandPath, getPathValue, setPathValue } from 'pathtrace';\nimport { GroupKey } from './constants';\nimport { ValidupNestedError, ValidupValidatorError } from './errors';\nimport { buildErrorMessageForAttributes, isOptionalValue } from './helpers';\nimport type {\n ContainerItem,\n ContainerMountOptions,\n ContainerOptions,\n ContainerRunOptions,\n ObjectPropertyPath,\n ObjectPropertyPathExtended,\n Validator,\n} from './types';\nimport { hasOwnProperty, isObject } from './utils';\n\nexport class Container<\n T extends Record<string, any> = Record<string, any>,\n> {\n protected options : ContainerOptions<T>;\n\n protected items : ContainerItem[];\n\n // ----------------------------------------------\n\n constructor(options: ContainerOptions<T> = {}) {\n this.options = options;\n this.items = [];\n\n this.initialize();\n }\n\n // ----------------------------------------------\n\n mount(container: Container) : void;\n\n mount(\n options: ContainerMountOptions,\n container: Container\n ): void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n data: Container | Validator\n ) : void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n options: ContainerMountOptions,\n data: Container | Validator\n ) : void;\n\n mount(...args: any[]) : void {\n if (args.length < 1) {\n throw new SyntaxError('The mount method requires at least one argument');\n }\n\n let path : string | undefined;\n\n let data: Container | Validator | undefined;\n let dataIsContainer : boolean = false;\n\n let options: ContainerMountOptions = {};\n\n for (let i = 0; i < args.length; i++) {\n if (typeof args[i] === 'string') {\n path = args[i];\n continue;\n }\n\n if (typeof args[i] === 'function') {\n data = args[i];\n continue;\n }\n\n if (args[i] instanceof Container) {\n data = args[i];\n dataIsContainer = true;\n continue;\n }\n\n if (isObject(args[i])) {\n options = args[i];\n }\n }\n\n if (\n !dataIsContainer &&\n (typeof path === 'undefined' || path.length === 0)\n ) {\n throw new SyntaxError('Only a container can be mounted without a key.');\n }\n\n if (typeof data === 'undefined') {\n throw new SyntaxError('No container/validator could be extracted from the fn arguments.');\n }\n\n this.items.push({\n ...options,\n data,\n path,\n });\n }\n\n // ----------------------------------------------\n\n async run(\n data: Record<string, any> = {},\n options: ContainerRunOptions<T> = {},\n ): Promise<T> {\n const output: Record<string, any> = {};\n\n const errors: ValidupValidatorError[] = [];\n const errorKeys : string[] = [];\n\n let pathsToInclude : string[] | undefined;\n if (options.pathsToInclude) {\n pathsToInclude = options.pathsToInclude as string[];\n } else if (this.options.pathsToInclude) {\n pathsToInclude = this.options.pathsToInclude as string[];\n }\n\n let itemCount = 0;\n for (let i = 0; i < this.items.length; i++) {\n const item = this.items[i];\n\n if (!this.isItemGroupIncluded(item, options.group)) {\n continue;\n }\n\n let pathsCount = 0;\n\n let paths : string[];\n if (item.path) {\n paths = expandPath(data, item.path);\n } else {\n paths = [''];\n }\n\n for (let j = 0; j < paths.length; j++) {\n const path = paths[j];\n const pathAbsolute = this.mergePaths(options.path, paths[j]);\n\n let value : unknown;\n if (hasOwnProperty(output, path)) {\n value = output[path];\n } else if (path.length > 0) {\n value = getPathValue(data, path);\n } else {\n value = data;\n }\n\n if (\n typeof pathsToInclude !== 'undefined' &&\n pathsToInclude.indexOf(path) === -1\n ) {\n continue;\n }\n\n try {\n if (item.data instanceof Container) {\n if (\n item.optional &&\n isOptionalValue(value, item.optionalValue)\n ) {\n if (item.optionalInclude) {\n output[path] = value;\n }\n } else {\n const tmp = await item.data.run(\n isObject(value) ? value : {},\n {\n group: options.group,\n flat: true,\n path: pathAbsolute,\n pathsToInclude: options.pathsToInclude,\n // todo: extract defaults for container\n },\n );\n\n const tmpKeys = Object.keys(tmp);\n for (let k = 0; k < tmpKeys.length; k++) {\n output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];\n }\n }\n } else {\n output[path] = await item.data({\n path,\n pathRaw: item.path ?? '',\n\n pathAbsolute,\n value,\n data,\n });\n }\n } catch (e) {\n if (e instanceof ValidupValidatorError) {\n errors.push(e);\n } else if (e instanceof ValidupNestedError) {\n errors.push(...e.children);\n } else {\n const error = new ValidupValidatorError({\n path,\n pathAbsolute,\n received: value,\n });\n\n if (e instanceof Error) {\n error.cause = e;\n error.message = e.message;\n }\n\n errors.push(error);\n }\n\n errorKeys.push(pathAbsolute);\n }\n\n pathsCount++;\n }\n\n if (pathsCount > 0) {\n itemCount++;\n }\n }\n\n if (this.options.oneOf) {\n if (errors.length === itemCount) {\n throw new ValidupNestedError({ message: buildErrorMessageForAttributes(errorKeys), children: errors });\n }\n } else if (errors.length > 0) {\n throw new ValidupNestedError({ message: buildErrorMessageForAttributes(errorKeys), children: errors });\n }\n\n if (options.defaults) {\n const defaultKeys = Object.keys(options.defaults);\n for (let i = 0; i < defaultKeys.length; i++) {\n if (\n !hasOwnProperty(output, defaultKeys[i]) ||\n typeof output[defaultKeys[i]] === 'undefined'\n ) {\n output[defaultKeys[i]] = options.defaults[defaultKeys[i] as unknown as ObjectPropertyPath<T>];\n }\n }\n }\n\n if (options.flat) {\n return output as T;\n }\n\n const temp : Record<string, any> = {};\n\n const keys = Object.keys(output);\n for (let i = 0; i < keys.length; i++) {\n setPathValue(temp, keys[i], output[keys[i]]);\n }\n\n return temp as T;\n }\n\n private isItemGroupIncluded(\n item: ContainerItem,\n group?: string,\n ) : boolean {\n if (group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.group) {\n if (Array.isArray(item.group)) {\n if (item.group.indexOf(GroupKey.WILDCARD) !== -1) {\n return true;\n }\n\n if (group && item.group.indexOf(group) !== -1) {\n return true;\n }\n } else {\n if (item.group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.group === group) {\n return true;\n }\n }\n\n return false;\n }\n\n return true;\n }\n\n private mergePaths(...args: (string | undefined)[]) {\n let output : string = '';\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (!arg || arg.length === 0) {\n continue;\n }\n\n if (arg.at(0) === '.') {\n output += arg;\n } else {\n output += output.length > 0 ? `.${arg}` : arg;\n }\n }\n\n return output;\n }\n\n protected initialize() : void {\n\n }\n}\n"],"names":["buildErrorMessageForAttributes","input","names","Array","isArray","distinctArray","Object","keys","length","join","String","GroupKey","OptionalValue","isOptionalValue","value","optionalValue","optionValueNormalized","UNDEFINED","NULL","ValidupValidatorError","Error","constructor","options","message","path","pathAbsolute","code","received","expected","ValidupError","ValidupNestedError","addChild","child","children","push","hasOwnProperty","obj","prop","prototype","call","isObject","Container","mount","args","SyntaxError","data","dataIsContainer","i","items","run","output","errors","errorKeys","pathsToInclude","itemCount","item","isItemGroupIncluded","group","pathsCount","paths","expandPath","j","mergePaths","getPathValue","indexOf","optional","optionalInclude","tmp","flat","tmpKeys","k","pathRaw","e","error","cause","oneOf","defaults","defaultKeys","temp","setPathValue","WILDCARD","arg","at","initialize"],"mappings":";;;AASO,SAASA,+BAA+BC,KAAgD,EAAA;IAC3F,IAAIC,KAAAA,CAAAA;IACJ,IAAIC,KAAAA,CAAMC,OAAO,CAACH,KAAQ,CAAA,EAAA;AACtBC,QAAAA,KAAAA,GAAQG,aAAcJ,CAAAA,KAAAA,CAAAA,CAAAA;KACnB,MAAA;QACHC,KAAQI,GAAAA,MAAAA,CAAOC,IAAI,CAACN,KAAAA,CAAAA,CAAAA;AACxB,KAAA;IAEA,IAAIC,KAAAA,CAAMM,MAAM,KAAK,CAAG,EAAA;QACpB,OAAO,+BAAA,CAAA;AACX,KAAA;IAEA,IAAIN,KAAAA,CAAMM,MAAM,GAAG,CAAG,EAAA;QAClB,OAAO,CAAC,eAAe,EAAEN,KAAAA,CAAMO,IAAI,CAAC,IAAA,CAAA,CAAM,aAAa,CAAC,CAAA;AAC5D,KAAA;IAEA,OAAO,CAAC,cAAc,EAAEC,MAAAA,CAAOR,KAAK,CAAC,CAAA,CAAE,CAAE,CAAA,YAAY,CAAC,CAAA;AAC1D;;AC1BA;;;;;AAKC,IAAA,IAAA,SAAA;AAEWS,CAAAA,SAAAA,QAAAA,EAAAA;;GAAAA,QAAAA,KAAAA,QAAAA,GAAAA,EAAAA,CAAAA,CAAAA,CA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EA,IAAIzB,IAAAA,CAAKE,KAAK,KAAKA,KAAO,EAAA;oBACtB,OAAO,IAAA,CAAA;AACX,iBAAA;AACJ,aAAA;YAEA,OAAO,KAAA,CAAA;AACX,SAAA;QAEA,OAAO,IAAA,CAAA;AACX,KAAA;IAEQK,UAAW,CAAA,GAAGnB,IAA4B,EAAE;AAChD,QAAA,IAAIO,MAAkB,GAAA,EAAA,CAAA;AAEtB,QAAA,IAAK,IAAIH,CAAI,GAAA,CAAA,EAAGA,IAAIJ,IAAKnC,CAAAA,MAAM,EAAEuC,CAAK,EAAA,CAAA;YAClC,MAAMkC,GAAAA,GAAMtC,IAAI,CAACI,CAAE,CAAA,CAAA;AACnB,YAAA,IAAI,CAACkC,GAAAA,IAAOA,GAAIzE,CAAAA,MAAM,KAAK,CAAG,EAAA;AAC1B,gBAAA,SAAA;AACJ,aAAA;AAEA,YAAA,IAAIyE,GAAIC,CAAAA,EAAE,CAAC,CAAA,CAAA,KAAO,GAAK,EAAA;gBACnBhC,MAAU+B,IAAAA,GAAAA,CAAAA;aACP,MAAA;gBACH/B,MAAUA,IAAAA,MAAAA,CAAO1C,MAAM,GAAG,CAAA,GAAI,CAAC,CAAC,EAAEyE,GAAI,CAAA,CAAC,GAAGA,GAAAA,CAAAA;AAC9C,aAAA;AACJ,SAAA;QAEA,OAAO/B,MAAAA,CAAAA;AACX,KAAA;AAEUiC,IAAAA,UAAAA,GAAoB,EAE9B;;IAjSA9D,WAAYC,CAAAA,OAAAA,GAA+B,EAAE,CAAE;QAC3C,IAAI,CAACA,OAAO,GAAGA,OAAAA,CAAAA;QACf,IAAI,CAAC0B,KAAK,GAAG,EAAE,CAAA;AAEf,QAAA,IAAI,CAACmC,UAAU,EAAA,CAAA;AACnB,KAAA;AA6RJ;;;;"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OptionalValue } from './constants';
|
|
1
2
|
import type { Container } from './module';
|
|
2
3
|
export type ObjectLiteral = Record<string | number, any>;
|
|
3
4
|
export type ContainerOptions<T> = {
|
|
@@ -62,6 +63,9 @@ export type ValidatorContext = {
|
|
|
62
63
|
};
|
|
63
64
|
export type Validator = (ctx: ValidatorContext) => Promise<unknown> | unknown;
|
|
64
65
|
export type ContainerMountOptions = {
|
|
66
|
+
/**
|
|
67
|
+
* Group(s) to execute.
|
|
68
|
+
*/
|
|
65
69
|
group?: string | string[];
|
|
66
70
|
/**
|
|
67
71
|
* Limit mounted paths on execution.
|
|
@@ -69,6 +73,25 @@ export type ContainerMountOptions = {
|
|
|
69
73
|
* be considered for execution.
|
|
70
74
|
*/
|
|
71
75
|
pathsToInclude?: string[];
|
|
76
|
+
/**
|
|
77
|
+
* Specify if the mounted container has to be evaluated successfully.
|
|
78
|
+
*
|
|
79
|
+
* default: false
|
|
80
|
+
*/
|
|
81
|
+
optional?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Which values are considered optional.
|
|
84
|
+
* An optional value won't be passed to the underlying container/validator.
|
|
85
|
+
*
|
|
86
|
+
* default: 'undefined'
|
|
87
|
+
*/
|
|
88
|
+
optionalValue?: `${OptionalValue}`;
|
|
89
|
+
/**
|
|
90
|
+
* Include optional value as property in output.
|
|
91
|
+
*
|
|
92
|
+
* default: false
|
|
93
|
+
*/
|
|
94
|
+
optionalInclude?: boolean;
|
|
72
95
|
};
|
|
73
96
|
export type ContainerItem = ContainerMountOptions & {
|
|
74
97
|
path?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "validup",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "A validation library.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Peter Placzek",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"keywords": [],
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"pathtrace": "^1.0.0",
|
|
43
44
|
"smob": "^1.5.0"
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function expandPropertyPath(data: Record<string, any>, path: string | string[], currPath: readonly string[]): string[];
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export declare function getPropertyPathValue(data: Record<string, any>, path: string): unknown;
|
|
2
|
-
export declare function setPropertyPathValue(data: Record<string, any> | Record<string, any>[], path: string | string[], value: unknown): Record<string, any> | Record<string, any>[];
|