@dwtechs/antity 0.17.0 → 0.18.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.md +1 -1
- package/dist/antity.js +21 -20
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
[](https://opensource.org/licenses/MIT)
|
|
3
3
|
[](https://www.npmjs.com/package/@dwtechs/antity)
|
|
4
4
|
[](https://www.npmjs.com/package/@dwtechs/antity)
|
|
5
|
-

|
|
6
6
|
|
|
7
7
|
- [Synopsis](#synopsis)
|
|
8
8
|
- [Support](#support)
|
package/dist/antity.js
CHANGED
|
@@ -24,8 +24,9 @@ SOFTWARE.
|
|
|
24
24
|
https://github.com/DWTechs/Antity.js
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
import { isBoolean, isStringOfLength, isValidNumber, isValidInteger, isValidFloat, isEven, isOdd, isPositive, isNegative, isPowerOfTwo, isAscii, isArrayOfLength,
|
|
27
|
+
import { isBoolean, isStringOfLength, isValidNumber, isValidInteger, isValidFloat, isEven, isOdd, isPositive, isNegative, isPowerOfTwo, isAscii, isArrayOfLength, isEmail, isRegex, isJson, isJWT, isSymbol, isIpAddress, isSlug, isHexadecimal, isValidDate, isValidTimestamp, isFunction, isHtmlElement, isHtmlEventAttribute, isNode, isObject, isAnsiEscapeCode, isLocale, isTimeZone, isString, isProperty, isArray, isIn, isDate, isNumber, isInteger, isNil } from '@dwtechs/checkard';
|
|
28
28
|
import { log } from '@dwtechs/winstan';
|
|
29
|
+
import { isValidPassword } from '@dwtechs/passken';
|
|
29
30
|
|
|
30
31
|
const LOGS_PREFIX = "Antity: ";
|
|
31
32
|
const METHODS = ["PATCH", "PUT", "POST"];
|
|
@@ -77,12 +78,12 @@ const Types = {
|
|
|
77
78
|
password: {
|
|
78
79
|
validate: (v, min, max, _typeCheck) => {
|
|
79
80
|
const o = {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
minLen: min || PWD_MIN_LENGTH,
|
|
82
|
+
maxLen: max || PWD_MAX_LENGTH,
|
|
83
|
+
lcase: PWD_LOWERCASE,
|
|
84
|
+
ucase: PWD_UPPERCASE,
|
|
85
|
+
num: PWD_NUMBERS,
|
|
86
|
+
sym: PWD_SYMBOLS,
|
|
86
87
|
};
|
|
87
88
|
return isValidPassword(v, o, true);
|
|
88
89
|
}
|
|
@@ -211,12 +212,10 @@ function trim(v) {
|
|
|
211
212
|
return v.trim();
|
|
212
213
|
if (isObject(v, true)) {
|
|
213
214
|
const obj = v;
|
|
214
|
-
for (const k
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
obj[k] = o.trim();
|
|
219
|
-
}
|
|
215
|
+
for (const k of Object.keys(obj)) {
|
|
216
|
+
const o = obj[k];
|
|
217
|
+
if (isString(o, "!0", null))
|
|
218
|
+
obj[k] = o.trim();
|
|
220
219
|
}
|
|
221
220
|
}
|
|
222
221
|
return v;
|
|
@@ -281,20 +280,27 @@ function validate(record, properties, method) {
|
|
|
281
280
|
return null;
|
|
282
281
|
}
|
|
283
282
|
|
|
283
|
+
const STANDARD_PROP_KEYS = new Set(['key', 'type', 'min', 'max', 'isPrivate', 'requiredFor', 'isTypeChecked', 'sanitizer', 'normalizer', 'validator']);
|
|
284
284
|
class Entity {
|
|
285
285
|
_name;
|
|
286
286
|
_privateProps;
|
|
287
287
|
_properties;
|
|
288
|
+
_propsByMethod;
|
|
288
289
|
constructor(name, properties) {
|
|
289
290
|
this._name = name;
|
|
290
291
|
this._properties = [];
|
|
291
292
|
this._privateProps = [];
|
|
293
|
+
this._propsByMethod = new Map(METHODS.map(m => [m, []]));
|
|
292
294
|
for (const p of properties) {
|
|
293
295
|
const prop = new Property(p.key, p.type, p.min, p.max, p.isPrivate, p.requiredFor, p.isTypeChecked, p.sanitizer, p.normalizer, p.validator);
|
|
294
|
-
Object.
|
|
296
|
+
for (const k of Object.keys(p))
|
|
297
|
+
if (!STANDARD_PROP_KEYS.has(k))
|
|
298
|
+
prop[k] = p[k];
|
|
295
299
|
this._properties.push(prop);
|
|
296
300
|
if (prop.isPrivate)
|
|
297
301
|
this._privateProps.push(prop.key);
|
|
302
|
+
for (const m of prop.requiredFor)
|
|
303
|
+
this._propsByMethod.get(m)?.push(prop);
|
|
298
304
|
}
|
|
299
305
|
}
|
|
300
306
|
get name() {
|
|
@@ -315,12 +321,7 @@ class Entity {
|
|
|
315
321
|
return this.properties.find(p => p.key === key);
|
|
316
322
|
}
|
|
317
323
|
getPropsByMethod(method) {
|
|
318
|
-
|
|
319
|
-
for (const p of this.properties) {
|
|
320
|
-
if (p.requiredFor.includes(method))
|
|
321
|
-
props.push(p);
|
|
322
|
-
}
|
|
323
|
-
return props;
|
|
324
|
+
return this._propsByMethod.get(method) ?? [];
|
|
324
325
|
}
|
|
325
326
|
normalizeArray = (req, _res, next) => {
|
|
326
327
|
log.debug(`normalizeArray ${this.name}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dwtechs/antity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Open source library for easy entity management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"entities"
|
|
@@ -34,9 +34,10 @@
|
|
|
34
34
|
"node": ">= 22"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@dwtechs/checkard": "3.6.
|
|
37
|
+
"@dwtechs/checkard": "3.6.1",
|
|
38
|
+
"@dwtechs/passken": "0.6.1",
|
|
38
39
|
"@dwtechs/sparray": "0.2.1",
|
|
39
|
-
"@dwtechs/winstan": "0.7.
|
|
40
|
+
"@dwtechs/winstan": "0.7.1"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@babel/core": "7.26.0",
|