@cratis/arc 20.41.1 → 20.41.4

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.
@@ -152,11 +152,18 @@ export class CommandResult<TResponse = object> implements ICommandResult<TRespon
152
152
  this.exceptionStackTrace = result.exceptionStackTrace;
153
153
  this.authorizationFailureReason = result.authorizationFailureReason;
154
154
 
155
- if (result.response) {
155
+ if (result.response !== undefined && result.response !== null) {
156
+ const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;
156
157
  if (isResponseTypeEnumerable) {
157
- this.response = JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response) as TResponse;
158
+ this.response = (Array.isArray(result.response)
159
+ ? (isPrimitive
160
+ ? Array.from(result.response)
161
+ : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))
162
+ : []) as TResponse;
158
163
  } else {
159
- this.response = JsonSerializer.deserializeFromInstance(responseInstanceType, result.response) as TResponse;
164
+ this.response = (isPrimitive
165
+ ? result.response
166
+ : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response)) as TResponse;
160
167
  }
161
168
  }
162
169
  }
@@ -0,0 +1,63 @@
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 { CommandResult } from '../CommandResult';
5
+
6
+ describe('when constructing with primitive response', () => {
7
+ const stringResult = new CommandResult<string>({
8
+ correlationId: '0c0ee8c8-b5a6-4999-b030-6e6a0c931b91',
9
+ isSuccess: true,
10
+ isAuthorized: true,
11
+ isValid: true,
12
+ hasExceptions: false,
13
+ validationResults: [],
14
+ exceptionMessages: [],
15
+ exceptionStackTrace: '',
16
+ authorizationFailureReason: '',
17
+ response: 'Handled: TestName'
18
+ }, String, false);
19
+
20
+ const zeroResult = new CommandResult<number>({
21
+ correlationId: '0c0ee8c8-b5a6-4999-b030-6e6a0c931b91',
22
+ isSuccess: true,
23
+ isAuthorized: true,
24
+ isValid: true,
25
+ hasExceptions: false,
26
+ validationResults: [],
27
+ exceptionMessages: [],
28
+ exceptionStackTrace: '',
29
+ authorizationFailureReason: '',
30
+ response: 0
31
+ }, Number, false);
32
+
33
+ const falseResult = new CommandResult<boolean>({
34
+ correlationId: '0c0ee8c8-b5a6-4999-b030-6e6a0c931b91',
35
+ isSuccess: true,
36
+ isAuthorized: true,
37
+ isValid: true,
38
+ hasExceptions: false,
39
+ validationResults: [],
40
+ exceptionMessages: [],
41
+ exceptionStackTrace: '',
42
+ authorizationFailureReason: '',
43
+ response: false
44
+ }, Boolean, false);
45
+
46
+ const stringArrayResult = new CommandResult<string[]>({
47
+ correlationId: '0c0ee8c8-b5a6-4999-b030-6e6a0c931b91',
48
+ isSuccess: true,
49
+ isAuthorized: true,
50
+ isValid: true,
51
+ hasExceptions: false,
52
+ validationResults: [],
53
+ exceptionMessages: [],
54
+ exceptionStackTrace: '',
55
+ authorizationFailureReason: '',
56
+ response: ['one', 'two']
57
+ }, String, true);
58
+
59
+ it('should preserve string response', () => stringResult.response!.should.equal('Handled: TestName'));
60
+ it('should preserve zero response', () => zeroResult.response!.should.equal(0));
61
+ it('should preserve false response', () => falseResult.response!.should.equal(false));
62
+ it('should preserve primitive array response', () => stringArrayResult.response!.should.deep.equal(['one', 'two']));
63
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"CommandResult.d.ts","sourceRoot":"","sources":["../../../commands/CommandResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAKnE,KAAK,SAAS,GAAG,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAA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5B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAG/B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAG1B,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAGhC,QAAQ,CAAC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IAG/C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAGrC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IAGrC,QAAQ,CAAC,0BAA0B,EAAE,MAAM,CAAC;IAG5C,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;gBAQlB,MAAM,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,WAAW,YAAS,EAAE,wBAAwB,EAAE,OAAO;IAgCtH,SAAS,CAAC,QAAQ,EAAE,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC;IAYxD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,aAAa,CAAC,SAAS,CAAC;IAYjE,WAAW,CAAC,QAAQ,EAAE,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC;IAY5D,cAAc,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC,SAAS,CAAC;IAYlE,mBAAmB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,aAAa,CAAC,SAAS,CAAC;CAM/E"}
@@ -69,12 +69,19 @@ class CommandResult {
69
69
  this.exceptionMessages = result.exceptionMessages;
70
70
  this.exceptionStackTrace = result.exceptionStackTrace;
71
71
  this.authorizationFailureReason = result.authorizationFailureReason;
72
- if (result.response) {
72
+ if (result.response !== undefined && result.response !== null) {
73
+ const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;
73
74
  if (isResponseTypeEnumerable) {
74
- this.response = fundamentals.JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response);
75
+ this.response = (Array.isArray(result.response)
76
+ ? (isPrimitive
77
+ ? Array.from(result.response)
78
+ : fundamentals.JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))
79
+ : []);
75
80
  }
76
81
  else {
77
- this.response = fundamentals.JsonSerializer.deserializeFromInstance(responseInstanceType, result.response);
82
+ this.response = (isPrimitive
83
+ ? result.response
84
+ : fundamentals.JsonSerializer.deserializeFromInstance(responseInstanceType, result.response));
78
85
  }
79
86
  }
80
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CommandResult.js","sources":["../../../commands/CommandResult.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 { Guid } from '@cratis/fundamentals';\nimport { ICommandResult } from './ICommandResult';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\n\n/**\n * Delegate type for the onSuccess callback.\n */\ntype OnSuccess = (<TResponse>(response: TResponse) => void) | (() => void);\n\n/**\n * Delegate type for the onFailed callback.\n */\ntype OnFailed<TResponse> = ((commandResult: CommandResult<TResponse>) => void) | (() => void);\n\n/**\n * Delegate type for the onException callback.\n */\ntype OnException = (messages: string[], stackTrace: string) => void;\n\n/**\n * Delegate type for the onUnauthorized callback.\n */\ntype OnUnauthorized = () => void;\n\n/**\n * Delegate type for the onValidationFailure callback.\n */\ntype OnValidationFailure = (validationResults: ValidationResult[]) => void;\n\ntype ServerCommandResult = {\n correlationId: string;\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: {\n severity: number;\n message: string;\n members: string[];\n state: object;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n response: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n}\n\n/**\n * Represents the result from executing a {@link ICommand}.\n */\nexport class CommandResult<TResponse = object> implements ICommandResult<TResponse> {\n\n static empty: CommandResult = new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n\n static failed = (exceptionMessages: string[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: true,\n validationResults: [],\n exceptionMessages: exceptionMessages,\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n static validationFailed = (validationResults: ValidationResult[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: validationResults.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n /** @inheritdoc */\n readonly correlationId: Guid;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /** @inheritdoc */\n readonly authorizationFailureReason: string;\n\n /** @inheritdoc */\n readonly response?: TResponse;\n\n /**\n * Creates an instance of command result.\n * @param {*} result The JSON/any representation of the command result;\n * @param {Constructor} responseInstanceType The {@see Constructor} that represents the type of response, if any. Defaults to {@see Object}.\n * @param {boolean} isResponseTypeEnumerable Whether or not the response type is an enumerable or not.\n */\n constructor(result: ServerCommandResult, responseInstanceType: Constructor = Object, isResponseTypeEnumerable: boolean) {\n this.correlationId = Guid.parse(result.correlationId);\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n\n if (result.response) {\n if (isResponseTypeEnumerable) {\n this.response = JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response) as TResponse;\n } else {\n this.response = JsonSerializer.deserializeFromInstance(responseInstanceType, result.response) as TResponse;\n }\n }\n }\n\n /**\n * Set up a callback for when the command was successful.\n * @param {OnSuccess} callback The callback to call when the command was successful.\n * @returns {CommandResult} The instance of the command result.\n */\n onSuccess(callback: OnSuccess): CommandResult<TResponse> {\n if (this.isSuccess) {\n callback(this.response as TResponse);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed.\n * @param {OnFailed} callback The callback to call when the command failed.\n * @returns {CommandResult} The instance of the command result.\n */\n onFailed(callback: OnFailed<TResponse>): CommandResult<TResponse> {\n if (!this.isSuccess) {\n callback(this);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed with an exception.\n * @param {OnException} callback The callback to call when the command had an exception.\n * @returns {CommandResult} The instance of the command result.\n */\n onException(callback: OnException): CommandResult<TResponse> {\n if (this.hasExceptions) {\n callback(this.exceptionMessages, this.exceptionStackTrace);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command was unauthorized.\n * @param {OnUnauthorized} callback The callback to call when the command was unauthorized.\n * @returns {CommandResult} The instance of the command result.\n */\n onUnauthorized(callback: OnUnauthorized): CommandResult<TResponse> {\n if (!this.isAuthorized) {\n callback();\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command had validation errors.\n * @param {OnSuccess} callback The callback to call when the command was invalid.\n * @returns {CommandResult} The instance of the command result.\n */\n onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse> {\n if (!this.isValid) {\n callback(this.validationResults);\n }\n return this;\n }\n}\n"],"names":["Guid","ValidationResult","J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AiB,CAAC;QACpC;AACA,QAAA,OAAO,IAAI;IACf;;;;;"}
1
+ {"version":3,"file":"CommandResult.js","sources":["../../../commands/CommandResult.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 { Guid } from '@cratis/fundamentals';\nimport { ICommandResult } from './ICommandResult';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\n\n/**\n * Delegate type for the onSuccess callback.\n */\ntype OnSuccess = (<TResponse>(response: TResponse) => void) | (() => void);\n\n/**\n * Delegate type for the onFailed callback.\n */\ntype OnFailed<TResponse> = ((commandResult: CommandResult<TResponse>) => void) | (() => void);\n\n/**\n * Delegate type for the onException callback.\n */\ntype OnException = (messages: string[], stackTrace: string) => void;\n\n/**\n * Delegate type for the onUnauthorized callback.\n */\ntype OnUnauthorized = () => void;\n\n/**\n * Delegate type for the onValidationFailure callback.\n */\ntype OnValidationFailure = (validationResults: ValidationResult[]) => void;\n\ntype ServerCommandResult = {\n correlationId: string;\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: {\n severity: number;\n message: string;\n members: string[];\n state: object;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n response: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n}\n\n/**\n * Represents the result from executing a {@link ICommand}.\n */\nexport class CommandResult<TResponse = object> implements ICommandResult<TResponse> {\n\n static empty: CommandResult = new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n\n static failed = (exceptionMessages: string[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: true,\n validationResults: [],\n exceptionMessages: exceptionMessages,\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n static validationFailed = (validationResults: ValidationResult[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: validationResults.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n /** @inheritdoc */\n readonly correlationId: Guid;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /** @inheritdoc */\n readonly authorizationFailureReason: string;\n\n /** @inheritdoc */\n readonly response?: TResponse;\n\n /**\n * Creates an instance of command result.\n * @param {*} result The JSON/any representation of the command result;\n * @param {Constructor} responseInstanceType The {@see Constructor} that represents the type of response, if any. Defaults to {@see Object}.\n * @param {boolean} isResponseTypeEnumerable Whether or not the response type is an enumerable or not.\n */\n constructor(result: ServerCommandResult, responseInstanceType: Constructor = Object, isResponseTypeEnumerable: boolean) {\n this.correlationId = Guid.parse(result.correlationId);\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n\n if (result.response !== undefined && result.response !== null) {\n const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;\n if (isResponseTypeEnumerable) {\n this.response = (Array.isArray(result.response)\n ? (isPrimitive\n ? Array.from(result.response)\n : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))\n : []) as TResponse;\n } else {\n this.response = (isPrimitive\n ? result.response\n : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response)) as TResponse;\n }\n }\n }\n\n /**\n * Set up a callback for when the command was successful.\n * @param {OnSuccess} callback The callback to call when the command was successful.\n * @returns {CommandResult} The instance of the command result.\n */\n onSuccess(callback: OnSuccess): CommandResult<TResponse> {\n if (this.isSuccess) {\n callback(this.response as TResponse);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed.\n * @param {OnFailed} callback The callback to call when the command failed.\n * @returns {CommandResult} The instance of the command result.\n */\n onFailed(callback: OnFailed<TResponse>): CommandResult<TResponse> {\n if (!this.isSuccess) {\n callback(this);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed with an exception.\n * @param {OnException} callback The callback to call when the command had an exception.\n * @returns {CommandResult} The instance of the command result.\n */\n onException(callback: OnException): CommandResult<TResponse> {\n if (this.hasExceptions) {\n callback(this.exceptionMessages, this.exceptionStackTrace);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command was unauthorized.\n * @param {OnUnauthorized} callback The callback to call when the command was unauthorized.\n * @returns {CommandResult} The instance of the command result.\n */\n onUnauthorized(callback: OnUnauthorized): CommandResult<TResponse> {\n if (!this.isAuthorized) {\n callback();\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command had validation errors.\n * @param {OnSuccess} callback The callback to call when the command was invalid.\n * @returns {CommandResult} The instance of the command result.\n */\n onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse> {\n if (!this.isValid) {\n callback(this.validationResults);\n }\n return this;\n }\n}\n"],"names":["Guid","ValidationResult","JsonSerializer"],"mappings":";;;;;MAyDa,aAAa,CAAA;AAEtB,IAAA,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AAc,CAAC,QAAwB,EAAA;AACnC,QAAA,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;AACpB,YAAA,QAAQ,EAAE;QACd;AACA,QAAA,OAAO,IAAI;IACf;AAOA,IAAA,mBAAmB,CAAC,QAA6B,EAAA;AAC7C,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;AACf,YAAA,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC;QACpC;AACA,QAAA,OAAO,IAAI;IACf;;;;;"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=when_constructing_with_primitive_response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"when_constructing_with_primitive_response.d.ts","sourceRoot":"","sources":["../../../../commands/for_CommandResult/when_constructing_with_primitive_response.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandResult.d.ts","sourceRoot":"","sources":["../../../commands/CommandResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAKnE,KAAK,SAAS,GAAG,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAK3E,KAAK,QAAQ,CAAC,SAAS,IAAI,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAK9F,KAAK,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;AAKpE,KAAK,cAAc,GAAG,MAAM,IAAI,CAAC;AAKjC,KAAK,mBA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AC,0BAA0B,EAAE,MAAM,CAAC;IAG5C,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;gBAQlB,MAAM,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,WAAW,YAAS,EAAE,wBAAwB,EAAE,OAAO;IAgCtH,SAAS,CAAC,QAAQ,EAAE,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC;IAYxD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,aAAa,CAAC,SAAS,CAAC;IAYjE,WAAW,CAAC,QAAQ,EAAE,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC;IAY5D,cAAc,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC,SAAS,CAAC;IAYlE,mBAAmB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,aAAa,CAAC,SAAS,CAAC;CAM/E"}
@@ -67,12 +67,19 @@ class CommandResult {
67
67
  this.exceptionMessages = result.exceptionMessages;
68
68
  this.exceptionStackTrace = result.exceptionStackTrace;
69
69
  this.authorizationFailureReason = result.authorizationFailureReason;
70
- if (result.response) {
70
+ if (result.response !== undefined && result.response !== null) {
71
+ const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;
71
72
  if (isResponseTypeEnumerable) {
72
- this.response = JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response);
73
+ this.response = (Array.isArray(result.response)
74
+ ? (isPrimitive
75
+ ? Array.from(result.response)
76
+ : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))
77
+ : []);
73
78
  }
74
79
  else {
75
- this.response = JsonSerializer.deserializeFromInstance(responseInstanceType, result.response);
80
+ this.response = (isPrimitive
81
+ ? result.response
82
+ : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response));
76
83
  }
77
84
  }
78
85
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CommandResult.js","sources":["../../../commands/CommandResult.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 { Guid } from '@cratis/fundamentals';\nimport { ICommandResult } from './ICommandResult';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\n\n/**\n * Delegate type for the onSuccess callback.\n */\ntype OnSuccess = (<TResponse>(response: TResponse) => void) | (() => void);\n\n/**\n * Delegate type for the onFailed callback.\n */\ntype OnFailed<TResponse> = ((commandResult: CommandResult<TResponse>) => void) | (() => void);\n\n/**\n * Delegate type for the onException callback.\n */\ntype OnException = (messages: string[], stackTrace: string) => void;\n\n/**\n * Delegate type for the onUnauthorized callback.\n */\ntype OnUnauthorized = () => void;\n\n/**\n * Delegate type for the onValidationFailure callback.\n */\ntype OnValidationFailure = (validationResults: ValidationResult[]) => void;\n\ntype ServerCommandResult = {\n correlationId: string;\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: {\n severity: number;\n message: string;\n members: string[];\n state: object;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n response: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n}\n\n/**\n * Represents the result from executing a {@link ICommand}.\n */\nexport class CommandResult<TResponse = object> implements ICommandResult<TResponse> {\n\n static empty: CommandResult = new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n\n static failed = (exceptionMessages: string[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: true,\n validationResults: [],\n exceptionMessages: exceptionMessages,\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n static validationFailed = (validationResults: ValidationResult[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: validationResults.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n /** @inheritdoc */\n readonly correlationId: Guid;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /** @inheritdoc */\n readonly authorizationFailureReason: string;\n\n /** @inheritdoc */\n readonly response?: TResponse;\n\n /**\n * Creates an instance of command result.\n * @param {*} result The JSON/any representation of the command result;\n * @param {Constructor} responseInstanceType The {@see Constructor} that represents the type of response, if any. Defaults to {@see Object}.\n * @param {boolean} isResponseTypeEnumerable Whether or not the response type is an enumerable or not.\n */\n constructor(result: ServerCommandResult, responseInstanceType: Constructor = Object, isResponseTypeEnumerable: boolean) {\n this.correlationId = Guid.parse(result.correlationId);\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n\n if (result.response) {\n if (isResponseTypeEnumerable) {\n this.response = JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response) as TResponse;\n } else {\n this.response = JsonSerializer.deserializeFromInstance(responseInstanceType, result.response) as TResponse;\n }\n }\n }\n\n /**\n * Set up a callback for when the command was successful.\n * @param {OnSuccess} callback The callback to call when the command was successful.\n * @returns {CommandResult} The instance of the command result.\n */\n onSuccess(callback: OnSuccess): CommandResult<TResponse> {\n if (this.isSuccess) {\n callback(this.response as TResponse);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed.\n * @param {OnFailed} callback The callback to call when the command failed.\n * @returns {CommandResult} The instance of the command result.\n */\n onFailed(callback: OnFailed<TResponse>): CommandResult<TResponse> {\n if (!this.isSuccess) {\n callback(this);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed with an exception.\n * @param {OnException} callback The callback to call when the command had an exception.\n * @returns {CommandResult} The instance of the command result.\n */\n onException(callback: OnException): CommandResult<TResponse> {\n if (this.hasExceptions) {\n callback(this.exceptionMessages, this.exceptionStackTrace);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command was unauthorized.\n * @param {OnUnauthorized} callback The callback to call when the command was unauthorized.\n * @returns {CommandResult} The instance of the command result.\n */\n onUnauthorized(callback: OnUnauthorized): CommandResult<TResponse> {\n if (!this.isAuthorized) {\n callback();\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command had validation errors.\n * @param {OnSuccess} callback The callback to call when the command was invalid.\n * @returns {CommandResult} The instance of the command result.\n */\n onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse> {\n if (!this.isValid) {\n callback(this.validationResults);\n }\n return this;\n }\n}\n"],"names":[],"mappings":";;;MAyDa,aAAa,CAAA;AAEtB,IAAA,OAAO,KAAK,GAAkB,IAAI,aAAa,CAAC;AAC5C,QAAA,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;AACpC,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,YAAY,EAAE,IAAI;AAClB,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,aAAa,EAAE,KAAK;AACpB,QAAA,iBAAiB,EAAE,EAAE;AACrB,QAAA,iBAAiB,EAAE,EAAE;AACrB,QAAA,mBAAmB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cAAc,CAAC,uBAAuB,CAAC,oBAAoB,EAAE,MAAM,CAAC,QAAQ,CAAc;YAC9G;QACJ;IACJ;AAOA,IAAA,SAAS,CAAC,QAAmB,EAAA;AACzB,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAChB,YAAA,QAAQ,CAAC,IAAI,CAAC,QAAqB,CAAC;QACxC;AACA,QAAA,OAAO,IAAI;IACf;AAOA,IAAA,QAAQ,CAAC,QAA6B,EAAA;AAClC,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACjB,QAAQ,CAAC,IAAI,CAAC;QAClB;AACA,QAAA,OAAO,IAAI;IACf;AAOA,IAAA,WAAW,CAAC,QAAqB,EAAA;AAC7B,QAAA,IAAI,IAAI,CAAC,aAAa,EAAE;YACpB,QAAQ,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,mBAAmB,CAAC;QAC9D;AACA,QAAA,OAAO,IAAI;IACf;AAOA,IAAA,cAAc,CAAC,QAAwB,EAAA;AACnC,QAAA,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;AACpB,YAAA,QAAQ,EAAE;QACd;AACA,QAAA,OAAO,IAAI;IACf;AAOA,IAAA,mBAAmB,CAAC,QAA6B,EAAA;AAC7C,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;AACf,YAAA,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC;QACpC;AACA,QAAA,OAAO,IAAI;IACf;;;;;"}
1
+ {"version":3,"file":"CommandResult.js","sources":["../../../commands/CommandResult.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 { Guid } from '@cratis/fundamentals';\nimport { ICommandResult } from './ICommandResult';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\n\n/**\n * Delegate type for the onSuccess callback.\n */\ntype OnSuccess = (<TResponse>(response: TResponse) => void) | (() => void);\n\n/**\n * Delegate type for the onFailed callback.\n */\ntype OnFailed<TResponse> = ((commandResult: CommandResult<TResponse>) => void) | (() => void);\n\n/**\n * Delegate type for the onException callback.\n */\ntype OnException = (messages: string[], stackTrace: string) => void;\n\n/**\n * Delegate type for the onUnauthorized callback.\n */\ntype OnUnauthorized = () => void;\n\n/**\n * Delegate type for the onValidationFailure callback.\n */\ntype OnValidationFailure = (validationResults: ValidationResult[]) => void;\n\ntype ServerCommandResult = {\n correlationId: string;\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: {\n severity: number;\n message: string;\n members: string[];\n state: object;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n response: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n}\n\n/**\n * Represents the result from executing a {@link ICommand}.\n */\nexport class CommandResult<TResponse = object> implements ICommandResult<TResponse> {\n\n static empty: CommandResult = new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n\n static failed = (exceptionMessages: string[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: true,\n validationResults: [],\n exceptionMessages: exceptionMessages,\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n static validationFailed = (validationResults: ValidationResult[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: validationResults.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n /** @inheritdoc */\n readonly correlationId: Guid;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /** @inheritdoc */\n readonly authorizationFailureReason: string;\n\n /** @inheritdoc */\n readonly response?: TResponse;\n\n /**\n * Creates an instance of command result.\n * @param {*} result The JSON/any representation of the command result;\n * @param {Constructor} responseInstanceType The {@see Constructor} that represents the type of response, if any. Defaults to {@see Object}.\n * @param {boolean} isResponseTypeEnumerable Whether or not the response type is an enumerable or not.\n */\n constructor(result: ServerCommandResult, responseInstanceType: Constructor = Object, isResponseTypeEnumerable: boolean) {\n this.correlationId = Guid.parse(result.correlationId);\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n\n if (result.response !== undefined && result.response !== null) {\n const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;\n if (isResponseTypeEnumerable) {\n this.response = (Array.isArray(result.response)\n ? (isPrimitive\n ? Array.from(result.response)\n : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))\n : []) as TResponse;\n } else {\n this.response = (isPrimitive\n ? result.response\n : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response)) as TResponse;\n }\n }\n }\n\n /**\n * Set up a callback for when the command was successful.\n * @param {OnSuccess} callback The callback to call when the command was successful.\n * @returns {CommandResult} The instance of the command result.\n */\n onSuccess(callback: OnSuccess): CommandResult<TResponse> {\n if (this.isSuccess) {\n callback(this.response as TResponse);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed.\n * @param {OnFailed} callback The callback to call when the command failed.\n * @returns {CommandResult} The instance of the command result.\n */\n onFailed(callback: OnFailed<TResponse>): CommandResult<TResponse> {\n if (!this.isSuccess) {\n callback(this);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed with an exception.\n * @param {OnException} callback The callback to call when the command had an exception.\n * @returns {CommandResult} The instance of the command result.\n */\n onException(callback: OnException): CommandResult<TResponse> {\n if (this.hasExceptions) {\n callback(this.exceptionMessages, this.exceptionStackTrace);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command was unauthorized.\n * @param {OnUnauthorized} callback The callback to call when the command was unauthorized.\n * @returns {CommandResult} The instance of the command result.\n */\n onUnauthorized(callback: OnUnauthorized): CommandResult<TResponse> {\n if (!this.isAuthorized) {\n callback();\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command had validation errors.\n * @param {OnSuccess} callback The callback to call when the command was invalid.\n * @returns {CommandResult} The instance of the command result.\n */\n onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse> {\n if (!this.isValid) {\n callback(this.validationResults);\n }\n return this;\n }\n}\n"],"names":[],"mappings":";;;MAyDa,aAAa,CAAA;AAEtB,IAAA,OAAO,KAAK,GAAkB,IAAI,aAAa,CAAC;AAC5C,QAAA,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;AACpC,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,YAAY,EAAE,IAAI;AAClB,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,aAAa,EAAE,KAAK;AACpB,QAAA,iBAAiB,EAAE,EAAE;AACrB,QAAA,iBAAiB,EAAE,EAAE;AACrB,QAAA,mBAAmB,EAAE,EAAE;AACvB,QAAA,0BAA0B,EAAE,EAAE;AAC9B,QAAA,QAAQ,EAAE;AACb,KAAA,EAAE,MAAM,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"file":"when_constructing_with_primitive_response.d.ts","sourceRoot":"","sources":["../../../../commands/for_CommandResult/when_constructing_with_primitive_response.ts"],"names":[],"mappings":""}
@@ -0,0 +1,56 @@
1
+ import { CommandResult } from '../CommandResult';
2
+ describe('when constructing with primitive response', () => {
3
+ const stringResult = new CommandResult({
4
+ correlationId: '0c0ee8c8-b5a6-4999-b030-6e6a0c931b91',
5
+ isSuccess: true,
6
+ isAuthorized: true,
7
+ isValid: true,
8
+ hasExceptions: false,
9
+ validationResults: [],
10
+ exceptionMessages: [],
11
+ exceptionStackTrace: '',
12
+ authorizationFailureReason: '',
13
+ response: 'Handled: TestName'
14
+ }, String, false);
15
+ const zeroResult = new CommandResult({
16
+ correlationId: '0c0ee8c8-b5a6-4999-b030-6e6a0c931b91',
17
+ isSuccess: true,
18
+ isAuthorized: true,
19
+ isValid: true,
20
+ hasExceptions: false,
21
+ validationResults: [],
22
+ exceptionMessages: [],
23
+ exceptionStackTrace: '',
24
+ authorizationFailureReason: '',
25
+ response: 0
26
+ }, Number, false);
27
+ const falseResult = new CommandResult({
28
+ correlationId: '0c0ee8c8-b5a6-4999-b030-6e6a0c931b91',
29
+ isSuccess: true,
30
+ isAuthorized: true,
31
+ isValid: true,
32
+ hasExceptions: false,
33
+ validationResults: [],
34
+ exceptionMessages: [],
35
+ exceptionStackTrace: '',
36
+ authorizationFailureReason: '',
37
+ response: false
38
+ }, Boolean, false);
39
+ const stringArrayResult = new CommandResult({
40
+ correlationId: '0c0ee8c8-b5a6-4999-b030-6e6a0c931b91',
41
+ isSuccess: true,
42
+ isAuthorized: true,
43
+ isValid: true,
44
+ hasExceptions: false,
45
+ validationResults: [],
46
+ exceptionMessages: [],
47
+ exceptionStackTrace: '',
48
+ authorizationFailureReason: '',
49
+ response: ['one', 'two']
50
+ }, String, true);
51
+ it('should preserve string response', () => stringResult.response.should.equal('Handled: TestName'));
52
+ it('should preserve zero response', () => zeroResult.response.should.equal(0));
53
+ it('should preserve false response', () => falseResult.response.should.equal(false));
54
+ it('should preserve primitive array response', () => stringArrayResult.response.should.deep.equal(['one', 'two']));
55
+ });
56
+ //# sourceMappingURL=when_constructing_with_primitive_response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"when_constructing_with_primitive_response.js","sourceRoot":"","sources":["../../../../commands/for_CommandResult/when_constructing_with_primitive_response.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,QAAQ,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACvD,MAAM,YAAY,GAAG,IAAI,aAAa,CAAS;QAC3C,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,0BAA0B,EAAE,EAAE;QAC9B,QAAQ,EAAE,mBAAmB;KAChC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAElB,MAAM,UAAU,GAAG,IAAI,aAAa,CAAS;QACzC,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,0BAA0B,EAAE,EAAE;QAC9B,QAAQ,EAAE,CAAC;KACd,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAElB,MAAM,WAAW,GAAG,IAAI,aAAa,CAAU;QAC3C,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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