@cratis/arc 19.0.1 → 19.0.2
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 +9 -1
- package/commands/for_Command/when_executing/and_command_route_not_found.ts +2 -2
- package/commands/for_Command/when_executing/and_fetch_throws_exception.ts +3 -3
- package/commands/for_Command/when_executing/with_client_validation_failing.ts +5 -5
- package/commands/for_Command/when_executing/with_client_validation_failure_and_custom_message.ts +5 -5
- package/commands/for_Command/when_executing/with_client_validation_passing.ts +1 -1
- package/commands/for_Command/when_executing/with_command_properties.ts +1 -1
- package/commands/for_Command/when_executing/with_custom_http_headers.ts +2 -2
- package/commands/for_Command/when_executing/with_microservice_header.ts +1 -1
- package/commands/for_Command/when_executing/with_missing_required_property.ts +7 -7
- package/commands/for_Command/when_executing/with_origin_and_api_base_path.ts +1 -1
- package/commands/for_Command/when_executing/with_route_parameters.ts +2 -2
- package/commands/for_Command/when_executing/with_successful_response.ts +5 -5
- package/commands/for_Command/when_validating/and_fetch_throws_exception.ts +3 -3
- package/commands/for_Command/when_validating/and_validation_endpoint_not_found.ts +2 -2
- package/commands/for_Command/when_validating/does_not_update_initial_values.ts +1 -1
- package/commands/for_Command/when_validating/with_client_validation_failure.ts +4 -4
- package/commands/for_Command/when_validating/with_client_validation_passing.ts +3 -3
- package/commands/for_Command/when_validating/with_required_property_missing.ts +4 -4
- package/commands/for_Command/when_validating/with_route_parameters.ts +61 -0
- package/commands/for_Command/when_validating/with_successful_response.ts +3 -3
- package/commands/for_Command/when_validating/with_validation_errors.ts +3 -3
- package/dist/cjs/commands/Command.d.ts.map +1 -1
- package/dist/cjs/commands/Command.js +7 -1
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/cjs/commands/for_Command/when_validating/with_route_parameters.d.ts +2 -0
- package/dist/cjs/commands/for_Command/when_validating/with_route_parameters.d.ts.map +1 -0
- package/dist/esm/commands/Command.d.ts.map +1 -1
- package/dist/esm/commands/Command.js +7 -1
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/for_Command/when_executing/and_command_route_not_found.js +2 -2
- package/dist/esm/commands/for_Command/when_executing/and_fetch_throws_exception.js +3 -3
- package/dist/esm/commands/for_Command/when_executing/with_client_validation_failing.js +5 -5
- package/dist/esm/commands/for_Command/when_executing/with_client_validation_failure_and_custom_message.js +5 -5
- package/dist/esm/commands/for_Command/when_executing/with_client_validation_passing.js +1 -1
- package/dist/esm/commands/for_Command/when_executing/with_command_properties.js +1 -1
- package/dist/esm/commands/for_Command/when_executing/with_custom_http_headers.js +2 -2
- package/dist/esm/commands/for_Command/when_executing/with_microservice_header.js +1 -1
- package/dist/esm/commands/for_Command/when_executing/with_missing_required_property.js +7 -7
- package/dist/esm/commands/for_Command/when_executing/with_origin_and_api_base_path.js +1 -1
- package/dist/esm/commands/for_Command/when_executing/with_route_parameters.js +2 -2
- package/dist/esm/commands/for_Command/when_executing/with_successful_response.js +5 -5
- package/dist/esm/commands/for_Command/when_validating/and_fetch_throws_exception.js +3 -3
- package/dist/esm/commands/for_Command/when_validating/and_validation_endpoint_not_found.js +2 -2
- package/dist/esm/commands/for_Command/when_validating/does_not_update_initial_values.js +1 -1
- package/dist/esm/commands/for_Command/when_validating/with_client_validation_failure.js +4 -4
- package/dist/esm/commands/for_Command/when_validating/with_client_validation_passing.js +3 -3
- package/dist/esm/commands/for_Command/when_validating/with_required_property_missing.js +4 -4
- package/dist/esm/commands/for_Command/when_validating/with_route_parameters.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_validating/with_route_parameters.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_validating/with_route_parameters.js +51 -0
- package/dist/esm/commands/for_Command/when_validating/with_route_parameters.js.map +1 -0
- package/dist/esm/commands/for_Command/when_validating/with_successful_response.js +3 -3
- package/dist/esm/commands/for_Command/when_validating/with_validation_errors.js +3 -3
- package/dist/esm/for_UrlHelpers/when_creating_url_from/with_base_path_ending_with_slash.js +3 -3
- package/dist/esm/for_UrlHelpers/when_creating_url_from/with_empty_origin.js +2 -2
- package/dist/esm/for_UrlHelpers/when_creating_url_from/with_null_or_undefined_origin.js +4 -4
- package/dist/esm/for_UrlHelpers/when_creating_url_from/with_relative_route.js +3 -3
- package/dist/esm/for_UrlHelpers/when_creating_url_from/with_valid_parameters.js +3 -3
- package/dist/esm/for_UrlHelpers/when_creating_url_from/without_document_object.js +1 -1
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_api_base_path_set.js +1 -1
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_globals_api_base_path.js +1 -1
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_origin_set.js +3 -3
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/without_api_base_path.js +1 -1
- package/dist/esm/queries/for_QueryFor/when_performing/with_client_validation_failing.js +4 -4
- package/dist/esm/queries/for_QueryFor/when_performing/with_client_validation_failure_and_custom_message.js +5 -5
- package/dist/esm/queries/for_QueryFor/when_performing/with_client_validation_passing.js +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/validation/for_Validator/when_defining_multiple_rules_for_same_property.js +2 -2
- package/dist/esm/validation/for_Validator/when_using_custom_error_message.js +1 -1
- package/dist/esm/validation/for_Validator/when_validating/with_all_rules_passing.js +2 -2
- package/dist/esm/validation/for_Validator/when_validating/with_multiple_rules_failing.js +3 -3
- package/dist/esm/validation/for_Validator/when_validating/with_one_rule_failing.js +3 -3
- package/dist/esm/validation/rules/for_EmailRule/when_validating/with_empty_string.js +1 -1
- package/dist/esm/validation/rules/for_EmailRule/when_validating/with_invalid_email.js +1 -1
- package/dist/esm/validation/rules/for_EmailRule/when_validating/with_valid_email.js +1 -1
- package/dist/esm/validation/rules/for_GreaterThanOrEqualRule/when_validating/with_value_equal_to_threshold.js +1 -1
- package/dist/esm/validation/rules/for_GreaterThanRule/when_validating/with_value_equal_to_threshold.js +1 -1
- package/dist/esm/validation/rules/for_GreaterThanRule/when_validating/with_value_greater_than_threshold.js +1 -1
- package/dist/esm/validation/rules/for_GreaterThanRule/when_validating/with_value_less_than_threshold.js +2 -2
- package/dist/esm/validation/rules/for_LengthRule/when_validating/with_string_longer_than_maximum.js +1 -1
- package/dist/esm/validation/rules/for_LengthRule/when_validating/with_string_shorter_than_minimum.js +1 -1
- package/dist/esm/validation/rules/for_LengthRule/when_validating/with_string_within_range.js +1 -1
- package/dist/esm/validation/rules/for_LessThanRule/when_validating/with_value_less_than_threshold.js +1 -1
- package/dist/esm/validation/rules/for_MaxLengthRule/when_validating/with_string_equal_to_maximum.js +1 -1
- package/dist/esm/validation/rules/for_MaxLengthRule/when_validating/with_string_longer_than_maximum.js +2 -2
- package/dist/esm/validation/rules/for_MinLengthRule/when_validating/with_string_equal_to_minimum.js +1 -1
- package/dist/esm/validation/rules/for_MinLengthRule/when_validating/with_string_longer_than_minimum.js +1 -1
- package/dist/esm/validation/rules/for_MinLengthRule/when_validating/with_string_shorter_than_minimum.js +2 -2
- package/dist/esm/validation/rules/for_NotEmptyRule/when_setting_custom_message.js +1 -1
- package/dist/esm/validation/rules/for_NotEmptyRule/when_validating/with_empty_array.js +1 -1
- package/dist/esm/validation/rules/for_NotEmptyRule/when_validating/with_empty_string.js +1 -1
- package/dist/esm/validation/rules/for_NotEmptyRule/when_validating/with_non_empty_array.js +1 -1
- package/dist/esm/validation/rules/for_NotEmptyRule/when_validating/with_null_value.js +4 -4
- package/dist/esm/validation/rules/for_NotEmptyRule/when_validating/with_undefined_value.js +2 -2
- package/dist/esm/validation/rules/for_NotEmptyRule/when_validating/with_valid_string.js +1 -1
- package/dist/esm/validation/rules/for_NotEmptyRule/when_validating/with_whitespace_string.js +1 -1
- package/for_UrlHelpers/when_creating_url_from/with_base_path_ending_with_slash.ts +3 -3
- package/for_UrlHelpers/when_creating_url_from/with_empty_origin.ts +2 -2
- package/for_UrlHelpers/when_creating_url_from/with_null_or_undefined_origin.ts +4 -4
- package/for_UrlHelpers/when_creating_url_from/with_relative_route.ts +3 -3
- package/for_UrlHelpers/when_creating_url_from/with_valid_parameters.ts +3 -3
- package/for_UrlHelpers/when_creating_url_from/without_document_object.ts +1 -1
- package/identity/for_IdentityProvider/when_refreshing/with_api_base_path_set.ts +1 -1
- package/identity/for_IdentityProvider/when_refreshing/with_globals_api_base_path.ts +1 -1
- package/identity/for_IdentityProvider/when_refreshing/with_origin_set.ts +3 -3
- package/identity/for_IdentityProvider/when_refreshing/without_api_base_path.ts +1 -1
- package/package.json +1 -1
- package/queries/for_QueryFor/when_performing/with_client_validation_failing.ts +4 -4
- package/queries/for_QueryFor/when_performing/with_client_validation_failure_and_custom_message.ts +5 -5
- package/queries/for_QueryFor/when_performing/with_client_validation_passing.ts +1 -1
- package/validation/for_Validator/when_defining_multiple_rules_for_same_property.ts +2 -2
- package/validation/for_Validator/when_using_custom_error_message.ts +1 -1
- package/validation/for_Validator/when_validating/with_all_rules_passing.ts +2 -2
- package/validation/for_Validator/when_validating/with_multiple_rules_failing.ts +3 -3
- package/validation/for_Validator/when_validating/with_one_rule_failing.ts +3 -3
- package/validation/rules/for_EmailRule/when_validating/with_empty_string.ts +1 -1
- package/validation/rules/for_EmailRule/when_validating/with_invalid_email.ts +1 -1
- package/validation/rules/for_EmailRule/when_validating/with_valid_email.ts +1 -1
- package/validation/rules/for_GreaterThanOrEqualRule/when_validating/with_value_equal_to_threshold.ts +1 -1
- package/validation/rules/for_GreaterThanRule/when_validating/with_value_equal_to_threshold.ts +1 -1
- package/validation/rules/for_GreaterThanRule/when_validating/with_value_greater_than_threshold.ts +1 -1
- package/validation/rules/for_GreaterThanRule/when_validating/with_value_less_than_threshold.ts +2 -2
- package/validation/rules/for_LengthRule/when_validating/with_string_longer_than_maximum.ts +1 -1
- package/validation/rules/for_LengthRule/when_validating/with_string_shorter_than_minimum.ts +1 -1
- package/validation/rules/for_LengthRule/when_validating/with_string_within_range.ts +1 -1
- package/validation/rules/for_LessThanRule/when_validating/with_value_less_than_threshold.ts +1 -1
- package/validation/rules/for_MaxLengthRule/when_validating/with_string_equal_to_maximum.ts +1 -1
- package/validation/rules/for_MaxLengthRule/when_validating/with_string_longer_than_maximum.ts +2 -2
- package/validation/rules/for_MinLengthRule/when_validating/with_string_equal_to_minimum.ts +1 -1
- package/validation/rules/for_MinLengthRule/when_validating/with_string_longer_than_minimum.ts +1 -1
- package/validation/rules/for_MinLengthRule/when_validating/with_string_shorter_than_minimum.ts +2 -2
- package/validation/rules/for_NotEmptyRule/when_setting_custom_message.ts +1 -1
- package/validation/rules/for_NotEmptyRule/when_validating/with_empty_array.ts +1 -1
- package/validation/rules/for_NotEmptyRule/when_validating/with_empty_string.ts +1 -1
- package/validation/rules/for_NotEmptyRule/when_validating/with_non_empty_array.ts +1 -1
- package/validation/rules/for_NotEmptyRule/when_validating/with_null_value.ts +4 -4
- package/validation/rules/for_NotEmptyRule/when_validating/with_undefined_value.ts +2 -2
- package/validation/rules/for_NotEmptyRule/when_validating/with_valid_string.ts +1 -1
- package/validation/rules/for_NotEmptyRule/when_validating/with_whitespace_string.ts +1 -1
package/commands/Command.ts
CHANGED
|
@@ -106,7 +106,15 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
106
106
|
return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
let actualRoute = this.route;
|
|
110
|
+
|
|
111
|
+
if (this.requestParameters && this.requestParameters.length > 0) {
|
|
112
|
+
const payload = this.buildPayload();
|
|
113
|
+
const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);
|
|
114
|
+
actualRoute = route;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
actualRoute = `${actualRoute}/validate`;
|
|
110
118
|
return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');
|
|
111
119
|
}
|
|
112
120
|
|
|
@@ -21,6 +21,6 @@ describe("when executing and command route not found", given(a_command, context
|
|
|
21
21
|
context.fetchStub.restore();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it("
|
|
25
|
-
it("
|
|
24
|
+
it("should return failed result", () => result.isSuccess.should.be.false);
|
|
25
|
+
it("should have exception messages", () => (result.exceptionMessages.length > 0).should.be.true);
|
|
26
26
|
}));
|
|
@@ -18,7 +18,7 @@ describe("when executing and fetch throws exception", given(a_command, context =
|
|
|
18
18
|
context.fetchStub.restore();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it("
|
|
22
|
-
it("
|
|
23
|
-
it("
|
|
21
|
+
it("should return failed result", () => result.isSuccess.should.be.false);
|
|
22
|
+
it("should include error message", () => result.exceptionMessages[0].should.contain('Error during server call'));
|
|
23
|
+
it("should have exception messages", () => (result.exceptionMessages.length > 0).should.be.true);
|
|
24
24
|
}));
|
|
@@ -47,23 +47,23 @@ describe("when executing with client validation failing", () => {
|
|
|
47
47
|
result = await command.execute();
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
it("
|
|
50
|
+
it("should not be success", () => {
|
|
51
51
|
result.isSuccess.should.be.false;
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it("
|
|
54
|
+
it("should not be valid", () => {
|
|
55
55
|
result.isValid.should.be.false;
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
it("
|
|
58
|
+
it("should have validation results", () => {
|
|
59
59
|
result.validationResults.should.not.be.empty;
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
it("
|
|
62
|
+
it("should have error for name", () => {
|
|
63
63
|
result.validationResults.some(r => r.members.includes('name')).should.be.true;
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
it("
|
|
66
|
+
it("should have error for age", () => {
|
|
67
67
|
result.validationResults.some(r => r.members.includes('age')).should.be.true;
|
|
68
68
|
});
|
|
69
69
|
});
|
package/commands/for_Command/when_executing/with_client_validation_failure_and_custom_message.ts
CHANGED
|
@@ -21,9 +21,9 @@ describe("when executing with client validation failure and custom message", giv
|
|
|
21
21
|
context.fetchStub.restore();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it("
|
|
25
|
-
it("
|
|
26
|
-
it("
|
|
27
|
-
it("
|
|
28
|
-
it("
|
|
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 custom error message", () => result.validationResults[0].message.should.equal('Email is required'));
|
|
28
|
+
it("should have error for email property", () => result.validationResults[0].members[0].should.equal('email'));
|
|
29
29
|
}));
|
|
@@ -32,7 +32,7 @@ describe("when executing with command properties", given(a_command, context => {
|
|
|
32
32
|
context.fetchStub.restore();
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
it("
|
|
35
|
+
it("should include command properties in body", () => {
|
|
36
36
|
const call = context.fetchStub.getCall(0);
|
|
37
37
|
const body = JSON.parse(call.args[1].body);
|
|
38
38
|
body.someProperty.should.equal('test value');
|
|
@@ -50,13 +50,13 @@ describe("when executing with custom http headers", given(class {
|
|
|
50
50
|
context.fetchStub.restore();
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
it("
|
|
53
|
+
it("should include custom headers", () => {
|
|
54
54
|
const call = context.fetchStub.getCall(0);
|
|
55
55
|
call.args[1].headers['X-Custom-Header'].should.equal('custom-value');
|
|
56
56
|
call.args[1].headers['Authorization'].should.equal('Bearer token123');
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
it("
|
|
59
|
+
it("should include default headers", () => {
|
|
60
60
|
const call = context.fetchStub.getCall(0);
|
|
61
61
|
call.args[1].headers['Content-Type'].should.equal('application/json');
|
|
62
62
|
call.args[1].headers['Accept'].should.equal('application/json');
|
|
@@ -41,7 +41,7 @@ describe("when executing with microservice header", given(class extends a_comman
|
|
|
41
41
|
Globals.microserviceHttpHeader = context.originalMicroserviceHeader;
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
it("
|
|
44
|
+
it("should include microservice header", () => {
|
|
45
45
|
const call = context.fetchStub.getCall(0);
|
|
46
46
|
call.args[1].headers['X-Microservice-Id'].should.equal('my-microservice');
|
|
47
47
|
});
|
|
@@ -22,11 +22,11 @@ describe("when executing with missing required property", given(class extends a_
|
|
|
22
22
|
context.fetchStub.restore();
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
it("
|
|
26
|
-
it("
|
|
27
|
-
it("
|
|
28
|
-
it("
|
|
29
|
-
it("
|
|
30
|
-
it("
|
|
31
|
-
it("
|
|
25
|
+
it("should not call fetch", () => context.fetchStub.called.should.be.false);
|
|
26
|
+
it("should return failed result", () => result.isSuccess.should.be.false);
|
|
27
|
+
it("should return invalid result", () => result.isValid.should.be.false);
|
|
28
|
+
it("should return authorized result", () => result.isAuthorized.should.be.true);
|
|
29
|
+
it("should have validation results", () => result.validationResults.length.should.equal(1));
|
|
30
|
+
it("should have validation message for property", () => result.validationResults[0].message.should.equal('someProperty is required'));
|
|
31
|
+
it("should have validation member for property", () => result.validationResults[0].members[0].should.equal('someProperty'));
|
|
32
32
|
}));
|
|
@@ -46,7 +46,7 @@ describe("when executing with origin and api base path", given(class {
|
|
|
46
46
|
context.fetchHelper.restore();
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
it("
|
|
49
|
+
it("should construct url with origin and base path", () => {
|
|
50
50
|
const call = context.fetchStub.getCall(0);
|
|
51
51
|
const url = call.args[0];
|
|
52
52
|
url.toString().should.contain('https://api.example.com');
|
|
@@ -46,13 +46,13 @@ describe("when executing with route parameters", given(class {
|
|
|
46
46
|
context.fetchHelper.restore();
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
it("
|
|
49
|
+
it("should replace route parameters in url", () => {
|
|
50
50
|
const call = context.fetchStub.getCall(0);
|
|
51
51
|
const url = call.args[0];
|
|
52
52
|
url.toString().should.contain('/api/items/123');
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
it("
|
|
55
|
+
it("should include all properties in body", () => {
|
|
56
56
|
const call = context.fetchStub.getCall(0);
|
|
57
57
|
const body = JSON.parse(call.args[1].body);
|
|
58
58
|
body.id.should.equal('123');
|
|
@@ -32,20 +32,20 @@ describe("when executing with successful response", given(a_command, context =>
|
|
|
32
32
|
context.fetchStub.restore();
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
it("
|
|
35
|
+
it("should call fetch with correct url", () => context.fetchStub.calledOnce.should.be.true);
|
|
36
36
|
|
|
37
|
-
it("
|
|
37
|
+
it("should call fetch with post method", () => {
|
|
38
38
|
const call = context.fetchStub.getCall(0);
|
|
39
39
|
call.args[1].method.should.equal('POST');
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
it("
|
|
42
|
+
it("should call fetch with json headers", () => {
|
|
43
43
|
const call = context.fetchStub.getCall(0);
|
|
44
44
|
call.args[1].headers['Content-Type'].should.equal('application/json');
|
|
45
45
|
call.args[1].headers['Accept'].should.equal('application/json');
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it("
|
|
48
|
+
it("should return command result", () => (result !== null && result !== undefined).should.be.true);
|
|
49
49
|
|
|
50
|
-
it("
|
|
50
|
+
it("should set initial values from current values", () => context.command.hasChanges.should.be.false);
|
|
51
51
|
}));
|
|
@@ -18,7 +18,7 @@ describe("when validating and fetch throws exception", given(a_command, context
|
|
|
18
18
|
context.fetchStub.restore();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it("
|
|
22
|
-
it("
|
|
23
|
-
it("
|
|
21
|
+
it("should return failed result", () => result.isSuccess.should.be.false);
|
|
22
|
+
it("should include error message", () => result.exceptionMessages[0].should.contain('Error during validation call'));
|
|
23
|
+
it("should have exception messages", () => (result.exceptionMessages.length > 0).should.be.true);
|
|
24
24
|
}));
|
|
@@ -21,6 +21,6 @@ describe("when validating and validation endpoint not found", given(a_command, c
|
|
|
21
21
|
context.fetchStub.restore();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it("
|
|
25
|
-
it("
|
|
24
|
+
it("should return failed result", () => result.isSuccess.should.be.false);
|
|
25
|
+
it("should have exception messages", () => (result.exceptionMessages.length > 0).should.be.true);
|
|
26
26
|
}));
|
|
@@ -35,5 +35,5 @@ describe("when validating does not update initial values", given(a_command, cont
|
|
|
35
35
|
context.fetchStub.restore();
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
it("
|
|
38
|
+
it("should still have changes after validation", () => context.command.hasChanges.should.be.true);
|
|
39
39
|
}));
|
|
@@ -19,8 +19,8 @@ describe("when validating with client validation failure", given(a_command_with_
|
|
|
19
19
|
context.fetchStub.restore();
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
it("
|
|
23
|
-
it("
|
|
24
|
-
it("
|
|
25
|
-
it("
|
|
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
26
|
}));
|
|
@@ -68,10 +68,10 @@ describe("when validating with client validation passing", () => {
|
|
|
68
68
|
fetchHelper.restore();
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
it("
|
|
72
|
-
it("
|
|
71
|
+
it("should call server", () => fetchStub.calledOnce.should.be.true);
|
|
72
|
+
it("should call validation endpoint", () => {
|
|
73
73
|
const url = fetchStub.getCall(0).args[0];
|
|
74
74
|
url.toString().should.contain('/api/test/validate');
|
|
75
75
|
});
|
|
76
|
-
it("
|
|
76
|
+
it("should return valid result", () => result.isValid.should.be.true);
|
|
77
77
|
});
|
|
@@ -21,8 +21,8 @@ describe("when validating with required property missing", given(class extends a
|
|
|
21
21
|
context.fetchStub.restore();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it("
|
|
25
|
-
it("
|
|
26
|
-
it("
|
|
27
|
-
it("
|
|
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
28
|
}));
|
|
@@ -0,0 +1,61 @@
|
|
|
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 sinon from 'sinon';
|
|
5
|
+
import { createFetchHelper } from '../../../helpers/fetchHelper';
|
|
6
|
+
import { CommandWithRouteParams } from '../CommandWithRouteParams';
|
|
7
|
+
import { given } from '../../../given';
|
|
8
|
+
|
|
9
|
+
describe("when validating with route parameters", given(class {
|
|
10
|
+
command: CommandWithRouteParams;
|
|
11
|
+
fetchStub: sinon.SinonStub;
|
|
12
|
+
fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
this.command = new CommandWithRouteParams();
|
|
16
|
+
this.command.setOrigin('http://localhost');
|
|
17
|
+
this.command.setApiBasePath('/api');
|
|
18
|
+
this.command.id = '123';
|
|
19
|
+
this.command.name = 'Test Item';
|
|
20
|
+
this.fetchHelper = createFetchHelper();
|
|
21
|
+
this.fetchStub = this.fetchHelper.stubFetch();
|
|
22
|
+
}
|
|
23
|
+
}, context => {
|
|
24
|
+
const responseData = {
|
|
25
|
+
correlationId: '12345678-1234-1234-1234-123456789012',
|
|
26
|
+
isSuccess: true,
|
|
27
|
+
isAuthorized: true,
|
|
28
|
+
isValid: true,
|
|
29
|
+
hasExceptions: false,
|
|
30
|
+
validationResults: [],
|
|
31
|
+
exceptionMessages: [],
|
|
32
|
+
exceptionStackTrace: '',
|
|
33
|
+
response: {}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
beforeEach(async () => {
|
|
37
|
+
context.fetchStub.resolves({
|
|
38
|
+
status: 200,
|
|
39
|
+
json: async () => responseData
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await context.command.validate();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
context.fetchHelper.restore();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should replace route parameters in url and append validate", () => {
|
|
50
|
+
const call = context.fetchStub.getCall(0);
|
|
51
|
+
const url = call.args[0];
|
|
52
|
+
url.toString().should.contain('/api/items/123/validate');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should include all properties in body", () => {
|
|
56
|
+
const call = context.fetchStub.getCall(0);
|
|
57
|
+
const body = JSON.parse(call.args[1].body);
|
|
58
|
+
body.id.should.equal('123');
|
|
59
|
+
body.name.should.equal('Test Item');
|
|
60
|
+
});
|
|
61
|
+
}));
|
|
@@ -32,16 +32,16 @@ describe("when validating with successful response", given(a_command, context =>
|
|
|
32
32
|
context.fetchStub.restore();
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
it("
|
|
35
|
+
it("should call fetch with validate route", () => {
|
|
36
36
|
const call = context.fetchStub.getCall(0);
|
|
37
37
|
const url = call.args[0];
|
|
38
38
|
url.toString().should.contain('/validate');
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
it("
|
|
41
|
+
it("should call fetch with post method", () => {
|
|
42
42
|
const call = context.fetchStub.getCall(0);
|
|
43
43
|
call.args[1].method.should.equal('POST');
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
it("
|
|
46
|
+
it("should return command result", () => (result !== null && result !== undefined).should.be.true);
|
|
47
47
|
}));
|
|
@@ -39,7 +39,7 @@ describe("when validating with validation errors", given(a_command, context => {
|
|
|
39
39
|
context.fetchStub.restore();
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
it("
|
|
43
|
-
it("
|
|
44
|
-
it("
|
|
42
|
+
it("should return invalid result", () => result.isValid.should.be.false);
|
|
43
|
+
it("should not be successful", () => result.isSuccess.should.be.false);
|
|
44
|
+
it("should not update initial values", () => context.command.hasChanges.should.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AE,CAAC;IAE3C,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAkB;gBAOf,aAAa,EAAE,WAAW,YAAS,EAAW,yBAAyB,EAAE,OAAO;IAQrG,eAAe,CAAC,YAAY,EAAE,MAAM;IAKpC,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKzC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKhD,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAyBnD,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAuB1D,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,0BAA0B;IAkBlC,OAAO,CAAC,YAAY;YAeN,cAAc;IA6B5B,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"}
|
|
@@ -67,7 +67,13 @@ class Command {
|
|
|
67
67
|
if (validationErrors.length > 0) {
|
|
68
68
|
return CommandResult.CommandResult.validationFailed(validationErrors);
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
let actualRoute = this.route;
|
|
71
|
+
if (this.requestParameters && this.requestParameters.length > 0) {
|
|
72
|
+
const payload = this.buildPayload();
|
|
73
|
+
const { route } = UrlHelpers.UrlHelpers.replaceRouteParameters(this.route, payload);
|
|
74
|
+
actualRoute = route;
|
|
75
|
+
}
|
|
76
|
+
actualRoute = `${actualRoute}/validate`;
|
|
71
77
|
return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');
|
|
72
78
|
}
|
|
73
79
|
buildPayload() {
|
|
@@ -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 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(): 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 const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');\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 const actualRoute = `${this.route}/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) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null || value === '') {\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 buildHeaders(): 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 return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\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;AAqBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AApB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAKX,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,IA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,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,iBAAiB,CAAC,QAAQ,CAAC;YAC5F;AACJ,QAAA,CAAC,CAAC;IACN;IAGA,iBAAiB,CAAC,QAAyB,EAAE,OAAe,EAAA;AACxD,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;AACjB,YAAA,QAAQ,EAAE,IAAI,OAAO,CAAC,QAAQ,CAAC;AAC/B,YAAA,OAAO,EAAE,IAAI,OAAO,CAAC,OAAO;AAC/B,SAAA,CAAC;IACN;IAEQ,gBAAgB,GAAA;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,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 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(): 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 const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');\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) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null || value === '') {\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 buildHeaders(): 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 return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\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;AAqBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AApB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAKX,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,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,GAAA;AACT,QAAA,MAAM,sBAAsB,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,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AAC;AAC/B,YAAA,OAAO,EAAE,IAAI,OAAO,CAAC,OAAO;AAC/B,SAAA,CAAC;IACN;IAEQ,gBAAgB,GAAA;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,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;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_route_parameters.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating/with_route_parameters.ts"],"names":[],"mappings":""}
|
|
@@ -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;AAYtE,8BAAsB,OAAO,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,YAAW,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAqBzH,QAAQ,CAAC,aAAa,EAAE,WAAW;IAAW,QAAQ,CAAC,yBAAyB,EAAE,OAAO;IApBrG,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,oBAAoB,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,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;IAO5D,OAAO,CAAC,gBAAgB;CAM3B"}
|
|
@@ -65,7 +65,13 @@ class Command {
|
|
|
65
65
|
if (validationErrors.length > 0) {
|
|
66
66
|
return CommandResult.validationFailed(validationErrors);
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
let actualRoute = this.route;
|
|
69
|
+
if (this.requestParameters && this.requestParameters.length > 0) {
|
|
70
|
+
const payload = this.buildPayload();
|
|
71
|
+
const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);
|
|
72
|
+
actualRoute = route;
|
|
73
|
+
}
|
|
74
|
+
actualRoute = `${actualRoute}/validate`;
|
|
69
75
|
return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');
|
|
70
76
|
}
|
|
71
77
|
buildPayload() {
|
|
@@ -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 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(): 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 const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');\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 const actualRoute = `${this.route}/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) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null || value === '') {\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 buildHeaders(): 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 return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\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;AAqBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AApB3D,IAAA,aAAa;AACb,IAAA,YAA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I,CAAC,UAAU,CAAC,OAAO,CAAC,iBAAiB,IAAG;YACxC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,QAAQ,CAAC,KAAK,EAAE;YACnD,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE;AACjD,YAAA,IAAI,QAAQ,IAAI,OAAO,EAAE;AACrB,gBAAA,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;YACpC;iBAAO;gBACH,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,iBAAiB,CAAC,QAAQ,CAAC;YAC5F;AACJ,QAAA,CAAC,CAAC;IACN;IAGA,iBAAiB,CAAC,QAAyB,EAAE,OAAe,EAAA;AACxD,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;AACjB,YAAA,QAAQ,EAAE,IAAI,OAAO,CAAC,QAAQ,CAAC;AAC/B,YAAA,OAAO,EAAE,IAAI,OAAO,CAAC,OAAO;AAC/B,SAAA,CAAC;IACN;IAEQ,gBAAgB,GAAA;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,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 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(): 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 const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');\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) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null || value === '') {\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 buildHeaders(): 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 return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\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;AAqBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AApB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAKX,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;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