@thisisagile/easy 15.12.13 → 15.13.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.
@@ -8,6 +8,7 @@ export declare const valid: () => PropertyDecorator;
8
8
  export declare const optional: () => PropertyDecorator;
9
9
  export declare const includes: (sub: string, message?: string) => PropertyDecorator;
10
10
  export declare const inList: (values: unknown[], message?: Text) => PropertyDecorator;
11
+ export declare const inOptionalList: (values: unknown[], message?: Text) => PropertyDecorator;
11
12
  export declare const gt: (limit: number, message?: Text) => PropertyDecorator;
12
13
  export declare const gte: (limit: number, message?: Text) => PropertyDecorator;
13
14
  export declare const lt: (limit: number, message?: Text) => PropertyDecorator;
@@ -24,6 +24,7 @@ __export(Contraints_exports, {
24
24
  gt: () => gt,
25
25
  gte: () => gte,
26
26
  inList: () => inList,
27
+ inOptionalList: () => inOptionalList,
27
28
  includes: () => includes,
28
29
  lt: () => lt,
29
30
  lte: () => lte,
@@ -50,6 +51,7 @@ const valid = () => constraint((v) => (0, import_Validate.validate)(v), "");
50
51
  const optional = () => constraint((v) => !(0, import_types.isDefined)(v) || (0, import_Validate.validate)(v), "");
51
52
  const includes = (sub, message) => constraint((s) => (0, import_types.isDefined)(s) && (0, import_types.isString)(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);
52
53
  const inList = (values, message) => constraint((v) => (0, import_types.isDefined)(v) && (0, import_types.isIn)(v, values), message ?? "Value {actual} must appear in list.");
54
+ const inOptionalList = (values, message) => constraint((v) => !(0, import_types.isDefined)(v) || (0, import_types.isIn)(v, values), message ?? "Value {actual} must appear in list.");
53
55
  const gt = (limit, message) => constraint((v) => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);
54
56
  const gte = (limit, message) => constraint((v) => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);
55
57
  const lt = (limit, message) => constraint((v) => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);
@@ -73,6 +75,7 @@ const rule = (message) => constraint((v) => (0, import_types.isFunction)(v) ? v(
73
75
  gt,
74
76
  gte,
75
77
  inList,
78
+ inOptionalList,
76
79
  includes,
77
80
  lt,
78
81
  lte,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/validation/Contraints.ts"],"sourcesContent":["import { Func, inFuture, inPast, isBoolean, isDefined, isFunction, isIn, isNotEmpty, isString, List, meta, Results, text, Text, toList, tryTo } from '../types';\nimport { validate, Validator } from './Validate';\n\nexport type Constraint = Func<boolean | Results, any>;\n\nexport const constraint =\n <T>(c: Constraint, message: Text): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n const cs = meta(subject).property(property).get<List<Validator>>('constraint') ?? toList<Validator>();\n meta(subject)\n .property(property)\n .set('constraint', cs.add({ property, constraint: c, text: message }));\n };\n\nexport const defined = (message?: Text): PropertyDecorator => constraint(v => isDefined(v), message ?? 'Property {property} must be defined.');\n\nexport const required = (message?: Text): PropertyDecorator =>\n constraint(v => isNotEmpty(v), message ?? 'Property {property} is required, and may not be empty.');\n\nexport const notEmpty = (message?: Text): PropertyDecorator => constraint(v => isNotEmpty(v), message ?? 'Property {property} may not be empty.');\n\nexport const valid = (): PropertyDecorator => constraint(v => validate(v), '');\n\nexport const optional = (): PropertyDecorator => constraint(v => !isDefined(v) || validate(v), '');\n\nexport const includes = (sub: string, message?: string): PropertyDecorator =>\n constraint(s => isDefined(s) && isString(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);\n\nexport const inList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);\n\nexport const gte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);\n\nexport const lt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);\n\nexport const lte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v <= limit, message ?? `Value {actual} must be smaller than or equal to ${limit}.`);\n\nexport const past = (message?: Text): PropertyDecorator => constraint(v => inPast(v), message ?? 'Value {actual} must lay in the past.');\n\nexport const future = (message?: Text): PropertyDecorator => constraint(v => inFuture(v), message ?? 'Value {actual} must lay in the future.');\n\nexport const minLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length >= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} must be at least '${length}' characters long.`\n );\n\nexport const maxLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length <= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} cannot be longer than '${length}' characters.`\n );\n\nexport const rule = (message?: Text): PropertyDecorator =>\n constraint(v => (isFunction(v) ? (v() as boolean | Results) : isBoolean(v) ? v : false), message ?? `Value {actual} must be true`);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqJ;AACrJ,sBAAoC;AAI7B,MAAM,aACX,CAAI,GAAe,YACnB,CAAC,SAAkB,aAAoC;AACrD,QAAM,SAAK,mBAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAqB,YAAY,SAAK,qBAAkB;AACpG,yBAAK,OAAO,EACT,SAAS,QAAQ,EACjB,IAAI,cAAc,GAAG,IAAI,EAAE,UAAU,YAAY,GAAG,MAAM,QAAQ,CAAC,CAAC;AACzE;AAEK,MAAM,UAAU,CAAC,YAAsC,WAAW,WAAK,wBAAU,CAAC,GAAG,WAAW,sCAAsC;AAEtI,MAAM,WAAW,CAAC,YACvB,WAAW,WAAK,yBAA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;AACvD;AAEK,MAAM,YAAY,CAAC,QAAgB,YACxC;AAAA,EACE,WACE,oBAAM,MAAM,CAAC,EACV,GAAG,QAAQ,EACX,IAAI,CAAAA,WAAK,mBAAKA,EAAC,EAAE,SAAS,EAAE,UAAU,MAAM,EAC5C,OAAO,IAAI;AAAA,EAChB,WAAW,yCAAyC,MAAM;AAC5D;AAEK,MAAM,OAAO,CAAC,YACnB,WAAW,WAAM,yBAAW,CAAC,IAAK,EAAE,QAA0B,wBAAU,CAAC,IAAI,IAAI,OAAQ,WAAW,6BAA6B;","names":["v"]}
