@cratis/arc 22.24.0 → 22.25.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 +26 -8
- package/commands/for_Command/when_executing/with_declared_blocking_severity.ts +48 -0
- package/dist/cjs/commands/Command.js +17 -8
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/esm/commands/Command.d.ts +1 -0
- package/dist/esm/commands/Command.d.ts.map +1 -1
- package/dist/esm/commands/Command.js +17 -8
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/for_Command/when_executing/with_declared_blocking_severity.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/with_declared_blocking_severity.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_declared_blocking_severity.js +39 -0
- package/dist/esm/commands/for_Command/when_executing/with_declared_blocking_severity.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/commands/Command.ts
CHANGED
|
@@ -31,6 +31,8 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
31
31
|
readonly validation?: CommandValidator<any>;
|
|
32
32
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
33
33
|
readonly roles: string[] = [];
|
|
34
|
+
/** Inclusive minimum blocking severity declared by a model-bound command proxy. */
|
|
35
|
+
readonly blockOnValidationSeverity?: ValidationResultSeverity;
|
|
34
36
|
abstract readonly propertyDescriptors: PropertyDescriptor[];
|
|
35
37
|
abstract get requestParameters(): string[];
|
|
36
38
|
|
|
@@ -100,13 +102,19 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
100
102
|
/** @inheritdoc */
|
|
101
103
|
async validate(): Promise<CommandResult<TCommandResponse>> {
|
|
102
104
|
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
const filteredClientErrors = this.blockOnValidationSeverity === undefined
|
|
106
|
+
? clientValidationErrors
|
|
107
|
+
: this.filterValidationResultsBySeverity(clientValidationErrors);
|
|
108
|
+
if (filteredClientErrors.length > 0) {
|
|
109
|
+
return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
const validationErrors = this.validateRequiredProperties();
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
const filteredRequiredErrors = this.blockOnValidationSeverity === undefined
|
|
114
|
+
? validationErrors
|
|
115
|
+
: this.filterValidationResultsBySeverity(validationErrors);
|
|
116
|
+
if (filteredRequiredErrors.length > 0) {
|
|
117
|
+
return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;
|
|
110
118
|
}
|
|
111
119
|
|
|
112
120
|
let actualRoute = this.route;
|
|
@@ -124,13 +132,19 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
124
132
|
/** @inheritdoc */
|
|
125
133
|
validateClientSide(): CommandResult<TCommandResponse> {
|
|
126
134
|
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
const filteredClientErrors = this.blockOnValidationSeverity === undefined
|
|
136
|
+
? clientValidationErrors
|
|
137
|
+
: this.filterValidationResultsBySeverity(clientValidationErrors);
|
|
138
|
+
if (filteredClientErrors.length > 0) {
|
|
139
|
+
return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;
|
|
129
140
|
}
|
|
130
141
|
|
|
131
142
|
const validationErrors = this.validateRequiredProperties();
|
|
132
|
-
|
|
133
|
-
|
|
143
|
+
const filteredRequiredErrors = this.blockOnValidationSeverity === undefined
|
|
144
|
+
? validationErrors
|
|
145
|
+
: this.filterValidationResultsBySeverity(validationErrors);
|
|
146
|
+
if (filteredRequiredErrors.length > 0) {
|
|
147
|
+
return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;
|
|
134
148
|
}
|
|
135
149
|
|
|
136
150
|
return CommandResult.empty as unknown as CommandResult<TCommandResponse>;
|
|
@@ -164,6 +178,10 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
164
178
|
}
|
|
165
179
|
|
|
166
180
|
private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {
|
|
181
|
+
if (this.blockOnValidationSeverity !== undefined) {
|
|
182
|
+
const effectiveAllowed = Math.min(allowedSeverity ?? ValidationResultSeverity.Error, this.blockOnValidationSeverity - 1);
|
|
183
|
+
return validationResults.filter(result => result.severity === ValidationResultSeverity.Unknown || result.severity > effectiveAllowed);
|
|
184
|
+
}
|
|
167
185
|
if (ignoreWarnings === true) {
|
|
168
186
|
return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);
|
|
169
187
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { Command } from '../../Command';
|
|
5
|
+
import { CommandValidator } from '../../CommandValidator';
|
|
6
|
+
import { PropertyDescriptor } from '../../../reflection/PropertyDescriptor';
|
|
7
|
+
import { ValidationResult } from '../../../validation/ValidationResult';
|
|
8
|
+
import { ValidationResultSeverity } from '../../../validation/ValidationResultSeverity';
|
|
9
|
+
|
|
10
|
+
class WarningValidator extends CommandValidator {
|
|
11
|
+
severity = ValidationResultSeverity.Information;
|
|
12
|
+
validate(): ValidationResult[] {
|
|
13
|
+
return [new ValidationResult(this.severity, 'Original message', [], null)];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class PolicyCommand extends Command {
|
|
18
|
+
readonly route = '/test';
|
|
19
|
+
readonly validation = new WarningValidator();
|
|
20
|
+
readonly blockOnValidationSeverity = ValidationResultSeverity.Information;
|
|
21
|
+
readonly propertyDescriptors: PropertyDescriptor[] = [];
|
|
22
|
+
get requestParameters(): string[] { return []; }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('when executing with declared blocking severity', () => {
|
|
26
|
+
let command: PolicyCommand;
|
|
27
|
+
beforeEach(() => { command = new PolicyCommand(Object, false); });
|
|
28
|
+
|
|
29
|
+
it('blocks information locally despite a permissive caller threshold', async () => {
|
|
30
|
+
const result = await command.execute(ValidationResultSeverity.Error, true);
|
|
31
|
+
result.isSuccess.should.be.false;
|
|
32
|
+
result.validationResults[0].severity.should.equal(ValidationResultSeverity.Information);
|
|
33
|
+
result.validationResults[0].message.should.equal('Original message');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('blocks information on preflight validation', async () => {
|
|
37
|
+
const result = await command.validate();
|
|
38
|
+
result.isSuccess.should.be.false;
|
|
39
|
+
result.validationResults[0].severity.should.equal(ValidationResultSeverity.Information);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('blocks an unclassified failure without changing its severity', async () => {
|
|
43
|
+
command.validation.severity = ValidationResultSeverity.Unknown;
|
|
44
|
+
const result = await command.execute();
|
|
45
|
+
result.isSuccess.should.be.false;
|
|
46
|
+
result.validationResults[0].severity.should.equal(ValidationResultSeverity.Unknown);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -21,6 +21,7 @@ var ValidationResultSeverity = require('../validation/ValidationResultSeverity.j
|
|
|
21
21
|
_httpHeadersCallback;
|
|
22
22
|
/* eslint-disable @typescript-eslint/no-explicit-any */ validation;
|
|
23
23
|
/* eslint-enable @typescript-eslint/no-explicit-any */ roles = [];
|
|
24
|
+
/** Inclusive minimum blocking severity declared by a model-bound command proxy. */ blockOnValidationSeverity;
|
|
24
25
|
_initialValues = {};
|
|
25
26
|
_hasChanges = false;
|
|
26
27
|
_callbacks = [];
|
|
@@ -71,12 +72,14 @@ var ValidationResultSeverity = require('../validation/ValidationResultSeverity.j
|
|
|
71
72
|
}
|
|
72
73
|
/** @inheritdoc */ async validate() {
|
|
73
74
|
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
const filteredClientErrors = this.blockOnValidationSeverity === undefined ? clientValidationErrors : this.filterValidationResultsBySeverity(clientValidationErrors);
|
|
76
|
+
if (filteredClientErrors.length > 0) {
|
|
77
|
+
return CommandResult.CommandResult.validationFailed(filteredClientErrors);
|
|
76
78
|
}
|
|
77
79
|
const validationErrors = this.validateRequiredProperties();
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
const filteredRequiredErrors = this.blockOnValidationSeverity === undefined ? validationErrors : this.filterValidationResultsBySeverity(validationErrors);
|
|
81
|
+
if (filteredRequiredErrors.length > 0) {
|
|
82
|
+
return CommandResult.CommandResult.validationFailed(filteredRequiredErrors);
|
|
80
83
|
}
|
|
81
84
|
let actualRoute = this.route;
|
|
82
85
|
if (this.requestParameters && this.requestParameters.length > 0) {
|
|
@@ -89,12 +92,14 @@ var ValidationResultSeverity = require('../validation/ValidationResultSeverity.j
|
|
|
89
92
|
}
|
|
90
93
|
/** @inheritdoc */ validateClientSide() {
|
|
91
94
|
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
const filteredClientErrors = this.blockOnValidationSeverity === undefined ? clientValidationErrors : this.filterValidationResultsBySeverity(clientValidationErrors);
|
|
96
|
+
if (filteredClientErrors.length > 0) {
|
|
97
|
+
return CommandResult.CommandResult.validationFailed(filteredClientErrors);
|
|
94
98
|
}
|
|
95
99
|
const validationErrors = this.validateRequiredProperties();
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
const filteredRequiredErrors = this.blockOnValidationSeverity === undefined ? validationErrors : this.filterValidationResultsBySeverity(validationErrors);
|
|
101
|
+
if (filteredRequiredErrors.length > 0) {
|
|
102
|
+
return CommandResult.CommandResult.validationFailed(filteredRequiredErrors);
|
|
98
103
|
}
|
|
99
104
|
return CommandResult.CommandResult.empty;
|
|
100
105
|
}
|
|
@@ -121,6 +126,10 @@ var ValidationResultSeverity = require('../validation/ValidationResultSeverity.j
|
|
|
121
126
|
return validationErrors;
|
|
122
127
|
}
|
|
123
128
|
filterValidationResultsBySeverity(validationResults, allowedSeverity, ignoreWarnings) {
|
|
129
|
+
if (this.blockOnValidationSeverity !== undefined) {
|
|
130
|
+
const effectiveAllowed = Math.min(allowedSeverity ?? ValidationResultSeverity.ValidationResultSeverity.Error, this.blockOnValidationSeverity - 1);
|
|
131
|
+
return validationResults.filter((result)=>result.severity === ValidationResultSeverity.ValidationResultSeverity.Unknown || result.severity > effectiveAllowed);
|
|
132
|
+
}
|
|
124
133
|
if (ignoreWarnings === true) {
|
|
125
134
|
return validationResults.filter((result)=>result.severity === ValidationResultSeverity.ValidationResultSeverity.Error);
|
|
126
135
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Command.js","sources":["../../../commands/Command.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 { ICommand, PropertyChanged } from './ICommand';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n async execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n actualRoute = `${actualRoute}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n /** @inheritdoc */\n validateClientSide(): CommandResult<TCommandResponse> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n return CommandResult.empty as unknown as CommandResult<TCommandResponse>;\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null) {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\n if (ignoreWarnings === true) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n if (allowedSeverity === undefined) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n return validationResults.filter(result => result.severity > allowedSeverity);\n }\n\n private buildHeaders(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n if (allowedSeverity !== undefined) {\n headers['X-Allowed-Severity'] = allowedSeverity.toString();\n }\n\n if (ignoreWarnings === true) {\n headers['X-Ignore-Warnings'] = 'true';\n }\n\n return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string,\n allowedSeverity?: ValidationResultSeverity,\n ignoreWarnings?: boolean\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders(allowedSeverity, ignoreWarnings);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Command","_microservice","_apiBasePath","_origin","_httpHeadersCallback","validation","roles","_initialValues","_hasChanges","_callbacks","_responseType","Object","_isResponseTypeEnumerable","Globals","microservice","apiBasePath","origin","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","execute","allowedSeverity","ignoreWarnings","clientValidationErrors","validate","filteredClientErrors","filterValidationResultsBySeverity","length","CommandResult","validationFailed","validationErrors","validateRequiredProperties","filteredRequiredErrors","actualRoute","route","requestParameters","payload","buildPayload","UrlHelpers","replaceRouteParameters","result","performRequest","setInitialValuesFromCurrentValues","validateClientSide","empty","propertyDescriptors","forEach","propertyDescriptor","property","name","isOptional","includes","value","undefined","push","ValidationResult","ValidationResultSeverity","Error","validationResults","filter","severity","buildHeaders","customHeaders","headers","microserviceHttpHeader","toString","notFoundMessage","errorMessage","joinPaths","url","createUrlFrom","response","fetch","method","body","JsonSerializer","serialize","status","failed","json","ex","clear","setInitialValues","values","prototype","hasOwnProperty","call","updateHasChanges","revertChanges","hasChanges","propertyChanged","callbackContainer","deref","thisArg","_","onPropertyChanged","WeakRef","some"],"mappings":";;;;;;;;;;AAAA;AACA;AAmBA;;AAEC,IACM,MAAeA,OAAAA,CAAAA;;;IACVC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;4DAGR,UAASC;AACT,2DACSC,KAAAA,GAAkB,EAAE;AAIrBC,IAAAA,cAAAA,GAAyB,EAAC;AAC1BC,IAAAA,WAAAA,GAAc,KAAA;AACdC,IAAAA,UAAAA,GAAyB,EAAE;AAEnC;;;;AAIC,QACD,YAAY,aAASC,GAA6BC,MAAM,EAAWC,yBAAkC,CAAE;aAAlFF,aAAAA,GAAAA,aAAAA;aAA8CE,yBAAAA,GAAAA,yBAAAA;AAC/D,QAAA,IAAI,CAACX,aAAa,GAAGY,eAAAA,CAAQC,YAAY,IAAI,EAAA;AAC7C,QAAA,IAAI,CAACZ,YAAY,GAAGW,eAAAA,CAAQE,WAAW,IAAI,EAAA;AAC3C,QAAA,IAAI,CAACZ,OAAO,GAAGU,eAAAA,CAAQG,MAAM,IAAI,EAAA;AACjC,QAAA,IAAI,CAACZ,oBAAoB,GAAG,KAAO,EAAC,CAAA;AACxC,IAAA;uBAGAa,eAAAA,CAAgBH,YAAoB,EAAE;QAClC,IAAI,CAACb,aAAa,GAAGa,YAAAA;AACzB,IAAA;uBAGAI,cAAAA,CAAeH,WAAmB,EAAQ;QACtC,IAAI,CAACb,YAAY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B;QACvB,IAAI,CAACjF,WAAW,GAAG,IAAI,CAACuC,mBAAmB,CAACoD,IAAI,CAAClD,CAAAA,kBAAAA,GAAAA;YAC7C,MAAMC,QAAAA,GAAWD,mBAAmBE,IAAI;YACxC,OAAO,IAAI,CAACD,QAAAA,CAAS,KAAK,IAAI,CAAC3C,cAAc,CAAC2C,QAAAA,CAAS;AAC3D,QAAA,CAAA,CAAA;AACJ,IAAA;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"Command.js","sources":["../../../commands/Command.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 { ICommand, PropertyChanged } from './ICommand';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n /** Inclusive minimum blocking severity declared by a model-bound command proxy. */\n readonly blockOnValidationSeverity?: ValidationResultSeverity;\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n async execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.blockOnValidationSeverity === undefined\n ? clientValidationErrors\n : this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.blockOnValidationSeverity === undefined\n ? validationErrors\n : this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n actualRoute = `${actualRoute}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n /** @inheritdoc */\n validateClientSide(): CommandResult<TCommandResponse> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.blockOnValidationSeverity === undefined\n ? clientValidationErrors\n : this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.blockOnValidationSeverity === undefined\n ? validationErrors\n : this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n return CommandResult.empty as unknown as CommandResult<TCommandResponse>;\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null) {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\n if (this.blockOnValidationSeverity !== undefined) {\n const effectiveAllowed = Math.min(allowedSeverity ?? ValidationResultSeverity.Error, this.blockOnValidationSeverity - 1);\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Unknown || result.severity > effectiveAllowed);\n }\n if (ignoreWarnings === true) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n if (allowedSeverity === undefined) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n return validationResults.filter(result => result.severity > allowedSeverity);\n }\n\n private buildHeaders(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n if (allowedSeverity !== undefined) {\n headers['X-Allowed-Severity'] = allowedSeverity.toString();\n }\n\n if (ignoreWarnings === true) {\n headers['X-Ignore-Warnings'] = 'true';\n }\n\n return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string,\n allowedSeverity?: ValidationResultSeverity,\n ignoreWarnings?: boolean\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders(allowedSeverity, ignoreWarnings);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Command","_microservice","_apiBasePath","_origin","_httpHeadersCallback","validation","roles","blockOnValidationSeverity","_initialValues","_hasChanges","_callbacks","_responseType","Object","_isResponseTypeEnumerable","Globals","microservice","apiBasePath","origin","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","execute","allowedSeverity","ignoreWarnings","clientValidationErrors","validate","filteredClientErrors","filterValidationResultsBySeverity","length","CommandResult","validationFailed","validationErrors","validateRequiredProperties","filteredRequiredErrors","actualRoute","route","requestParameters","payload","buildPayload","UrlHelpers","replaceRouteParameters","result","performRequest","setInitialValuesFromCurrentValues","undefined","validateClientSide","empty","propertyDescriptors","forEach","propertyDescriptor","property","name","isOptional","includes","value","push","ValidationResult","ValidationResultSeverity","Error","validationResults","effectiveAllowed","Math","min","filter","severity","Unknown","buildHeaders","customHeaders","headers","microserviceHttpHeader","toString","notFoundMessage","errorMessage","joinPaths","url","createUrlFrom","response","fetch","method","body","JsonSerializer","serialize","status","failed","json","ex","clear","setInitialValues","values","prototype","hasOwnProperty","call","updateHasChanges","revertChanges","hasChanges","propertyChanged","callbackContainer","deref","thisArg","_","onPropertyChanged","WeakRef","some"],"mappings":";;;;;;;;;;AAAA;AACA;AAmBA;;AAEC,IACM,MAAeA,OAAAA,CAAAA;;;IACVC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;4DAGR,UAASC;AACT,2DACSC,KAAAA,GAAkB,EAAE;wFAE7B,yBAASC;AAIDC,IAAAA,cAAAA,GAAyB,EAAC;AAC1BC,IAAAA,WAAAA,GAAc,KAAA;AACdC,IAAAA,UAAAA,GAAyB,EAAE;AAEnC;;;;AAIC,QACD,YAAY,aAASC,GAA6BC,MAAM,EAAWC,yBAAkC,CAAE;aAAlFF,aAAAA,GAAAA,aAAAA;aAA8CE,yBAAAA,GAAAA,yBAAAA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AAA,CAAAA;AACtB8E,YAAAA,OAAAA,EAAS,IAAIG,OAAAA,CAAQH,OAAAA;AACzB,SAAA,CAAA;AACJ,IAAA;IAEQN,gBAAAA,GAAmB;QACvB,IAAI,CAACrF,WAAW,GAAG,IAAI,CAACwC,mBAAmB,CAACuD,IAAI,CAACrD,CAAAA,kBAAAA,GAAAA;YAC7C,MAAMC,QAAAA,GAAWD,mBAAmBE,IAAI;YACxC,OAAO,IAAI,CAACD,QAAAA,CAAS,KAAK,IAAI,CAAC5C,cAAc,CAAC4C,QAAAA,CAAS;AAC3D,QAAA,CAAA,CAAA;AACJ,IAAA;AACJ;;"}
|
|
@@ -15,6 +15,7 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
|
|
|
15
15
|
abstract readonly route: string;
|
|
16
16
|
readonly validation?: CommandValidator<any>;
|
|
17
17
|
readonly roles: string[];
|
|
18
|
+
readonly blockOnValidationSeverity?: ValidationResultSeverity;
|
|
18
19
|
abstract readonly propertyDescriptors: PropertyDescriptor[];
|
|
19
20
|
abstract get requestParameters(): string[];
|
|
20
21
|
private _initialValues;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Command.d.ts","sourceRoot":"","sources":["../../../commands/Command.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAInE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAUlF,8BAAsB,OAAO,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE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CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAkB;IAOpC,YAAqB,aAAa,EAAE,WAAW,YAAS,EAAW,yBAAyB,EAAE,OAAO,EAKpG;IAGD,eAAe,CAAC,YAAY,EAAE,MAAM,QAEnC;IAGD,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAExC;IAGD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9B;IAGD,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAErD;IAGK,OAAO,CAAC,eAAe,CAAC,EAAE,wBAAwB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAwB5H;IAGK,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CA2BzD;IAGD,kBAAkB,IAAI,aAAa,CAAC,gBAAgB,CAAC,CAkBpD;IAED,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,0BAA0B;IAkBlC,OAAO,CAAC,iCAAiC;IAczC,OAAO,CAAC,YAAY;YAuBN,cAAc;IA+B5B,KAAK,IAAI,IAAI,CAOZ;IAGD,gBAAgB,CAAC,MAAM,EAAE,eAAe,QASvC;IAGD,iCAAiC,SAQhC;IAGD,aAAa,IAAI,IAAI,CAKpB;IAGD,IAAI,UAAU,YAEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM,QAY/B;IAGD,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,QAK3D;IAED,OAAO,CAAC,gBAAgB;CAM3B"}
|
|
@@ -19,6 +19,7 @@ import { ValidationResultSeverity } from '../validation/ValidationResultSeverity
|
|
|
19
19
|
_httpHeadersCallback;
|
|
20
20
|
/* eslint-disable @typescript-eslint/no-explicit-any */ validation;
|
|
21
21
|
/* eslint-enable @typescript-eslint/no-explicit-any */ roles = [];
|
|
22
|
+
/** Inclusive minimum blocking severity declared by a model-bound command proxy. */ blockOnValidationSeverity;
|
|
22
23
|
_initialValues = {};
|
|
23
24
|
_hasChanges = false;
|
|
24
25
|
_callbacks = [];
|
|
@@ -69,12 +70,14 @@ import { ValidationResultSeverity } from '../validation/ValidationResultSeverity
|
|
|
69
70
|
}
|
|
70
71
|
/** @inheritdoc */ async validate() {
|
|
71
72
|
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
const filteredClientErrors = this.blockOnValidationSeverity === undefined ? clientValidationErrors : this.filterValidationResultsBySeverity(clientValidationErrors);
|
|
74
|
+
if (filteredClientErrors.length > 0) {
|
|
75
|
+
return CommandResult.validationFailed(filteredClientErrors);
|
|
74
76
|
}
|
|
75
77
|
const validationErrors = this.validateRequiredProperties();
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
const filteredRequiredErrors = this.blockOnValidationSeverity === undefined ? validationErrors : this.filterValidationResultsBySeverity(validationErrors);
|
|
79
|
+
if (filteredRequiredErrors.length > 0) {
|
|
80
|
+
return CommandResult.validationFailed(filteredRequiredErrors);
|
|
78
81
|
}
|
|
79
82
|
let actualRoute = this.route;
|
|
80
83
|
if (this.requestParameters && this.requestParameters.length > 0) {
|
|
@@ -87,12 +90,14 @@ import { ValidationResultSeverity } from '../validation/ValidationResultSeverity
|
|
|
87
90
|
}
|
|
88
91
|
/** @inheritdoc */ validateClientSide() {
|
|
89
92
|
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
const filteredClientErrors = this.blockOnValidationSeverity === undefined ? clientValidationErrors : this.filterValidationResultsBySeverity(clientValidationErrors);
|
|
94
|
+
if (filteredClientErrors.length > 0) {
|
|
95
|
+
return CommandResult.validationFailed(filteredClientErrors);
|
|
92
96
|
}
|
|
93
97
|
const validationErrors = this.validateRequiredProperties();
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
const filteredRequiredErrors = this.blockOnValidationSeverity === undefined ? validationErrors : this.filterValidationResultsBySeverity(validationErrors);
|
|
99
|
+
if (filteredRequiredErrors.length > 0) {
|
|
100
|
+
return CommandResult.validationFailed(filteredRequiredErrors);
|
|
96
101
|
}
|
|
97
102
|
return CommandResult.empty;
|
|
98
103
|
}
|
|
@@ -119,6 +124,10 @@ import { ValidationResultSeverity } from '../validation/ValidationResultSeverity
|
|
|
119
124
|
return validationErrors;
|
|
120
125
|
}
|
|
121
126
|
filterValidationResultsBySeverity(validationResults, allowedSeverity, ignoreWarnings) {
|
|
127
|
+
if (this.blockOnValidationSeverity !== undefined) {
|
|
128
|
+
const effectiveAllowed = Math.min(allowedSeverity ?? ValidationResultSeverity.Error, this.blockOnValidationSeverity - 1);
|
|
129
|
+
return validationResults.filter((result)=>result.severity === ValidationResultSeverity.Unknown || result.severity > effectiveAllowed);
|
|
130
|
+
}
|
|
122
131
|
if (ignoreWarnings === true) {
|
|
123
132
|
return validationResults.filter((result)=>result.severity === ValidationResultSeverity.Error);
|
|
124
133
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Command.js","sources":["../../../commands/Command.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 { ICommand, PropertyChanged } from './ICommand';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n async execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n actualRoute = `${actualRoute}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n /** @inheritdoc */\n validateClientSide(): CommandResult<TCommandResponse> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n return CommandResult.empty as unknown as CommandResult<TCommandResponse>;\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null) {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\n if (ignoreWarnings === true) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n if (allowedSeverity === undefined) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n return validationResults.filter(result => result.severity > allowedSeverity);\n }\n\n private buildHeaders(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n if (allowedSeverity !== undefined) {\n headers['X-Allowed-Severity'] = allowedSeverity.toString();\n }\n\n if (ignoreWarnings === true) {\n headers['X-Ignore-Warnings'] = 'true';\n }\n\n return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string,\n allowedSeverity?: ValidationResultSeverity,\n ignoreWarnings?: boolean\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders(allowedSeverity, ignoreWarnings);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Command","_microservice","_apiBasePath","_origin","_httpHeadersCallback","validation","roles","_initialValues","_hasChanges","_callbacks","_responseType","Object","_isResponseTypeEnumerable","Globals","microservice","apiBasePath","origin","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","execute","allowedSeverity","ignoreWarnings","clientValidationErrors","validate","filteredClientErrors","filterValidationResultsBySeverity","length","CommandResult","validationFailed","validationErrors","validateRequiredProperties","filteredRequiredErrors","actualRoute","route","requestParameters","payload","buildPayload","UrlHelpers","replaceRouteParameters","result","performRequest","setInitialValuesFromCurrentValues","validateClientSide","empty","propertyDescriptors","forEach","propertyDescriptor","property","name","isOptional","includes","value","undefined","push","ValidationResult","ValidationResultSeverity","Error","validationResults","filter","severity","buildHeaders","customHeaders","headers","microserviceHttpHeader","toString","notFoundMessage","errorMessage","joinPaths","url","createUrlFrom","response","fetch","method","body","JsonSerializer","serialize","status","failed","json","ex","clear","setInitialValues","values","prototype","hasOwnProperty","call","updateHasChanges","revertChanges","hasChanges","propertyChanged","callbackContainer","deref","thisArg","_","onPropertyChanged","WeakRef","some"],"mappings":";;;;;;;;AAAA;AACA;AAmBA;;AAEC,IACM,MAAeA,OAAAA,CAAAA;;;IACVC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;4DAGR,UAASC;AACT,2DACSC,KAAAA,GAAkB,EAAE;AAIrBC,IAAAA,cAAAA,GAAyB,EAAC;AAC1BC,IAAAA,WAAAA,GAAc,KAAA;AACdC,IAAAA,UAAAA,GAAyB,EAAE;AAEnC;;;;AAIC,QACD,YAAY,aAASC,GAA6BC,MAAM,EAAWC,yBAAkC,CAAE;aAAlFF,aAAAA,GAAAA,aAAAA;aAA8CE,yBAAAA,GAAAA,yBAAAA;AAC/D,QAAA,IAAI,CAACX,aAAa,GAAGY,OAAAA,CAAQC,YAAY,IAAI,EAAA;AAC7C,QAAA,IAAI,CAACZ,YAAY,GAAGW,OAAAA,CAAQE,WAAW,IAAI,EAAA;AAC3C,QAAA,IAAI,CAACZ,OAAO,GAAGU,OAAAA,CAAQG,MAAM,IAAI,EAAA;AACjC,QAAA,IAAI,CAACZ,oBAAoB,GAAG,KAAO,EAA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U,IAAI6E,OAAAA,CAAQ7E,QAAAA,CAAAA;AACtB0E,YAAAA,OAAAA,EAAS,IAAIG,OAAAA,CAAQH,OAAAA;AACzB,SAAA,CAAA;AACJ,IAAA;IAEQN,gBAAAA,GAAmB;QACvB,IAAI,CAACjF,WAAW,GAAG,IAAI,CAACuC,mBAAmB,CAACoD,IAAI,CAAClD,CAAAA,kBAAAA,GAAAA;YAC7C,MAAMC,QAAAA,GAAWD,mBAAmBE,IAAI;YACxC,OAAO,IAAI,CAACD,QAAAA,CAAS,KAAK,IAAI,CAAC3C,cAAc,CAAC2C,QAAAA,CAAS;AAC3D,QAAA,CAAA,CAAA;AACJ,IAAA;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"Command.js","sources":["../../../commands/Command.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 { ICommand, PropertyChanged } from './ICommand';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n /** Inclusive minimum blocking severity declared by a model-bound command proxy. */\n readonly blockOnValidationSeverity?: ValidationResultSeverity;\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n async execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.blockOnValidationSeverity === undefined\n ? clientValidationErrors\n : this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.blockOnValidationSeverity === undefined\n ? validationErrors\n : this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n actualRoute = `${actualRoute}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n /** @inheritdoc */\n validateClientSide(): CommandResult<TCommandResponse> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.blockOnValidationSeverity === undefined\n ? clientValidationErrors\n : this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.blockOnValidationSeverity === undefined\n ? validationErrors\n : this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n return CommandResult.empty as unknown as CommandResult<TCommandResponse>;\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null) {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\n if (this.blockOnValidationSeverity !== undefined) {\n const effectiveAllowed = Math.min(allowedSeverity ?? ValidationResultSeverity.Error, this.blockOnValidationSeverity - 1);\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Unknown || result.severity > effectiveAllowed);\n }\n if (ignoreWarnings === true) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n if (allowedSeverity === undefined) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n return validationResults.filter(result => result.severity > allowedSeverity);\n }\n\n private buildHeaders(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n if (allowedSeverity !== undefined) {\n headers['X-Allowed-Severity'] = allowedSeverity.toString();\n }\n\n if (ignoreWarnings === true) {\n headers['X-Ignore-Warnings'] = 'true';\n }\n\n return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string,\n allowedSeverity?: ValidationResultSeverity,\n ignoreWarnings?: boolean\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders(allowedSeverity, ignoreWarnings);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Command","_microservice","_apiBasePath","_origin","_httpHeadersCallback","validation","roles","blockOnValidationSeverity","_initialValues","_hasChanges","_callbacks","_responseType","Object","_isResponseTypeEnumerable","Globals","microservice","apiBasePath","origin","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","execute","allowedSeverity","ignoreWarnings","clientValidationErrors","validate","filteredClientErrors","filterValidationResultsBySeverity","length","CommandResult","validationFailed","validationErrors","validateRequiredProperties","filteredRequiredErrors","actualRoute","route","requestParameters","payload","buildPayload","UrlHelpers","replaceRouteParameters","result","performRequest","setInitialValuesFromCurrentValues","undefined","validateClientSide","empty","propertyDescriptors","forEach","propertyDescriptor","property","name","isOptional","includes","value","push","ValidationResult","ValidationResultSeverity","Error","validationResults","effectiveAllowed","Math","min","filter","severity","Unknown","buildHeaders","customHeaders","headers","microserviceHttpHeader","toString","notFoundMessage","errorMessage","joinPaths","url","createUrlFrom","response","fetch","method","body","JsonSerializer","serialize","status","failed","json","ex","clear","setInitialValues","values","prototype","hasOwnProperty","call","updateHasChanges","revertChanges","hasChanges","propertyChanged","callbackContainer","deref","thisArg","_","onPropertyChanged","WeakRef","some"],"mappings":";;;;;;;;AAAA;AACA;AAmBA;;AAEC,IACM,MAAeA,OAAAA,CAAAA;;;IACVC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;4DAGR,UAASC;AACT,2DACSC,KAAAA,GAAkB,EAAE;wFAE7B,yBAASC;AAIDC,IAAAA,cAAAA,GAAyB,EAAC;AAC1BC,IAAAA,WAAAA,GAAc,KAAA;AACdC,IAAAA,UAA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EAAE8E,OAAe,EAAE;AAC1D,QAAA,IAAI,CAAC1F,UAAU,CAAC+C,IAAI,CAAC;AACjBnC,YAAAA,QAAAA,EAAU,IAAIiF,OAAAA,CAAQjF,QAAAA,CAAAA;AACtB8E,YAAAA,OAAAA,EAAS,IAAIG,OAAAA,CAAQH,OAAAA;AACzB,SAAA,CAAA;AACJ,IAAA;IAEQN,gBAAAA,GAAmB;QACvB,IAAI,CAACrF,WAAW,GAAG,IAAI,CAACwC,mBAAmB,CAACuD,IAAI,CAACrD,CAAAA,kBAAAA,GAAAA;YAC7C,MAAMC,QAAAA,GAAWD,mBAAmBE,IAAI;YACxC,OAAO,IAAI,CAACD,QAAAA,CAAS,KAAK,IAAI,CAAC5C,cAAc,CAAC4C,QAAAA,CAAS;AAC3D,QAAA,CAAA,CAAA;AACJ,IAAA;AACJ;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_declared_blocking_severity.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_declared_blocking_severity.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Command } from '../../Command';
|
|
2
|
+
import { CommandValidator } from '../../CommandValidator';
|
|
3
|
+
import { ValidationResult } from '../../../validation/ValidationResult';
|
|
4
|
+
import { ValidationResultSeverity } from '../../../validation/ValidationResultSeverity';
|
|
5
|
+
class WarningValidator extends CommandValidator {
|
|
6
|
+
severity = ValidationResultSeverity.Information;
|
|
7
|
+
validate() {
|
|
8
|
+
return [new ValidationResult(this.severity, 'Original message', [], null)];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class PolicyCommand extends Command {
|
|
12
|
+
route = '/test';
|
|
13
|
+
validation = new WarningValidator();
|
|
14
|
+
blockOnValidationSeverity = ValidationResultSeverity.Information;
|
|
15
|
+
propertyDescriptors = [];
|
|
16
|
+
get requestParameters() { return []; }
|
|
17
|
+
}
|
|
18
|
+
describe('when executing with declared blocking severity', () => {
|
|
19
|
+
let command;
|
|
20
|
+
beforeEach(() => { command = new PolicyCommand(Object, false); });
|
|
21
|
+
it('blocks information locally despite a permissive caller threshold', async () => {
|
|
22
|
+
const result = await command.execute(ValidationResultSeverity.Error, true);
|
|
23
|
+
result.isSuccess.should.be.false;
|
|
24
|
+
result.validationResults[0].severity.should.equal(ValidationResultSeverity.Information);
|
|
25
|
+
result.validationResults[0].message.should.equal('Original message');
|
|
26
|
+
});
|
|
27
|
+
it('blocks information on preflight validation', async () => {
|
|
28
|
+
const result = await command.validate();
|
|
29
|
+
result.isSuccess.should.be.false;
|
|
30
|
+
result.validationResults[0].severity.should.equal(ValidationResultSeverity.Information);
|
|
31
|
+
});
|
|
32
|
+
it('blocks an unclassified failure without changing its severity', async () => {
|
|
33
|
+
command.validation.severity = ValidationResultSeverity.Unknown;
|
|
34
|
+
const result = await command.execute();
|
|
35
|
+
result.isSuccess.should.be.false;
|
|
36
|
+
result.validationResults[0].severity.should.equal(ValidationResultSeverity.Unknown);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=with_declared_blocking_severity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_declared_blocking_severity.js","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_declared_blocking_severity.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AAExF,MAAM,gBAAiB,SAAQ,gBAAgB;IAC3C,QAAQ,GAAG,wBAAwB,CAAC,WAAW,CAAC;IAChD,QAAQ;QACJ,OAAO,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,EAAE,EAAE,IAAI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