@thisisagile/easy 8.8.0 → 8.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -14,4 +14,6 @@ export declare const lt: (limit: number, message?: Text | undefined) => Property
|
|
|
14
14
|
export declare const lte: (limit: number, message?: Text | undefined) => PropertyDecorator;
|
|
15
15
|
export declare const past: (message?: Text | undefined) => PropertyDecorator;
|
|
16
16
|
export declare const future: (message?: Text | undefined) => PropertyDecorator;
|
|
17
|
+
export declare const minLength: (length: number, message?: Text | undefined) => PropertyDecorator;
|
|
18
|
+
export declare const maxLength: (length: number, message?: Text | undefined) => PropertyDecorator;
|
|
17
19
|
export declare const rule: (message?: Text | undefined) => PropertyDecorator;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rule = exports.future = exports.past = exports.lte = exports.lt = exports.gte = exports.gt = exports.inList = exports.includes = exports.optional = exports.valid = exports.notEmpty = exports.required = exports.defined = exports.constraint = void 0;
|
|
3
|
+
exports.rule = exports.maxLength = exports.minLength = exports.future = exports.past = exports.lte = exports.lt = exports.gte = exports.gt = exports.inList = exports.includes = exports.optional = exports.valid = exports.notEmpty = exports.required = exports.defined = exports.constraint = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const Validate_1 = require("./Validate");
|
|
6
6
|
const constraint = (c, message) => (subject, property) => {
|
|
@@ -36,6 +36,16 @@ const past = (message) => (0, exports.constraint)(v => (0, types_1.inPast)(v), m
|
|
|
36
36
|
exports.past = past;
|
|
37
37
|
const future = (message) => (0, exports.constraint)(v => (0, types_1.inFuture)(v), message ?? 'Value {actual} must lay in the future.');
|
|
38
38
|
exports.future = future;
|
|
39
|
+
const minLength = (length, message) => (0, exports.constraint)(v => (0, types_1.tryTo)(() => v)
|
|
40
|
+
.is.defined()
|
|
41
|
+
.map(v => (0, types_1.text)(v).toString().length >= length)
|
|
42
|
+
.orElse(true), message ?? `Value {actual} must be at least '${length}' characters long.`);
|
|
43
|
+
exports.minLength = minLength;
|
|
44
|
+
const maxLength = (length, message) => (0, exports.constraint)(v => (0, types_1.tryTo)(() => v)
|
|
45
|
+
.is.defined()
|
|
46
|
+
.map(v => (0, types_1.text)(v).toString().length <= length)
|
|
47
|
+
.orElse(true), message ?? `Value {actual} cannot be longer than '${length}' characters.`);
|
|
48
|
+
exports.maxLength = maxLength;
|
|
39
49
|
const rule = (message) => (0, exports.constraint)(v => ((0, types_1.isFunction)(v) ? v() : false), message ?? `Value {actual} must be true`);
|
|
40
50
|
exports.rule = rule;
|
|
41
51
|
//# sourceMappingURL=Contraints.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Contraints.js","sourceRoot":"","sources":["../../src/validation/Contraints.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"Contraints.js","sourceRoot":"","sources":["../../src/validation/Contraints.ts"],"names":[],"mappings":";;;AAAA,oCAAqJ;AACrJ,yCAAiD;AAI1C,MAAM,UAAU,GACrB,CAAI,CAAa,EAAE,OAAa,EAAqB,EAAE,CACvD,CAAC,OAAgB,EAAE,QAAyB,EAAQ,EAAE;IACpD,MAAM,EAAE,GAAG,IAAA,YAAI,EAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAkB,YAAY,CAAC,IAAI,IAAA,cAAM,GAAa,CAAC;IACtG,IAAA,YAAI,EAAC,OAAO,CAAC;SACV,QAAQ,CAAC,QAAQ,CAAC;SAClB,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAC3E,CAAC,CAAC;AAPS,QAAA,UAAU,cAOnB;AAEG,MAAM,OAAO,GAAG,CAAC,OAAc,EAAqB,EAAE,CAAC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EAAwB,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,OAAO,IAAI,6BAA6B,CAAC,CAAC;AADrG,QAAA,IAAI,QACiG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.9.0",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@thisisagile/easy-test": "8.
|
|
34
|
+
"@thisisagile/easy-test": "8.9.0",
|
|
35
35
|
"@types/form-urlencoded": "^4.4.0",
|
|
36
36
|
"@types/jsonwebtoken": "^8.5.6",
|
|
37
37
|
"@types/validator": "^13.7.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Func, inFuture, inPast, isDefined, isFunction, isIn, isNotEmpty, isString, List, meta, Results, Text, toList } from '../types';
|
|
1
|
+
import { Func, inFuture, inPast, isDefined, isFunction, isIn, isNotEmpty, isString, List, meta, Results, text, Text, toList, tryTo } from '../types';
|
|
2
2
|
import { validate, Validator } from './Validate';
|
|
3
3
|
|
|
4
4
|
export type Constraint = Func<boolean | Results, any>;
|
|
@@ -43,5 +43,25 @@ export const past = (message?: Text): PropertyDecorator => constraint(v => inPas
|
|
|
43
43
|
|
|
44
44
|
export const future = (message?: Text): PropertyDecorator => constraint(v => inFuture(v), message ?? 'Value {actual} must lay in the future.');
|
|
45
45
|
|
|
46
|
+
export const minLength = (length: number, message?: Text): PropertyDecorator =>
|
|
47
|
+
constraint(
|
|
48
|
+
v =>
|
|
49
|
+
tryTo(() => v)
|
|
50
|
+
.is.defined()
|
|
51
|
+
.map(v => text(v).toString().length >= length)
|
|
52
|
+
.orElse(true) as boolean,
|
|
53
|
+
message ?? `Value {actual} must be at least '${length}' characters long.`
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export const maxLength = (length: number, message?: Text): PropertyDecorator =>
|
|
57
|
+
constraint(
|
|
58
|
+
v =>
|
|
59
|
+
tryTo(() => v)
|
|
60
|
+
.is.defined()
|
|
61
|
+
.map(v => text(v).toString().length <= length)
|
|
62
|
+
.orElse(true) as boolean,
|
|
63
|
+
message ?? `Value {actual} cannot be longer than '${length}' characters.`
|
|
64
|
+
);
|
|
65
|
+
|
|
46
66
|
export const rule = (message?: Text): PropertyDecorator =>
|
|
47
67
|
constraint(v => (isFunction(v) ? (v() as boolean | Results) : false), message ?? `Value {actual} must be true`);
|