1
+ {"version":3,"sources":["../../src/validation/Contraints.ts"],"sourcesContent":["import { Func, inFuture, inPast, isBoolean, isDefined, isFunction, isIn, isNotEmpty, isString, List, meta, Results, text, Text, toList, tryTo } from '../types';\nimport { validate, Validator } from './Validate';\n\nexport type Constraint = Func<boolean | Results, any>;\n\nexport const constraint =\n <T>(c: Constraint, message: Text): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n const cs = meta(subject).property(property).get<List<Validator>>('constraint') ?? toList<Validator>();\n meta(subject)\n .property(property)\n .set('constraint', cs.add({ property, constraint: c, text: message }));\n };\n\nexport const defined = (message?: Text): PropertyDecorator => constraint(v => isDefined(v), message ?? 'Property {property} must be defined.');\n\nexport const required = (message?: Text): PropertyDecorator =>\n constraint(v => isNotEmpty(v), message ?? 'Property {property} is required, and may not be empty.');\n\nexport const notEmpty = (message?: Text): PropertyDecorator => constraint(v => isNotEmpty(v), message ?? 'Property {property} may not be empty.');\n\nexport const valid = (): PropertyDecorator => constraint(v => validate(v), '');\n\nexport const optional = (): PropertyDecorator => constraint(v => !isDefined(v) || validate(v), '');\n\nexport const includes = (sub: string, message?: string): PropertyDecorator =>\n constraint(s => isDefined(s) && isString(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);\n\nexport const inList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const inOptionalList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => !isDefined(v) || isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);\n\nexport const gte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);\n\nexport const lt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);\n\nexport const lte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v <= limit, message ?? `Value {actual} must be smaller than or equal to ${limit}.`);\n\nexport const past = (message?: Text): PropertyDecorator => constraint(v => inPast(v), message ?? 'Value {actual} must lay in the past.');\n\nexport const future = (message?: Text): PropertyDecorator => constraint(v => inFuture(v), message ?? 'Value {actual} must lay in the future.');\n\nexport const minLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length >= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} must be at least '${length}' characters long.`\n );\n\nexport const maxLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length <= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} cannot be longer than '${length}' characters.`\n );\n\nexport const rule = (message?: Text): PropertyDecorator =>\n constraint(v => (isFunction(v) ? (v() as boolean | Results) : isBoolean(v) ? v : false), message ?? `Value {actual} must be true`);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqJ;AACrJ,sBAAoC;AAI7B,MAAM,aACX,CAAI,GAAe,YACnB,CAAC,SAAkB,aAAo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tJ,MAAM,MAAM,CAAC,OAAe,YACjC,WAAW,OAAK,KAAK,OAAO,WAAW,mDAAmD,KAAK,GAAG;AAE7F,MAAM,OAAO,CAAC,YAAsC,WAAW,WAAK,qBAAO,CAAC,GAAG,WAAW,sCAAsC;AAEhI,MAAM,SAAS,CAAC,YAAsC,WAAW,WAAK,uBAAS,CAAC,GAAG,WAAW,wCAAwC;AAEtI,MAAM,YAAY,CAAC,QAAgB,YACxC;AAAA,EACE,WACE,oBAAM,MAAM,CAAC,EACV,GAAG,QAAQ,EACX,IAAI,CAAAA,WAAK,mBAAKA,EAAC,EAAE,SAAS,EAAE,UAAU,MAAM,EAC5C,OAAO,IAAI;AAAA,EAChB,WAAW,oCAAoC,MAAM;AACvD;AAEK,MAAM,YAAY,CAAC,QAAgB,YACxC;AAAA,EACE,WACE,oBAAM,MAAM,CAAC,EACV,GAAG,QAAQ,EACX,IAAI,CAAAA,WAAK,mBAAKA,EAAC,EAAE,SAAS,EAAE,UAAU,MAAM,EAC5C,OAAO,IAAI;AAAA,EAChB,WAAW,yCAAyC,MAAM;AAC5D;AAEK,MAAM,OAAO,CAAC,YACnB,WAAW,WAAM,yBAAW,CAAC,IAAK,EAAE,QAA0B,wBAAU,CAAC,IAAI,IAAI,OAAQ,WAAW,6BAA6B;","names":["v"]}
@@ -12,6 +12,7 @@ const valid = () => constraint((v) => validate(v), "");
12
12
  const optional = () => constraint((v) => !isDefined(v) || validate(v), "");
13
13
  const includes = (sub, message) => constraint((s) => isDefined(s) && isString(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);
14
14
  const inList = (values, message) => constraint((v) => isDefined(v) && isIn(v, values), message ?? "Value {actual} must appear in list.");
15
+ const inOptionalList = (values, message) => constraint((v) => !isDefined(v) || isIn(v, values), message ?? "Value {actual} must appear in list.");
15
16
  const gt = (limit, message) => constraint((v) => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);
16
17
  const gte = (limit, message) => constraint((v) => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);
17
18
  const lt = (limit, message) => constraint((v) => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);
@@ -34,6 +35,7 @@ export {
34
35
  gt,
35
36
  gte,
36
37
  inList,
38
+ inOptionalList,
37
39
  includes,
38
40
  lt,
39
41
  lte,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/validation/Contraints.ts"],"sourcesContent":["import { Func, inFuture, inPast, isBoolean, isDefined, isFunction, isIn, isNotEmpty, isString, List, meta, Results, text, Text, toList, tryTo } from '../types';\nimport { validate, Validator } from './Validate';\n\nexport type Constraint = Func<boolean | Results, any>;\n\nexport const constraint =\n <T>(c: Constraint, message: Text): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n const cs = meta(subject).property(property).get<List<Validator>>('constraint') ?? toList<Validator>();\n meta(subject)\n .property(property)\n .set('constraint', cs.add({ property, constraint: c, text: message }));\n };\n\nexport const defined = (message?: Text): PropertyDecorator => constraint(v => isDefined(v), message ?? 'Property {property} must be defined.');\n\nexport const required = (message?: Text): PropertyDecorator =>\n constraint(v => isNotEmpty(v), message ?? 'Property {property} is required, and may not be empty.');\n\nexport const notEmpty = (message?: Text): PropertyDecorator => constraint(v => isNotEmpty(v), message ?? 'Property {property} may not be empty.');\n\nexport const valid = (): PropertyDecorator => constraint(v => validate(v), '');\n\nexport const optional = (): PropertyDecorator => constraint(v => !isDefined(v) || validate(v), '');\n\nexport const includes = (sub: string, message?: string): PropertyDecorator =>\n constraint(s => isDefined(s) && isString(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);\n\nexport const inList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);\n\nexport const gte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);\n\nexport const lt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);\n\nexport const lte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v <= limit, message ?? `Value {actual} must be smaller than or equal to ${limit}.`);\n\nexport const past = (message?: Text): PropertyDecorator => constraint(v => inPast(v), message ?? 'Value {actual} must lay in the past.');\n\nexport const future = (message?: Text): PropertyDecorator => constraint(v => inFuture(v), message ?? 'Value {actual} must lay in the future.');\n\nexport const minLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length >= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} must be at least '${length}' characters long.`\n );\n\nexport const maxLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length <= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} cannot be longer than '${length}' characters.`\n );\n\nexport const rule = (message?: Text): PropertyDecorator =>\n constraint(v => (isFunction(v) ? (v() as boolean | Results) : isBoolean(v) ? v : false), message ?? `Value {actual} must be true`);\n"],"mappings":";AAAA,SAAe,UAAU,QAAQ,WAAW,WAAW,YAAY,MAAM,YAAY,UAAgB,MAAe,MAAY,QAAQ,aAAa;AACrJ,SAAS,gBAA2B;AAI7B,MAAM,aACX,CAAI,GAAe,YACnB,CAAC,SAAkB,aAAoC;AACrD,QAAM,KAAK,KAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAqB,YAAY,KAAK,OAAkB;AACpG,OAAK,OAAO,EACT,SAAS,QAAQ,EACjB,IAAI,cAAc,GAAG,IAAI,EAAE,UAAU,YAAY,GAAG,MAAM,QAAQ,CAAC,CAAC;AACzE;AAEK,MAAM,UAAU,CAAC,YAAsC,WAAW,OAAK,UAAU,CAAC,GAAG,WAAW,sCAAsC;AAEtI,MAAM,WAAW,CAAC,YACvB,WAAW,OAAK,WA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MAAM,YAAY,CAAC,QAAgB,YACxC;AAAA,EACE,OACE,MAAM,MAAM,CAAC,EACV,GAAG,QAAQ,EACX,IAAI,CAAAA,OAAK,KAAKA,EAAC,EAAE,SAAS,EAAE,UAAU,MAAM,EAC5C,OAAO,IAAI;AAAA,EAChB,WAAW,yCAAyC,MAAM;AAC5D;AAEK,MAAM,OAAO,CAAC,YACnB,WAAW,OAAM,WAAW,CAAC,IAAK,EAAE,IAA0B,UAAU,CAAC,IAAI,IAAI,OAAQ,WAAW,6BAA6B;","names":["v"]}
