@cratis/arc 22.28.1 → 22.30.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.
- package/commands/Command.ts +20 -14
- package/commands/for_Command/when_executing/with_rule_severities_and_declared_policy.ts +62 -0
- package/commands/for_Command/when_validating/with_rule_severities.ts +120 -0
- package/dist/cjs/commands/Command.d.ts.map +1 -1
- package/dist/cjs/commands/Command.js +27 -6
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/cjs/validation/PropertyRule.d.ts +3 -0
- package/dist/cjs/validation/PropertyRule.d.ts.map +1 -1
- package/dist/cjs/validation/PropertyRule.js +13 -1
- package/dist/cjs/validation/PropertyRule.js.map +1 -1
- package/dist/cjs/validation/RuleBuilder.d.ts +2 -0
- package/dist/cjs/validation/RuleBuilder.d.ts.map +1 -1
- package/dist/cjs/validation/RuleBuilder.js +10 -0
- package/dist/cjs/validation/RuleBuilder.js.map +1 -1
- package/dist/esm/commands/Command.d.ts.map +1 -1
- package/dist/esm/commands/Command.js +27 -6
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/for_Command/when_executing/with_rule_severities_and_declared_policy.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/with_rule_severities_and_declared_policy.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_rule_severities_and_declared_policy.js +51 -0
- package/dist/esm/commands/for_Command/when_executing/with_rule_severities_and_declared_policy.js.map +1 -0
- package/dist/esm/commands/for_Command/when_validating/with_rule_severities.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_validating/with_rule_severities.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_validating/with_rule_severities.js +104 -0
- package/dist/esm/commands/for_Command/when_validating/with_rule_severities.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/validation/PropertyRule.d.ts +3 -0
- package/dist/esm/validation/PropertyRule.d.ts.map +1 -1
- package/dist/esm/validation/PropertyRule.js +13 -1
- package/dist/esm/validation/PropertyRule.js.map +1 -1
- package/dist/esm/validation/RuleBuilder.d.ts +2 -0
- package/dist/esm/validation/RuleBuilder.d.ts.map +1 -1
- package/dist/esm/validation/RuleBuilder.js +10 -0
- package/dist/esm/validation/RuleBuilder.js.map +1 -1
- package/package.json +1 -1
- package/validation/PropertyRule.ts +16 -1
- package/validation/RuleBuilder.ts +13 -0
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { IValidationRule } from './IValidationRule.js';
|
|
2
2
|
import { ValidationResult } from './ValidationResult.js';
|
|
3
|
+
import { ValidationResultSeverity } from './ValidationResultSeverity.js';
|
|
3
4
|
export declare abstract class PropertyRule<T, TProperty> implements IValidationRule<T> {
|
|
4
5
|
protected readonly propertyAccessor: (instance: T) => TProperty;
|
|
5
6
|
protected errorMessage: string;
|
|
7
|
+
private severity;
|
|
6
8
|
constructor(propertyAccessor: (instance: T) => TProperty, defaultErrorMessage: string);
|
|
7
9
|
withMessage(message: string): this;
|
|
10
|
+
withSeverity(severity: ValidationResultSeverity | null): this;
|
|
8
11
|
validate(instance: T, propertyName: string): ValidationResult[];
|
|
9
12
|
protected abstract isValid(value: TProperty, instance: T): boolean;
|
|
10
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyRule.d.ts","sourceRoot":"","sources":["../../../validation/PropertyRule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"PropertyRule.d.ts","sourceRoot":"","sources":["../../../validation/PropertyRule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAOzE,8BAAsB,YAAY,CAAC,CAAC,EAAE,SAAS,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IAUtE,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,SAAS;IATnE,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAC/B,OAAO,CAAC,QAAQ,CAAmE;IAOnF,YACuB,gBAAgB,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,SAAS,EAC/D,mBAAmB,EAAE,MAAM,EAG9B;IAOD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAGjC;IAOD,YAAY,CAAC,QAAQ,EAAE,wBAAwB,GAAG,IAAI,GAAG,IAAI,CAG5D;IAGD,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAe9D;IAQD,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,GAAG,OAAO,CAAC;CACtE"}
|
|
@@ -10,6 +10,7 @@ import { ValidationResultSeverity } from './ValidationResultSeverity.js';
|
|
|
10
10
|
*/ class PropertyRule {
|
|
11
11
|
propertyAccessor;
|
|
12
12
|
errorMessage;
|
|
13
|
+
severity = ValidationResultSeverity.Error;
|
|
13
14
|
/**
|
|
14
15
|
* Initializes a new instance of the {@link PropertyRule} class.
|
|
15
16
|
* @param propertyAccessor Function to access the property value from the instance.
|
|
@@ -26,11 +27,22 @@ import { ValidationResultSeverity } from './ValidationResultSeverity.js';
|
|
|
26
27
|
this.errorMessage = message;
|
|
27
28
|
return this;
|
|
28
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Set the severity of this rule. Null leaves an unrepresentable server-side rule to server validation.
|
|
32
|
+
* @param severity The severity, or null if it cannot be determined statically.
|
|
33
|
+
* @returns This rule instance for chaining.
|
|
34
|
+
*/ withSeverity(severity) {
|
|
35
|
+
this.severity = severity;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
29
38
|
/** @inheritdoc */ validate(instance, propertyName) {
|
|
39
|
+
if (this.severity === null) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
30
42
|
const value = this.propertyAccessor(instance);
|
|
31
43
|
if (!this.isValid(value, instance)) {
|
|
32
44
|
return [
|
|
33
|
-
new ValidationResult(
|
|
45
|
+
new ValidationResult(this.severity, this.errorMessage.replace('{PropertyName}', propertyName), [
|
|
34
46
|
propertyName
|
|
35
47
|
], null)
|
|
36
48
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyRule.js","sources":["../../../validation/PropertyRule.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IValidationRule } from './IValidationRule.js';\nimport { ValidationResult } from './ValidationResult.js';\nimport { ValidationResultSeverity } from './ValidationResultSeverity.js';\n\n/**\n * Base class for property-based validation rules.\n * @template T The type being validated.\n * @template TProperty The type of the property being validated.\n */\nexport abstract class PropertyRule<T, TProperty> implements IValidationRule<T> {\n protected errorMessage: string;\n\n /**\n * Initializes a new instance of the {@link PropertyRule} class.\n * @param propertyAccessor Function to access the property value from the instance.\n * @param defaultErrorMessage The default error message if validation fails.\n */\n constructor(\n protected readonly propertyAccessor: (instance: T) => TProperty,\n defaultErrorMessage: string\n ) {\n this.errorMessage = defaultErrorMessage;\n }\n\n /**\n * Set a custom error message for this rule.\n * @param message The custom error message.\n * @returns This rule instance for chaining.\n */\n withMessage(message: string): this {\n this.errorMessage = message;\n return this;\n }\n\n /** @inheritdoc */\n validate(instance: T, propertyName: string): ValidationResult[] {\n const value = this.propertyAccessor(instance);\n if (!this.isValid(value, instance)) {\n return [new ValidationResult(\n
|
|
1
|
+
{"version":3,"file":"PropertyRule.js","sources":["../../../validation/PropertyRule.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IValidationRule } from './IValidationRule.js';\nimport { ValidationResult } from './ValidationResult.js';\nimport { ValidationResultSeverity } from './ValidationResultSeverity.js';\n\n/**\n * Base class for property-based validation rules.\n * @template T The type being validated.\n * @template TProperty The type of the property being validated.\n */\nexport abstract class PropertyRule<T, TProperty> implements IValidationRule<T> {\n protected errorMessage: string;\n private severity: ValidationResultSeverity | null = ValidationResultSeverity.Error;\n\n /**\n * Initializes a new instance of the {@link PropertyRule} class.\n * @param propertyAccessor Function to access the property value from the instance.\n * @param defaultErrorMessage The default error message if validation fails.\n */\n constructor(\n protected readonly propertyAccessor: (instance: T) => TProperty,\n defaultErrorMessage: string\n ) {\n this.errorMessage = defaultErrorMessage;\n }\n\n /**\n * Set a custom error message for this rule.\n * @param message The custom error message.\n * @returns This rule instance for chaining.\n */\n withMessage(message: string): this {\n this.errorMessage = message;\n return this;\n }\n\n /**\n * Set the severity of this rule. Null leaves an unrepresentable server-side rule to server validation.\n * @param severity The severity, or null if it cannot be determined statically.\n * @returns This rule instance for chaining.\n */\n withSeverity(severity: ValidationResultSeverity | null): this {\n this.severity = severity;\n return this;\n }\n\n /** @inheritdoc */\n validate(instance: T, propertyName: string): ValidationResult[] {\n if (this.severity === null) {\n return [];\n }\n\n const value = this.propertyAccessor(instance);\n if (!this.isValid(value, instance)) {\n return [new ValidationResult(\n this.severity,\n this.errorMessage.replace('{PropertyName}', propertyName),\n [propertyName],\n null\n )];\n }\n return [];\n }\n\n /**\n * Determine if the property value is valid.\n * @param value The property value.\n * @param instance The instance being validated.\n * @returns True if valid, false otherwise.\n */\n protected abstract isValid(value: TProperty, instance: T): boolean;\n}\n"],"names":["PropertyRule","errorMessage","severity","ValidationResultSeverity","Error","propertyAccessor","defaultErrorMessage","withMessage","message","withSeverity","validate","instance","propertyName","value","isValid","ValidationResult","replace"],"mappings":";;;AAAA;AACA;AAMA;;;;AAIC,IACM,MAAeA,YAAAA,CAAAA;;IACRC,YAAAA;IACFC,QAAAA,GAA4CC,wBAAAA,CAAyBC,KAAK;AAElF;;;;AAIC,QACD,WAAA,CACuBC,gBAA4C,EAC/DC,mBAA2B,CAC7B;aAFqBD,gBAAAA,GAAAA,gBAAAA;QAGnB,IAAI,CAACJ,YAAY,GAAGK,mBAAAA;AACxB,IAAA;AAEA;;;;QAKAC,WAAAA,CAAYC,OAAe,EAAQ;QAC/B,IAAI,CAACP,YAAY,GAAGO,OAAAA;AACpB,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAC,YAAAA,CAAaP,QAAyC,EAAQ;QAC1D,IAAI,CAACA,QAAQ,GAAGA,QAAAA;AAChB,QAAA,OAAO,IAAI;AACf,IAAA;AAEA,uBACAQ,QAAAA,CAASC,QAAW,EAAEC,YAAoB,EAAsB;AAC5D,QAAA,IAAI,IAAI,CAACV,QAAQ,KAAK,IAAA,EAAM;AACxB,YAAA,OAAO,EAAE;AACb,QAAA;AAEA,QAAA,MAAMW,KAAAA,GAAQ,IAAI,CAACR,gBAAgB,CAACM,QAAAA,CAAAA;AACpC,QAAA,IAAI,CAAC,IAAI,CAACG,OAAO,CAACD,OAAOF,QAAAA,CAAAA,EAAW;YAChC,OAAO;AAAC,gBAAA,IAAII,gBAAAA,CACR,IAAI,CAACb,QAAQ,EACb,IAAI,CAACD,YAAY,CAACe,OAAO,CAAC,gBAAA,EAAkBJ,YAAAA,CAAAA,EAC5C;AAACA,oBAAAA;iBAAa,EACd,IAAA;AACF,aAAA;AACN,QAAA;AACA,QAAA,OAAO,EAAE;AACb,IAAA;AASJ;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PropertyValidator } from './PropertyValidator.js';
|
|
2
2
|
import { IValidationRule } from './IValidationRule.js';
|
|
3
|
+
import { ValidationResultSeverity } from './ValidationResultSeverity.js';
|
|
3
4
|
export declare class RuleBuilder<T, TProperty> {
|
|
4
5
|
private readonly propertyValidator;
|
|
5
6
|
private readonly _propertyAccessor;
|
|
@@ -7,5 +8,6 @@ export declare class RuleBuilder<T, TProperty> {
|
|
|
7
8
|
constructor(propertyValidator: PropertyValidator<T>, _propertyAccessor: (instance: T) => TProperty);
|
|
8
9
|
addRule(rule: IValidationRule<T>): RuleBuilder<T, TProperty>;
|
|
9
10
|
withMessage(message: string): RuleBuilder<T, TProperty>;
|
|
11
|
+
withSeverity(severity: ValidationResultSeverity | null): RuleBuilder<T, TProperty>;
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=RuleBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuleBuilder.d.ts","sourceRoot":"","sources":["../../../validation/RuleBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"RuleBuilder.d.ts","sourceRoot":"","sources":["../../../validation/RuleBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAOzE,qBAAa,WAAW,CAAC,CAAC,EAAE,SAAS;IAS7B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IATtC,OAAO,CAAC,QAAQ,CAAC,CAAqB;IAOtC,YACqB,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC,EACvC,iBAAiB,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,SAAS,EAEjE;IAOD,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAI3D;IAOD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAKtD;IAOD,YAAY,CAAC,QAAQ,EAAE,wBAAwB,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAKjF;CACJ"}
|
|
@@ -37,6 +37,16 @@ import { PropertyRule } from './PropertyRule.js';
|
|
|
37
37
|
}
|
|
38
38
|
return this;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Set the severity of the last property rule.
|
|
42
|
+
* @param severity The rule's severity, or null when it is determined only on the server.
|
|
43
|
+
* @returns The rule builder for chaining.
|
|
44
|
+
*/ withSeverity(severity) {
|
|
45
|
+
if (this.lastRule && this.lastRule instanceof PropertyRule) {
|
|
46
|
+
this.lastRule.withSeverity(severity);
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
export { RuleBuilder };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuleBuilder.js","sources":["../../../validation/RuleBuilder.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { PropertyValidator } from './PropertyValidator.js';\nimport { IValidationRule } from './IValidationRule.js';\nimport { PropertyRule } from './PropertyRule.js';\n\n/**\n * Represents a builder for creating validation rules for a property.\n * @template T The type being validated.\n * @template TProperty The type of the property being validated.\n */\nexport class RuleBuilder<T, TProperty> {\n private lastRule?: IValidationRule<T>;\n\n /**\n * Initializes a new instance of the {@link RuleBuilder} class.\n * @param propertyValidator The property validator to add rules to.\n * @param _propertyAccessor Function to access the property value.\n */\n constructor(\n private readonly propertyValidator: PropertyValidator<T>,\n private readonly _propertyAccessor: (instance: T) => TProperty\n ) {\n }\n\n /**\n * Add a custom validation rule.\n * @param rule The validation rule to add.\n * @returns The rule builder for chaining.\n */\n addRule(rule: IValidationRule<T>): RuleBuilder<T, TProperty> {\n this.propertyValidator.addRule(rule);\n this.lastRule = rule;\n return this;\n }\n\n /**\n * Set a custom error message for the last added rule.\n * @param message The custom error message.\n * @returns The rule builder for chaining.\n */\n withMessage(message: string): RuleBuilder<T, TProperty> {\n if (this.lastRule && this.lastRule instanceof PropertyRule) {\n this.lastRule.withMessage(message);\n }\n return this;\n }\n}\n"],"names":["RuleBuilder","lastRule","_propertyAccessor","propertyValidator","addRule","rule","withMessage","message","PropertyRule"],"mappings":";;AAAA;AACA;
|
|
1
|
+
{"version":3,"file":"RuleBuilder.js","sources":["../../../validation/RuleBuilder.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { PropertyValidator } from './PropertyValidator.js';\nimport { IValidationRule } from './IValidationRule.js';\nimport { PropertyRule } from './PropertyRule.js';\nimport { ValidationResultSeverity } from './ValidationResultSeverity.js';\n\n/**\n * Represents a builder for creating validation rules for a property.\n * @template T The type being validated.\n * @template TProperty The type of the property being validated.\n */\nexport class RuleBuilder<T, TProperty> {\n private lastRule?: IValidationRule<T>;\n\n /**\n * Initializes a new instance of the {@link RuleBuilder} class.\n * @param propertyValidator The property validator to add rules to.\n * @param _propertyAccessor Function to access the property value.\n */\n constructor(\n private readonly propertyValidator: PropertyValidator<T>,\n private readonly _propertyAccessor: (instance: T) => TProperty\n ) {\n }\n\n /**\n * Add a custom validation rule.\n * @param rule The validation rule to add.\n * @returns The rule builder for chaining.\n */\n addRule(rule: IValidationRule<T>): RuleBuilder<T, TProperty> {\n this.propertyValidator.addRule(rule);\n this.lastRule = rule;\n return this;\n }\n\n /**\n * Set a custom error message for the last added rule.\n * @param message The custom error message.\n * @returns The rule builder for chaining.\n */\n withMessage(message: string): RuleBuilder<T, TProperty> {\n if (this.lastRule && this.lastRule instanceof PropertyRule) {\n this.lastRule.withMessage(message);\n }\n return this;\n }\n\n /**\n * Set the severity of the last property rule.\n * @param severity The rule's severity, or null when it is determined only on the server.\n * @returns The rule builder for chaining.\n */\n withSeverity(severity: ValidationResultSeverity | null): RuleBuilder<T, TProperty> {\n if (this.lastRule && this.lastRule instanceof PropertyRule) {\n this.lastRule.withSeverity(severity);\n }\n return this;\n }\n}\n"],"names":["RuleBuilder","lastRule","_propertyAccessor","propertyValidator","addRule","rule","withMessage","message","PropertyRule","withSeverity","severity"],"mappings":";;AAAA;AACA;AAOA;;;;AAIC,IACM,MAAMA,WAAAA,CAAAA;;;IACDC,QAAAA;AAER;;;;AAIC,QACD,YACI,iBAAwD,EACvCC,iBAA6C,CAChE;aAFmBC,iBAAAA,GAAAA,iBAAAA;aACAD,iBAAAA,GAAAA,iBAAAA;AAErB,IAAA;AAEA;;;;QAKAE,OAAAA,CAAQC,IAAwB,EAA6B;AACzD,QAAA,IAAI,CAACF,iBAAiB,CAACC,OAAO,CAACC,IAAAA,CAAAA;QAC/B,IAAI,CAACJ,QAAQ,GAAGI,IAAAA;AAChB,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAC,WAAAA,CAAYC,OAAe,EAA6B;QACpD,IAAI,IAAI,CAACN,QAAQ,IAAI,IAAI,CAACA,QAAQ,YAAYO,YAAAA,EAAc;AACxD,YAAA,IAAI,CAACP,QAAQ,CAACK,WAAW,CAACC,OAAAA,CAAAA;AAC9B,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAE,YAAAA,CAAaC,QAAyC,EAA6B;QAC/E,IAAI,IAAI,CAACT,QAAQ,IAAI,IAAI,CAACA,QAAQ,YAAYO,YAAAA,EAAc;AACxD,YAAA,IAAI,CAACP,QAAQ,CAACQ,YAAY,CAACC,QAAAA,CAAAA;AAC/B,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AACJ;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@cratis/arc",
|
|
4
|
-
"version": "22.
|
|
4
|
+
"version": "22.30.0",
|
|
5
5
|
"description": "TypeScript command, query, validation, identity, and messaging runtime for Cratis Arc — the CQRS application framework for ASP.NET Core — used by generated proxies.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cratis",
|
|
@@ -12,6 +12,7 @@ import { ValidationResultSeverity } from './ValidationResultSeverity.js';
|
|
|
12
12
|
*/
|
|
13
13
|
export abstract class PropertyRule<T, TProperty> implements IValidationRule<T> {
|
|
14
14
|
protected errorMessage: string;
|
|
15
|
+
private severity: ValidationResultSeverity | null = ValidationResultSeverity.Error;
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Initializes a new instance of the {@link PropertyRule} class.
|
|
@@ -35,12 +36,26 @@ export abstract class PropertyRule<T, TProperty> implements IValidationRule<T> {
|
|
|
35
36
|
return this;
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Set the severity of this rule. Null leaves an unrepresentable server-side rule to server validation.
|
|
41
|
+
* @param severity The severity, or null if it cannot be determined statically.
|
|
42
|
+
* @returns This rule instance for chaining.
|
|
43
|
+
*/
|
|
44
|
+
withSeverity(severity: ValidationResultSeverity | null): this {
|
|
45
|
+
this.severity = severity;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
38
49
|
/** @inheritdoc */
|
|
39
50
|
validate(instance: T, propertyName: string): ValidationResult[] {
|
|
51
|
+
if (this.severity === null) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
const value = this.propertyAccessor(instance);
|
|
41
56
|
if (!this.isValid(value, instance)) {
|
|
42
57
|
return [new ValidationResult(
|
|
43
|
-
|
|
58
|
+
this.severity,
|
|
44
59
|
this.errorMessage.replace('{PropertyName}', propertyName),
|
|
45
60
|
[propertyName],
|
|
46
61
|
null
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { PropertyValidator } from './PropertyValidator.js';
|
|
5
5
|
import { IValidationRule } from './IValidationRule.js';
|
|
6
6
|
import { PropertyRule } from './PropertyRule.js';
|
|
7
|
+
import { ValidationResultSeverity } from './ValidationResultSeverity.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Represents a builder for creating validation rules for a property.
|
|
@@ -46,4 +47,16 @@ export class RuleBuilder<T, TProperty> {
|
|
|
46
47
|
}
|
|
47
48
|
return this;
|
|
48
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Set the severity of the last property rule.
|
|
53
|
+
* @param severity The rule's severity, or null when it is determined only on the server.
|
|
54
|
+
* @returns The rule builder for chaining.
|
|
55
|
+
*/
|
|
56
|
+
withSeverity(severity: ValidationResultSeverity | null): RuleBuilder<T, TProperty> {
|
|
57
|
+
if (this.lastRule && this.lastRule instanceof PropertyRule) {
|
|
58
|
+
this.lastRule.withSeverity(severity);
|
|
59
|
+
}
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
49
62
|
}
|