@cratis/arc 20.43.5 → 20.43.7
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 +1 -1
- package/commands/for_Command/when_executing/with_empty_required_string_property.ts +47 -0
- package/commands/for_Command/when_executing/with_null_required_property.ts +29 -0
- package/commands/for_Command/when_validating/with_empty_required_string_property.ts +48 -0
- package/commands/for_Command/when_validating/with_null_required_property.ts +29 -0
- package/dist/cjs/commands/Command.js +1 -1
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/cjs/commands/for_Command/when_executing/with_empty_required_string_property.d.ts +2 -0
- package/dist/cjs/commands/for_Command/when_executing/with_empty_required_string_property.d.ts.map +1 -0
- package/dist/cjs/commands/for_Command/when_executing/with_null_required_property.d.ts +2 -0
- package/dist/cjs/commands/for_Command/when_executing/with_null_required_property.d.ts.map +1 -0
- package/dist/cjs/commands/for_Command/when_validating/with_empty_required_string_property.d.ts +2 -0
- package/dist/cjs/commands/for_Command/when_validating/with_empty_required_string_property.d.ts.map +1 -0
- package/dist/cjs/commands/for_Command/when_validating/with_null_required_property.d.ts +2 -0
- package/dist/cjs/commands/for_Command/when_validating/with_null_required_property.d.ts.map +1 -0
- package/dist/esm/commands/Command.js +1 -1
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/for_Command/when_executing/with_empty_required_string_property.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/with_empty_required_string_property.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_empty_required_string_property.js +39 -0
- package/dist/esm/commands/for_Command/when_executing/with_empty_required_string_property.js.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_null_required_property.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/with_null_required_property.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_null_required_property.js +22 -0
- package/dist/esm/commands/for_Command/when_executing/with_null_required_property.js.map +1 -0
- package/dist/esm/commands/for_Command/when_validating/with_empty_required_string_property.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_validating/with_empty_required_string_property.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_validating/with_empty_required_string_property.js +40 -0
- package/dist/esm/commands/for_Command/when_validating/with_empty_required_string_property.js.map +1 -0
- package/dist/esm/commands/for_Command/when_validating/with_null_required_property.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_validating/with_null_required_property.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_validating/with_null_required_property.js +22 -0
- package/dist/esm/commands/for_Command/when_validating/with_null_required_property.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/commands/Command.ts
CHANGED
|
@@ -135,7 +135,7 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
135
135
|
this.propertyDescriptors.forEach(propertyDescriptor => {
|
|
136
136
|
if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {
|
|
137
137
|
const value = this[propertyDescriptor.name];
|
|
138
|
-
if (value === undefined || value === null
|
|
138
|
+
if (value === undefined || value === null) {
|
|
139
139
|
validationErrors.push(new ValidationResult(
|
|
140
140
|
ValidationResultSeverity.Error,
|
|
141
141
|
`${propertyDescriptor.name} is required`,
|
|
@@ -0,0 +1,47 @@
|
|
|
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 executing with empty required string property", given(class extends a_command {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.command.someProperty = '';
|
|
12
|
+
}
|
|
13
|
+
}, context => {
|
|
14
|
+
let result: CommandResult<object>;
|
|
15
|
+
const responseData = {
|
|
16
|
+
correlationId: '12345678-1234-1234-1234-123456789012',
|
|
17
|
+
isSuccess: true,
|
|
18
|
+
isAuthorized: true,
|
|
19
|
+
isValid: true,
|
|
20
|
+
hasExceptions: false,
|
|
21
|
+
validationResults: [],
|
|
22
|
+
exceptionMessages: [],
|
|
23
|
+
exceptionStackTrace: '',
|
|
24
|
+
response: {}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
beforeEach(async () => {
|
|
28
|
+
context.fetchStub.resolves({
|
|
29
|
+
status: 200,
|
|
30
|
+
json: async () => responseData
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
result = await context.command.execute();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
context.fetchStub.restore();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should call fetch", () => context.fetchStub.calledOnce.should.be.true);
|
|
41
|
+
it("should return valid result", () => result.isValid.should.be.true);
|
|
42
|
+
it("should send empty string value", () => {
|
|
43
|
+
const call = context.fetchStub.getCall(0);
|
|
44
|
+
const body = JSON.parse(call.args[1].body);
|
|
45
|
+
body.someProperty.should.equal('');
|
|
46
|
+
});
|
|
47
|
+
}));
|
|
@@ -0,0 +1,29 @@
|
|
|
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 executing with null required property", given(class extends a_command {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.command.someProperty = null as unknown as string;
|
|
12
|
+
}
|
|
13
|
+
}, context => {
|
|
14
|
+
let result: CommandResult<object>;
|
|
15
|
+
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
result = await context.command.execute();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
context.fetchStub.restore();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should not call fetch", () => 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 validation message for property", () => result.validationResults[0].message.should.equal('someProperty is required'));
|
|
28
|
+
it("should have validation member for property", () => result.validationResults[0].members[0].should.equal('someProperty'));
|
|
29
|
+
}));
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { given } from '../../../given';
|
|
5
|
+
import { CommandResult } from '../../CommandResult';
|
|
6
|
+
import { a_command } from '../given/a_command';
|
|
7
|
+
|
|
8
|
+
describe("when validating with empty required string property", given(class extends a_command {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.command.someProperty = '';
|
|
12
|
+
}
|
|
13
|
+
}, context => {
|
|
14
|
+
let result: CommandResult<object>;
|
|
15
|
+
const responseData = {
|
|
16
|
+
correlationId: '12345678-1234-1234-1234-123456789012',
|
|
17
|
+
isSuccess: true,
|
|
18
|
+
isAuthorized: true,
|
|
19
|
+
isValid: true,
|
|
20
|
+
hasExceptions: false,
|
|
21
|
+
validationResults: [],
|
|
22
|
+
exceptionMessages: [],
|
|
23
|
+
exceptionStackTrace: '',
|
|
24
|
+
response: {}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
beforeEach(async () => {
|
|
28
|
+
context.fetchStub.resolves({
|
|
29
|
+
status: 200,
|
|
30
|
+
json: async () => responseData
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
result = await context.command.validate();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
context.fetchStub.restore();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should call server", () => context.fetchStub.calledOnce.should.be.true);
|
|
41
|
+
it("should call validation endpoint", () => context.fetchStub.getCall(0).args[0].toString().should.equal('http://localhost/api/test-route/validate'));
|
|
42
|
+
it("should return valid result", () => result.isValid.should.be.true);
|
|
43
|
+
it("should send empty string value", () => {
|
|
44
|
+
const call = context.fetchStub.getCall(0);
|
|
45
|
+
const body = JSON.parse(call.args[1].body);
|
|
46
|
+
body.someProperty.should.equal('');
|
|
47
|
+
});
|
|
48
|
+
}));
|
|
@@ -0,0 +1,29 @@
|
|
|
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 with null required property", given(class extends a_command {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.command.someProperty = null as unknown as string;
|
|
12
|
+
}
|
|
13
|
+
}, context => {
|
|
14
|
+
let result: CommandResult<object>;
|
|
15
|
+
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
result = await context.command.validate();
|
|
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 validation message for property", () => result.validationResults[0].message.should.equal('someProperty is required'));
|
|
28
|
+
it("should have validation member for property", () => result.validationResults[0].members[0].should.equal('someProperty'));
|
|
29
|
+
}));
|
|
@@ -92,7 +92,7 @@ class Command {
|
|
|
92
92
|
this.propertyDescriptors.forEach(propertyDescriptor => {
|
|
93
93
|
if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {
|
|
94
94
|
const value = this[propertyDescriptor.name];
|
|
95
|
-
if (value === undefined || value === null
|
|
95
|
+
if (value === undefined || value === null) {
|
|
96
96
|
validationErrors.push(new ValidationResult.ValidationResult(ValidationResultSeverity.ValidationResultSeverity.Error, `${propertyDescriptor.name} is required`, [propertyDescriptor.name], null));
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -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 || 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 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,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AA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AAU,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 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","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,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AC,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;;;;"}
|
package/dist/cjs/commands/for_Command/when_executing/with_empty_required_string_property.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_empty_required_string_property.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_empty_required_string_property.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_null_required_property.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_null_required_property.ts"],"names":[],"mappings":""}
|
package/dist/cjs/commands/for_Command/when_validating/with_empty_required_string_property.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_empty_required_string_property.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating/with_empty_required_string_property.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_null_required_property.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating/with_null_required_property.ts"],"names":[],"mappings":""}
|
|
@@ -90,7 +90,7 @@ class Command {
|
|
|
90
90
|
this.propertyDescriptors.forEach(propertyDescriptor => {
|
|
91
91
|
if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {
|
|
92
92
|
const value = this[propertyDescriptor.name];
|
|
93
|
-
if (value === undefined || value === null
|
|
93
|
+
if (value === undefined || value === null) {
|
|
94
94
|
validationErrors.push(new ValidationResult(ValidationResultSeverity.Error, `${propertyDescriptor.name} is required`, [propertyDescriptor.name], null));
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -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 || 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 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,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C,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 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,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0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_empty_required_string_property.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_empty_required_string_property.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { given } from '../../../given';
|
|
2
|
+
import { a_command } from '../given/a_command';
|
|
3
|
+
describe("when executing with empty required string property", given(class extends a_command {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.command.someProperty = '';
|
|
7
|
+
}
|
|
8
|
+
}, context => {
|
|
9
|
+
let result;
|
|
10
|
+
const responseData = {
|
|
11
|
+
correlationId: '12345678-1234-1234-1234-123456789012',
|
|
12
|
+
isSuccess: true,
|
|
13
|
+
isAuthorized: true,
|
|
14
|
+
isValid: true,
|
|
15
|
+
hasExceptions: false,
|
|
16
|
+
validationResults: [],
|
|
17
|
+
exceptionMessages: [],
|
|
18
|
+
exceptionStackTrace: '',
|
|
19
|
+
response: {}
|
|
20
|
+
};
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
context.fetchStub.resolves({
|
|
23
|
+
status: 200,
|
|
24
|
+
json: async () => responseData
|
|
25
|
+
});
|
|
26
|
+
result = await context.command.execute();
|
|
27
|
+
});
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
context.fetchStub.restore();
|
|
30
|
+
});
|
|
31
|
+
it("should call fetch", () => context.fetchStub.calledOnce.should.be.true);
|
|
32
|
+
it("should return valid result", () => result.isValid.should.be.true);
|
|
33
|
+
it("should send empty string value", () => {
|
|
34
|
+
const call = context.fetchStub.getCall(0);
|
|
35
|
+
const body = JSON.parse(call.args[1].body);
|
|
36
|
+
body.someProperty.should.equal('');
|
|
37
|
+
});
|
|
38
|
+
}));
|
|
39
|
+
//# sourceMappingURL=with_empty_required_string_property.js.map
|
package/dist/esm/commands/for_Command/when_executing/with_empty_required_string_property.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_empty_required_string_property.js","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_empty_required_string_property.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,QAAQ,CAAC,oDAAoD,EAAE,KAAK,CAAC,KAAM,SAAQ,SAAS;IACxF;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,EAAE,CAAC;IACnC,CAAC;CACJ,EAAE,OAAO,CAAC,EAAE;IACT,IAAI,MAA6B,CAAC;IAClC,MAAM,YAAY,GAAG;QACjB,aAAa,EAAE,sCAAsC;QACrD,SAAS,EAAE,IAAI;QACf,YAAY,EAAE,IAAI;QAClB,OAAO,EAAE,IAAI;QACb,aAAa,EAAE,KAAK;QACpB,iBAAiB,EAAE,EAAE;QACrB,iBAAiB,EAAE,EAAE;QACrB,mBAAmB,EAAE,EAAE;QACvB,QAAQ,EAAE,EAAE;KACf,CAAC;IAEF,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC;YACvB,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,YAAY;SACjC,CAAC,CAAC;QAEH,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC3E,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACtE,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACtC,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_null_required_property.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_null_required_property.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { given } from '../../../given';
|
|
2
|
+
import { a_command } from '../given/a_command';
|
|
3
|
+
describe("when executing with null required property", given(class extends a_command {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.command.someProperty = null;
|
|
7
|
+
}
|
|
8
|
+
}, context => {
|
|
9
|
+
let result;
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
result = await context.command.execute();
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
context.fetchStub.restore();
|
|
15
|
+
});
|
|
16
|
+
it("should not call fetch", () => context.fetchStub.called.should.be.false);
|
|
17
|
+
it("should return invalid result", () => result.isValid.should.be.false);
|
|
18
|
+
it("should have validation error", () => result.validationResults.length.should.equal(1));
|
|
19
|
+
it("should have validation message for property", () => result.validationResults[0].message.should.equal('someProperty is required'));
|
|
20
|
+
it("should have validation member for property", () => result.validationResults[0].members[0].should.equal('someProperty'));
|
|
21
|
+
}));
|
|
22
|
+
//# sourceMappingURL=with_null_required_property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_null_required_property.js","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_null_required_property.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,QAAQ,CAAC,4CAA4C,EAAE,KAAK,CAAC,KAAM,SAAQ,SAAS;IAChF;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,IAAyB,CAAC;IAC1D,CAAC;CACJ,EAAE,OAAO,CAAC,EAAE;IACT,IAAI,MAA6B,CAAC;IAElC,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC5E,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,6CAA6C,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;IACtI,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;AAChI,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/esm/commands/for_Command/when_validating/with_empty_required_string_property.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_empty_required_string_property.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating/with_empty_required_string_property.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { given } from '../../../given';
|
|
2
|
+
import { a_command } from '../given/a_command';
|
|
3
|
+
describe("when validating with empty required string property", given(class extends a_command {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.command.someProperty = '';
|
|
7
|
+
}
|
|
8
|
+
}, context => {
|
|
9
|
+
let result;
|
|
10
|
+
const responseData = {
|
|
11
|
+
correlationId: '12345678-1234-1234-1234-123456789012',
|
|
12
|
+
isSuccess: true,
|
|
13
|
+
isAuthorized: true,
|
|
14
|
+
isValid: true,
|
|
15
|
+
hasExceptions: false,
|
|
16
|
+
validationResults: [],
|
|
17
|
+
exceptionMessages: [],
|
|
18
|
+
exceptionStackTrace: '',
|
|
19
|
+
response: {}
|
|
20
|
+
};
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
context.fetchStub.resolves({
|
|
23
|
+
status: 200,
|
|
24
|
+
json: async () => responseData
|
|
25
|
+
});
|
|
26
|
+
result = await context.command.validate();
|
|
27
|
+
});
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
context.fetchStub.restore();
|
|
30
|
+
});
|
|
31
|
+
it("should call server", () => context.fetchStub.calledOnce.should.be.true);
|
|
32
|
+
it("should call validation endpoint", () => context.fetchStub.getCall(0).args[0].toString().should.equal('http://localhost/api/test-route/validate'));
|
|
33
|
+
it("should return valid result", () => result.isValid.should.be.true);
|
|
34
|
+
it("should send empty string value", () => {
|
|
35
|
+
const call = context.fetchStub.getCall(0);
|
|
36
|
+
const body = JSON.parse(call.args[1].body);
|
|
37
|
+
body.someProperty.should.equal('');
|
|
38
|
+
});
|
|
39
|
+
}));
|
|
40
|
+
//# sourceMappingURL=with_empty_required_string_property.js.map
|
package/dist/esm/commands/for_Command/when_validating/with_empty_required_string_property.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_empty_required_string_property.js","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating/with_empty_required_string_property.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,QAAQ,CAAC,qDAAqD,EAAE,KAAK,CAAC,KAAM,SAAQ,SAAS;IACzF;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,EAAE,CAAC;IACnC,CAAC;CACJ,EAAE,OAAO,CAAC,EAAE;IACT,IAAI,MAA6B,CAAC;IAClC,MAAM,YAAY,GAAG;QACjB,aAAa,EAAE,sCAAsC;QACrD,SAAS,EAAE,IAAI;QACf,YAAY,EAAE,IAAI;QAClB,OAAO,EAAE,IAAI;QACb,aAAa,EAAE,KAAK;QACpB,iBAAiB,EAAE,EAAE;QACrB,iBAAiB,EAAE,EAAE;QACrB,mBAAmB,EAAE,EAAE;QACvB,QAAQ,EAAE,EAAE;KACf,CAAC;IAEF,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC;YACvB,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,YAAY;SACjC,CAAC,CAAC;QAEH,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC5E,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC,CAAC;IACtJ,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACtE,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACtC,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_null_required_property.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating/with_null_required_property.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { given } from '../../../given';
|
|
2
|
+
import { a_command } from '../given/a_command';
|
|
3
|
+
describe("when validating with null required property", given(class extends a_command {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.command.someProperty = null;
|
|
7
|
+
}
|
|
8
|
+
}, context => {
|
|
9
|
+
let result;
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
result = await context.command.validate();
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
context.fetchStub.restore();
|
|
15
|
+
});
|
|
16
|
+
it("should not call server", () => context.fetchStub.called.should.be.false);
|
|
17
|
+
it("should return invalid result", () => result.isValid.should.be.false);
|
|
18
|
+
it("should have validation error", () => result.validationResults.length.should.equal(1));
|
|
19
|
+
it("should have validation message for property", () => result.validationResults[0].message.should.equal('someProperty is required'));
|
|
20
|
+
it("should have validation member for property", () => result.validationResults[0].members[0].should.equal('someProperty'));
|
|
21
|
+
}));
|
|
22
|
+
//# sourceMappingURL=with_null_required_property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_null_required_property.js","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating/with_null_required_property.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,QAAQ,CAAC,6CAA6C,EAAE,KAAK,CAAC,KAAM,SAAQ,SAAS;IACjF;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,IAAyB,CAAC;IAC1D,CAAC;CACJ,EAAE,OAAO,CAAC,EAAE;IACT,IAAI,MAA6B,CAAC;IAElC,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC9C,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;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