1
+ {"version":3,"sources":["../../src/validation/Contraints.ts"],"sourcesContent":["import { Func, inFuture, inPast, isBoolean, isDefined, isFunction, isIn, isNotEmpty, isString, List, meta, Results, text, Text, toList, tryTo } from '../types';\nimport { validate, Validator } from './Validate';\n\nexport type Constraint = Func<boolean | Results, any>;\n\nexport const constraint =\n <T>(c: Constraint, message: Text): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n const cs = meta(subject).property(property).get<List<Validator>>('constraint') ?? toList<Validator>();\n meta(subject)\n .property(property)\n .set('constraint', cs.add({ property, constraint: c, text: message }));\n };\n\nexport const defined = (message?: Text): PropertyDecorator => constraint(v => isDefined(v), message ?? 'Property {property} must be defined.');\n\nexport const required = (message?: Text): PropertyDecorator =>\n constraint(v => isNotEmpty(v), message ?? 'Property {property} is required, and may not be empty.');\n\nexport const notEmpty = (message?: Text): PropertyDecorator => constraint(v => isNotEmpty(v), message ?? 'Property {property} may not be empty.');\n\nexport const valid = (): PropertyDecorator => constraint(v => validate(v), '');\n\nexport const optional = (): PropertyDecorator => constraint(v => !isDefined(v) || validate(v), '');\n\nexport const includes = (sub: string, message?: string): PropertyDecorator =>\n constraint(s => isDefined(s) && isString(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);\n\nexport const inList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const inOptionalList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => !isDefined(v) || isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);\n\nexport const gte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);\n\nexport const lt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);\n\nexport const lte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v <= limit, message ?? `Value {actual} must be smaller than or equal to ${limit}.`);\n\nexport const past = (message?: Text): PropertyDecorator => constraint(v => inPast(v), message ?? 'Value {actual} must lay in the past.');\n\nexport const future = (message?: Text): PropertyDecorator => constraint(v => inFuture(v), message ?? 'Value {actual} must lay in the future.');\n\nexport const minLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length >= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} must be at least '${length}' characters long.`\n );\n\nexport const maxLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length <= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} cannot be longer than '${length}' characters.`\n );\n\nexport const rule = (message?: Text): PropertyDecorator =>\n constraint(v => (isFunction(v) ? (v() as boolean | Results) : isBoolean(v) ? v : false), message ?? `Value {actual} must be true`);\n"],"mappings":";AAAA,SAAe,UAAU,QAAQ,WAAW,WAAW,YAAY,MAAM,YAAY,UAAgB,MAAe,MAAY,QAAQ,aAAa;AACrJ,SAAS,gBAA2B;AAI7B,MAAM,aACX,CAAI,GAAe,YACnB,CAAC,SAAkB,aAAoC;AACrD,QAAM,KAAK,KAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAqB,YAAY,KAAK,OAAkB;AACpG,OA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YAAsC,WAAW,OAAK,OAAO,CAAC,GAAG,WAAW,sCAAsC;AAEhI,MAAM,SAAS,CAAC,YAAsC,WAAW,OAAK,SAAS,CAAC,GAAG,WAAW,wCAAwC;AAEtI,MAAM,YAAY,CAAC,QAAgB,YACxC;AAAA,EACE,OACE,MAAM,MAAM,CAAC,EACV,GAAG,QAAQ,EACX,IAAI,CAAAA,OAAK,KAAKA,EAAC,EAAE,SAAS,EAAE,UAAU,MAAM,EAC5C,OAAO,IAAI;AAAA,EAChB,WAAW,oCAAoC,MAAM;AACvD;AAEK,MAAM,YAAY,CAAC,QAAgB,YACxC;AAAA,EACE,OACE,MAAM,MAAM,CAAC,EACV,GAAG,QAAQ,EACX,IAAI,CAAAA,OAAK,KAAKA,EAAC,EAAE,SAAS,EAAE,UAAU,MAAM,EAC5C,OAAO,IAAI;AAAA,EAChB,WAAW,yCAAyC,MAAM;AAC5D;AAEK,MAAM,OAAO,CAAC,YACnB,WAAW,OAAM,WAAW,CAAC,IAAK,EAAE,IAA0B,UAAU,CAAC,IAAI,IAAI,OAAQ,WAAW,6BAA6B;","names":["v"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisisagile/easy",
3
- "version": "15.12.13",
3
+ "version": "15.13.0",
4
4
  "description": "Straightforward library for building domain-driven microservice architectures",
5
5
  "author": "Sander Hoogendoorn",
6
6
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "access": "public"
34
34
  },
35
35
  "devDependencies": {
36
- "@thisisagile/easy-test": "15.12.13",
36
+ "@thisisagile/easy-test": "15.13.0",
37
37
  "@types/form-urlencoded": "^4.4.0",
38
38
  "@types/jsonwebtoken": "^9.0.2",
39
39
  "@types/luxon": "3.2.0",
@@ -29,6 +29,9 @@ export const includes = (sub: string, message?: string): PropertyDecorator =>
29
29
  export const inList = (values: unknown[], message?: Text): PropertyDecorator =>
30
30
  constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');
31
31
 
32
+ export const inOptionalList = (values: unknown[], message?: Text): PropertyDecorator =>
33
+ constraint(v => !isDefined(v) || isIn(v, values), message ?? 'Value {actual} must appear in list.');
34
+
32
35
  export const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);
33
36
 
34
37
  export const gte = (limit: number, message?: Text): PropertyDecorator =>