@cratis/arc 20.54.2 → 20.54.3
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 +15 -0
- package/commands/ICommand.ts +10 -0
- package/commands/for_Command/when_validating_client_side/with_client_validation_failure.ts +26 -0
- package/commands/for_Command/when_validating_client_side/with_client_validation_passing.ts +69 -0
- package/commands/for_Command/when_validating_client_side/with_required_property_missing.ts +28 -0
- package/dist/cjs/commands/Command.d.ts +1 -0
- package/dist/cjs/commands/Command.d.ts.map +1 -1
- package/dist/cjs/commands/Command.js +11 -0
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/cjs/commands/ICommand.d.ts +1 -0
- package/dist/cjs/commands/ICommand.d.ts.map +1 -1
- package/dist/cjs/commands/for_Command/when_validating_client_side/with_client_validation_failure.d.ts +2 -0
- package/dist/cjs/commands/for_Command/when_validating_client_side/with_client_validation_failure.d.ts.map +1 -0
- package/dist/cjs/commands/for_Command/when_validating_client_side/with_client_validation_passing.d.ts +2 -0
- package/dist/cjs/commands/for_Command/when_validating_client_side/with_client_validation_passing.d.ts.map +1 -0
- package/dist/cjs/commands/for_Command/when_validating_client_side/with_required_property_missing.d.ts +2 -0
- package/dist/cjs/commands/for_Command/when_validating_client_side/with_required_property_missing.d.ts.map +1 -0
- 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 +11 -0
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/ICommand.d.ts +1 -0
- package/dist/esm/commands/ICommand.d.ts.map +1 -1
- package/dist/esm/commands/for_Command/when_validating_client_side/with_client_validation_failure.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_client_validation_failure.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_client_validation_failure.js +18 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_client_validation_failure.js.map +1 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_client_validation_passing.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_client_validation_passing.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_client_validation_passing.js +48 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_client_validation_passing.js.map +1 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_required_property_missing.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_required_property_missing.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_required_property_missing.js +21 -0
- package/dist/esm/commands/for_Command/when_validating_client_side/with_required_property_missing.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/commands/Command.ts
CHANGED
|
@@ -121,6 +121,21 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
121
121
|
return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/** @inheritdoc */
|
|
125
|
+
validateClientSide(): CommandResult<TCommandResponse> {
|
|
126
|
+
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
127
|
+
if (clientValidationErrors.length > 0) {
|
|
128
|
+
return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const validationErrors = this.validateRequiredProperties();
|
|
132
|
+
if (validationErrors.length > 0) {
|
|
133
|
+
return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return CommandResult.empty as unknown as CommandResult<TCommandResponse>;
|
|
137
|
+
}
|
|
138
|
+
|
|
124
139
|
private buildPayload(): object {
|
|
125
140
|
const payload = {};
|
|
126
141
|
this.propertyDescriptors.forEach(propertyDescriptor => {
|
package/commands/ICommand.ts
CHANGED
|
@@ -47,6 +47,16 @@ export interface ICommand<TCommandContent = object, TCommandResponse = object> e
|
|
|
47
47
|
*/
|
|
48
48
|
validate(): Promise<CommandResult<TCommandResponse>>;
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Validate the {@link ICommand} using only client-side rules, without contacting the server.
|
|
52
|
+
* @returns {CommandResult} for the validation containing the client-side validation status.
|
|
53
|
+
* @remarks
|
|
54
|
+
* This method checks the registered validator rules and required properties locally.
|
|
55
|
+
* It never performs a network call. Use this for cheap, immediate feedback while the user is typing;
|
|
56
|
+
* use {@link validate} when server-side rules (e.g. uniqueness checks) also need to be verified.
|
|
57
|
+
*/
|
|
58
|
+
validateClientSide(): CommandResult<TCommandResponse>;
|
|
59
|
+
|
|
50
60
|
/**
|
|
51
61
|
* Clear the command properties and reset them to their default values. This will also clear the initial values.
|
|
52
62
|
* This is used when the command is not needed anymore and should be cleared.
|
|
@@ -0,0 +1,26 @@
|
|
|
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 { a_command_with_validator } from '../given/a_command_with_validator';
|
|
5
|
+
import { given } from '../../../given';
|
|
6
|
+
import { CommandResult } from '../../CommandResult';
|
|
7
|
+
|
|
8
|
+
describe("when validating client side with client validation failure", given(a_command_with_validator, context => {
|
|
9
|
+
let result: CommandResult<object>;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
context.command.email = '';
|
|
13
|
+
context.command.age = 25;
|
|
14
|
+
|
|
15
|
+
result = context.command.validateClientSide();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
context.fetchStub.restore();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should not call server", () => context.fetchStub.called.should.be.false);
|
|
23
|
+
it("should return invalid result", () => result.isValid.should.be.false);
|
|
24
|
+
it("should have validation error", () => result.validationResults.length.should.equal(1));
|
|
25
|
+
it("should have error for email property", () => result.validationResults[0].members[0].should.equal('email'));
|
|
26
|
+
}));
|
|
@@ -0,0 +1,69 @@
|
|
|
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 '../../../validation/RuleBuilderExtensions';
|
|
8
|
+
import sinon from 'sinon';
|
|
9
|
+
import { CommandResult } from '../../CommandResult';
|
|
10
|
+
import { createFetchHelper } from '../../../helpers/fetchHelper';
|
|
11
|
+
|
|
12
|
+
interface ITestCommand {
|
|
13
|
+
email: string;
|
|
14
|
+
age: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class TestCommandValidator extends CommandValidator<ITestCommand> {
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
this.ruleFor(c => c.email).notEmpty().emailAddress();
|
|
21
|
+
this.ruleFor(c => c.age).greaterThanOrEqual(18);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class TestCommand extends Command<ITestCommand> {
|
|
26
|
+
readonly route = '/api/test';
|
|
27
|
+
readonly validation = new TestCommandValidator();
|
|
28
|
+
readonly propertyDescriptors: PropertyDescriptor[] = [];
|
|
29
|
+
email = '';
|
|
30
|
+
age = 0;
|
|
31
|
+
|
|
32
|
+
constructor() {
|
|
33
|
+
super(Object, false);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get requestParameters(): string[] {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get properties(): string[] {
|
|
41
|
+
return ['email', 'age'];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe("when validating client side with client validation passing", () => {
|
|
46
|
+
let command: TestCommand;
|
|
47
|
+
let fetchStub: sinon.SinonStub;
|
|
48
|
+
let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
|
|
49
|
+
let result: CommandResult<object>;
|
|
50
|
+
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
command = new TestCommand();
|
|
53
|
+
command.setOrigin('http://localhost');
|
|
54
|
+
command.email = 'test@example.com';
|
|
55
|
+
command.age = 25;
|
|
56
|
+
|
|
57
|
+
fetchHelper = createFetchHelper();
|
|
58
|
+
fetchStub = fetchHelper.stubFetch();
|
|
59
|
+
|
|
60
|
+
result = command.validateClientSide();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
fetchHelper.restore();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should not call server", () => fetchStub.called.should.be.false);
|
|
68
|
+
it("should return valid result", () => result.isValid.should.be.true);
|
|
69
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { given } from '../../../given';
|
|
5
|
+
import { CommandResult } from '../../CommandResult';
|
|
6
|
+
import { a_command } from '../given/a_command';
|
|
7
|
+
|
|
8
|
+
describe("when validating client side with required property missing", given(class extends a_command {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.command.someProperty = undefined as unknown as string;
|
|
12
|
+
}
|
|
13
|
+
}, context => {
|
|
14
|
+
let result: CommandResult<object>;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
result = context.command.validateClientSide();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
context.fetchStub.restore();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should not call server", () => context.fetchStub.called.should.be.false);
|
|
25
|
+
it("should return invalid result", () => result.isValid.should.be.false);
|
|
26
|
+
it("should have validation error", () => result.validationResults.length.should.equal(1));
|
|
27
|
+
it("should have error for missing property", () => result.validationResults[0].members[0].should.equal('someProperty'));
|
|
28
|
+
}));
|
|
@@ -27,6 +27,7 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
|
|
|
27
27
|
setHttpHeadersCallback(callback: GetHttpHeaders): void;
|
|
28
28
|
execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>>;
|
|
29
29
|
validate(): Promise<CommandResult<TCommandResponse>>;
|
|
30
|
+
validateClientSide(): CommandResult<TCommandResponse>;
|
|
30
31
|
private buildPayload;
|
|
31
32
|
private validateRequiredProperties;
|
|
32
33
|
private filterValidationResultsBySeverity;
|
|
@@ -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,YAAW,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAsBzH,QAAQ,CAAC,aAAa,EAAE,WAAW;IAAW,QAAQ,CAAC,yBAAyB,EAAE,OAAO;IArBrG,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,oBAAoB,C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D,kBAAkB,IAAI,aAAa,CAAC,gBAAgB,CAAC;IAcrD,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,0BAA0B;IAkBlC,OAAO,CAAC,iCAAiC;IAUzC,OAAO,CAAC,YAAY;YAuBN,cAAc;IA+B5B,KAAK,IAAI,IAAI;IAUb,gBAAgB,CAAC,MAAM,EAAE,eAAe;IAYxC,iCAAiC;IAWjC,aAAa,IAAI,IAAI;IAQrB,IAAI,UAAU,YAEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM;IAehC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;IAO5D,OAAO,CAAC,gBAAgB;CAM3B"}
|
|
@@ -79,6 +79,17 @@ class Command {
|
|
|
79
79
|
actualRoute = `${actualRoute}/validate`;
|
|
80
80
|
return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');
|
|
81
81
|
}
|
|
82
|
+
validateClientSide() {
|
|
83
|
+
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
84
|
+
if (clientValidationErrors.length > 0) {
|
|
85
|
+
return CommandResult.CommandResult.validationFailed(clientValidationErrors);
|
|
86
|
+
}
|
|
87
|
+
const validationErrors = this.validateRequiredProperties();
|
|
88
|
+
if (validationErrors.length > 0) {
|
|
89
|
+
return CommandResult.CommandResult.validationFailed(validationErrors);
|
|
90
|
+
}
|
|
91
|
+
return CommandResult.CommandResult.empty;
|
|
92
|
+
}
|
|
82
93
|
buildPayload() {
|
|
83
94
|
const payload = {};
|
|
84
95
|
this.propertyDescriptors.forEach(propertyDescriptor => {
|
|
@@ -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 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":["Globals","CommandResult","UrlHelpers","ValidationResult","Val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AC,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC;AAC3D,QAAA,CAAC,CAAC;IACN;AACH;;;;"}
|
|
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":["Globals","CommandResult","UrlHelpers","ValidationResult","ValidationResultSeverity","joinPaths","JsonSerializer"],"mappings":";;;;;;;;;;MAuBsB,OAAO,CAAA;AAsBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AArB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAEV,KAAK,GAAa,EAAE;IAIrB,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EAAA;QAAhF,IAAA,CAAA,aAAa,GAAb,aAAa;QAAiC,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QACxF,IAAI,CAAC,aAAa,GAAGA,eAAO,CAAC,YAAY,IAAI,EAAE;QAC/C,IAAI,CAAC,YAAY,GAAGA,eAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAGA,eAAO,CAAC,MAAM,IAAI,EAAE;QACnC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ly propertyDescriptors: PropertyDescriptor[];
|
|
10
10
|
execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>>;
|
|
11
11
|
validate(): Promise<CommandResult<TCommandResponse>>;
|
|
12
|
+
validateClientSide(): CommandResult<TCommandResponse>;
|
|
12
13
|
clear(): void;
|
|
13
14
|
setInitialValues(values: TCommandContent): void;
|
|
14
15
|
setInitialValuesFromCurrentValues(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ICommand.d.ts","sourceRoot":"","sources":["../../../commands/ICommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAKlF,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAKzD,MAAM,WAAW,QAAQ,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,SAAQ,gBAAgB;IAInG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAKvB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAKzB,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAQnD,OAAO,CAAC,eAAe,CAAC,EAAE,wBAAwB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;IASxH,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ICommand.d.ts","sourceRoot":"","sources":["../../../commands/ICommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAKlF,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAKzD,MAAM,WAAW,QAAQ,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,SAAQ,gBAAgB;IAInG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAKvB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAKzB,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAQnD,OAAO,CAAC,eAAe,CAAC,EAAE,wBAAwB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;IASxH,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAUrD,kBAAkB,IAAI,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAMtD,KAAK,IAAI,IAAI,CAAC;IAMd,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IAKhD,iCAAiC,IAAI,IAAI,CAAC;IAK1C,aAAa,IAAI,IAAI,CAAC;IAKtB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAM7B,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAOxC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_client_validation_failure.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating_client_side/with_client_validation_failure.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_client_validation_passing.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating_client_side/with_client_validation_passing.ts"],"names":[],"mappings":"AAMA,OAAO,2CAA2C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_required_property_missing.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating_client_side/with_required_property_missing.ts"],"names":[],"mappings":""}
|
|
@@ -27,6 +27,7 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
|
|
|
27
27
|
setHttpHeadersCallback(callback: GetHttpHeaders): void;
|
|
28
28
|
execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>>;
|
|
29
29
|
validate(): Promise<CommandResult<TCommandResponse>>;
|
|
30
|
+
validateClientSide(): CommandResult<TCommandResponse>;
|
|
30
31
|
private buildPayload;
|
|
31
32
|
private validateRequiredProperties;
|
|
32
33
|
private filterValidationResultsBySeverity;
|
|
@@ -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,YAAW,QAA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,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKhD,OAAO,CAAC,eAAe,CAAC,EAAE,wBAAwB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IA2BvH,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAwB1D,kBAAkB,IAAI,aAAa,CAAC,gBAAgB,CAAC;IAcrD,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,0BAA0B;IAkBlC,OAAO,CAAC,iCAAiC;IAUzC,OAAO,CAAC,YAAY;YAuBN,cAAc;IA+B5B,KAAK,IAAI,IAAI;IAUb,gBAAgB,CAAC,MAAM,EAAE,eAAe;IAYxC,iCAAiC;IAWjC,aAAa,IAAI,IAAI;IAQrB,IAAI,UAAU,YAEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM;IAehC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;IAO5D,OAAO,CAAC,gBAAgB;CAM3B"}
|
|
@@ -77,6 +77,17 @@ class Command {
|
|
|
77
77
|
actualRoute = `${actualRoute}/validate`;
|
|
78
78
|
return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');
|
|
79
79
|
}
|
|
80
|
+
validateClientSide() {
|
|
81
|
+
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
82
|
+
if (clientValidationErrors.length > 0) {
|
|
83
|
+
return CommandResult.validationFailed(clientValidationErrors);
|
|
84
|
+
}
|
|
85
|
+
const validationErrors = this.validateRequiredProperties();
|
|
86
|
+
if (validationErrors.length > 0) {
|
|
87
|
+
return CommandResult.validationFailed(validationErrors);
|
|
88
|
+
}
|
|
89
|
+
return CommandResult.empty;
|
|
90
|
+
}
|
|
80
91
|
buildPayload() {
|
|
81
92
|
const payload = {};
|
|
82
93
|
this.propertyDescriptors.forEach(propertyDescriptor => {
|
|
@@ -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 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":[],"mappings":";;;;;;;;MAuBsB,OAAO,CAAA;AAsBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AArB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAEV,KAAK,GAAa,EAAE;IAIrB,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EAAA;QAAhF,IAAA,CAAA,aAAa,GAAb,aAAa;QAAiC,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QACxF,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE;QAC/C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE;QACnC,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AAChC,QAAA,IAAI,CAAC,aAAa,GAAG,YAAY;IACrC;AAGA,IAAA,cAAc,CAAC,WAAmB,EAAA;AAC9B,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;IACnC;AAGA,IAAA,SAAS,CAAC,MAAc,EAAA;AACpB,QAAA,IAAI,CAAC,OAAO,GAAG,MAAM;IACzB;AAGA,IAAA,sBAAsB,CAAC,QAAwB,EAAA;AAC3C,QAAA,IAAI,CAAC,oBAAoB,GAAG,QAAQ;IACxC;AAGA,IAAA,MAAM,OAAO,CAAC,eAA0C,EAAE,cAAwB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C,IAAI,CAAC,kBAAkB,IAAG;AAClE,YAAA,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI;YACxC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC;AAC3D,QAAA,CAAC,CAAC;IACN;AACH;;;;"}
|
|
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":[],"mappings":";;;;;;;;MAuBsB,OAAO,CAAA;AAsBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AArB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAEV,KAAK,GAAa,EAAE;IAIrB,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EAAA;QAAhF,IAAA,CAAA,aAAa,GAAb,aAAa;QAAiC,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QACxF,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE;QAC/C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC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
|
readonly propertyDescriptors: PropertyDescriptor[];
|
|
10
10
|
execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>>;
|
|
11
11
|
validate(): Promise<CommandResult<TCommandResponse>>;
|
|
12
|
+
validateClientSide(): CommandResult<TCommandResponse>;
|
|
12
13
|
clear(): void;
|
|
13
14
|
setInitialValues(values: TCommandContent): void;
|
|
14
15
|
setInitialValuesFromCurrentValues(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ICommand.d.ts","sourceRoot":"","sources":["../../../commands/ICommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAKlF,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAKzD,MAAM,WAAW,QAAQ,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,SAAQ,gBAAgB;IAInG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAKvB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAKzB,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAQnD,OAAO,CAAC,eAAe,CAAC,EAAE,wBAAwB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;IASxH,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ICommand.d.ts","sourceRoot":"","sources":["../../../commands/ICommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAKlF,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAKzD,MAAM,WAAW,QAAQ,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,SAAQ,gBAAgB;IAInG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAKvB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAKzB,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAQnD,OAAO,CAAC,eAAe,CAAC,EAAE,wBAAwB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;IASxH,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAUrD,kBAAkB,IAAI,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAMtD,KAAK,IAAI,IAAI,CAAC;IAMd,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IAKhD,iCAAiC,IAAI,IAAI,CAAC;IAK1C,aAAa,IAAI,IAAI,CAAC;IAKtB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAM7B,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAOxC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_client_validation_failure.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating_client_side/with_client_validation_failure.ts"],"names":[],"mappings":""}
|
package/dist/esm/commands/for_Command/when_validating_client_side/with_client_validation_failure.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { a_command_with_validator } from '../given/a_command_with_validator';
|
|
2
|
+
import { given } from '../../../given';
|
|
3
|
+
describe("when validating client side with client validation failure", given(a_command_with_validator, context => {
|
|
4
|
+
let result;
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
context.command.email = '';
|
|
7
|
+
context.command.age = 25;
|
|
8
|
+
result = context.command.validateClientSide();
|
|
9
|
+
});
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
context.fetchStub.restore();
|
|
12
|
+
});
|
|
13
|
+
it("should not call server", () => context.fetchStub.called.should.be.false);
|
|
14
|
+
it("should return invalid result", () => result.isValid.should.be.false);
|
|
15
|
+
it("should have validation error", () => result.validationResults.length.should.equal(1));
|
|
16
|
+
it("should have error for email property", () => result.validationResults[0].members[0].should.equal('email'));
|
|
17
|
+
}));
|
|
18
|
+
//# sourceMappingURL=with_client_validation_failure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_client_validation_failure.js","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating_client_side/with_client_validation_failure.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,QAAQ,CAAC,4DAA4D,EAAE,KAAK,CAAC,wBAAwB,EAAE,OAAO,CAAC,EAAE;IAC7G,IAAI,MAA6B,CAAC;IAElC,UAAU,CAAC,GAAG,EAAE;QACZ,OAAO,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC;QAC3B,OAAO,CAAC,OAAO,CAAC,GAAG,GAAG,EAAE,CAAC;QAEzB,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC7E,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACzE,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1F,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AACnH,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_client_validation_passing.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating_client_side/with_client_validation_passing.ts"],"names":[],"mappings":"AAMA,OAAO,2CAA2C,CAAC"}
|
package/dist/esm/commands/for_Command/when_validating_client_side/with_client_validation_passing.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Command } from '../../Command';
|
|
2
|
+
import { CommandValidator } from '../../CommandValidator';
|
|
3
|
+
import '../../../validation/RuleBuilderExtensions';
|
|
4
|
+
import { createFetchHelper } from '../../../helpers/fetchHelper';
|
|
5
|
+
class TestCommandValidator extends CommandValidator {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.ruleFor(c => c.email).notEmpty().emailAddress();
|
|
9
|
+
this.ruleFor(c => c.age).greaterThanOrEqual(18);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class TestCommand extends Command {
|
|
13
|
+
route = '/api/test';
|
|
14
|
+
validation = new TestCommandValidator();
|
|
15
|
+
propertyDescriptors = [];
|
|
16
|
+
email = '';
|
|
17
|
+
age = 0;
|
|
18
|
+
constructor() {
|
|
19
|
+
super(Object, false);
|
|
20
|
+
}
|
|
21
|
+
get requestParameters() {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
get properties() {
|
|
25
|
+
return ['email', 'age'];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
describe("when validating client side with client validation passing", () => {
|
|
29
|
+
let command;
|
|
30
|
+
let fetchStub;
|
|
31
|
+
let fetchHelper;
|
|
32
|
+
let result;
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
command = new TestCommand();
|
|
35
|
+
command.setOrigin('http://localhost');
|
|
36
|
+
command.email = 'test@example.com';
|
|
37
|
+
command.age = 25;
|
|
38
|
+
fetchHelper = createFetchHelper();
|
|
39
|
+
fetchStub = fetchHelper.stubFetch();
|
|
40
|
+
result = command.validateClientSide();
|
|
41
|
+
});
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
fetchHelper.restore();
|
|
44
|
+
});
|
|
45
|
+
it("should not call server", () => fetchStub.called.should.be.false);
|
|
46
|
+
it("should return valid result", () => result.isValid.should.be.true);
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=with_client_validation_passing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_client_validation_passing.js","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating_client_side/with_client_validation_passing.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,2CAA2C,CAAC;AAGnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAOjE,MAA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C;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,WAAW,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACrE,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_required_property_missing.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating_client_side/with_required_property_missing.ts"],"names":[],"mappings":""}
|