@cratis/arc 23.10.1 → 23.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/commands/CommandResult.ts +24 -14
  2. package/commands/CommandResults.ts +5 -0
  3. package/commands/ICommandResult.ts +3 -0
  4. package/commands/for_CommandResult/when_aggregating_missing_handler_results.ts +17 -0
  5. package/commands/for_CommandResult/when_an_older_server_omits_the_missing_handler_flag.ts +22 -0
  6. package/commands/for_CommandResult/when_the_handler_is_missing.ts +26 -0
  7. package/dist/cjs/commands/CommandResult.d.ts +3 -0
  8. package/dist/cjs/commands/CommandResult.d.ts.map +1 -1
  9. package/dist/cjs/commands/CommandResult.js +14 -8
  10. package/dist/cjs/commands/CommandResult.js.map +1 -1
  11. package/dist/cjs/commands/CommandResults.d.ts +1 -0
  12. package/dist/cjs/commands/CommandResults.d.ts.map +1 -1
  13. package/dist/cjs/commands/CommandResults.js +3 -0
  14. package/dist/cjs/commands/CommandResults.js.map +1 -1
  15. package/dist/cjs/commands/ICommandResult.d.ts +1 -0
  16. package/dist/cjs/commands/ICommandResult.d.ts.map +1 -1
  17. package/dist/esm/commands/CommandResult.d.ts +3 -0
  18. package/dist/esm/commands/CommandResult.d.ts.map +1 -1
  19. package/dist/esm/commands/CommandResult.js +14 -8
  20. package/dist/esm/commands/CommandResult.js.map +1 -1
  21. package/dist/esm/commands/CommandResults.d.ts +1 -0
  22. package/dist/esm/commands/CommandResults.d.ts.map +1 -1
  23. package/dist/esm/commands/CommandResults.js +3 -0
  24. package/dist/esm/commands/CommandResults.js.map +1 -1
  25. package/dist/esm/commands/ICommandResult.d.ts +1 -0
  26. package/dist/esm/commands/ICommandResult.d.ts.map +1 -1
  27. package/dist/esm/commands/for_CommandResult/when_aggregating_missing_handler_results.d.ts +2 -0
  28. package/dist/esm/commands/for_CommandResult/when_aggregating_missing_handler_results.d.ts.map +1 -0
  29. package/dist/esm/commands/for_CommandResult/when_aggregating_missing_handler_results.js +12 -0
  30. package/dist/esm/commands/for_CommandResult/when_aggregating_missing_handler_results.js.map +1 -0
  31. package/dist/esm/commands/for_CommandResult/when_an_older_server_omits_the_missing_handler_flag.d.ts +2 -0
  32. package/dist/esm/commands/for_CommandResult/when_an_older_server_omits_the_missing_handler_flag.d.ts.map +1 -0
  33. package/dist/esm/commands/for_CommandResult/when_an_older_server_omits_the_missing_handler_flag.js +18 -0
  34. package/dist/esm/commands/for_CommandResult/when_an_older_server_omits_the_missing_handler_flag.js.map +1 -0
  35. package/dist/esm/commands/for_CommandResult/when_the_handler_is_missing.d.ts +2 -0
  36. package/dist/esm/commands/for_CommandResult/when_the_handler_is_missing.d.ts.map +1 -0
  37. package/dist/esm/commands/for_CommandResult/when_the_handler_is_missing.js +22 -0
  38. package/dist/esm/commands/for_CommandResult/when_the_handler_is_missing.js.map +1 -0
  39. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +1 -1
@@ -55,6 +55,7 @@ type ServerCommandResult = {
55
55
  exceptionStackTrace: string;
56
56
  authorizationFailureReason: string;
57
57
  isRetryable?: boolean;
58
+ isMissingHandler?: boolean;
58
59
 
59
60
  /* eslint-disable @typescript-eslint/no-explicit-any */
60
61
  response: any;
@@ -146,6 +147,9 @@ export class CommandResult<TResponse = object> implements ICommandResult<TRespon
146
147
  /** @inheritdoc */
147
148
  readonly isRetryable: boolean;
148
149
 
150
+ /** Whether no server handler was registered, so execution or validation did not run. */
151
+ readonly isMissingHandler: boolean;
152
+
149
153
  /** @inheritdoc */
150
154
  readonly response?: TResponse;
151
155
 
@@ -168,20 +172,9 @@ export class CommandResult<TResponse = object> implements ICommandResult<TRespon
168
172
  // Older servers do not report retryable failures; none of their results are.
169
173
  this.isRetryable = result.isRetryable ?? false;
170
174
 
171
- if (result.response !== undefined && result.response !== null) {
172
- const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;
173
- if (isResponseTypeEnumerable) {
174
- this.response = (Array.isArray(result.response)
175
- ? (isPrimitive
176
- ? Array.from(result.response)
177
- : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))
178
- : []) as TResponse;
179
- } else {
180
- this.response = (isPrimitive
181
- ? result.response
182
- : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response)) as TResponse;
183
- }
184
- }
175
+ // Older servers do not identify missing handlers.
176
+ this.isMissingHandler = result.isMissingHandler ?? false;
177
+ this.response = this.deserializeResponse(result, responseInstanceType, isResponseTypeEnumerable);
185
178
  }
186
179
 
187
180
  /**
@@ -263,4 +256,21 @@ export class CommandResult<TResponse = object> implements ICommandResult<TRespon
263
256
  }
264
257
  return this;
265
258
  }
259
+
260
+ private deserializeResponse(result: ServerCommandResult, responseInstanceType: Constructor, isResponseTypeEnumerable: boolean): TResponse | undefined {
261
+ if (result.response === undefined || result.response === null) {
262
+ return undefined;
263
+ }
264
+ const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;
265
+ if (isResponseTypeEnumerable) {
266
+ return (Array.isArray(result.response)
267
+ ? (isPrimitive
268
+ ? Array.from(result.response)
269
+ : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))
270
+ : []) as TResponse;
271
+ }
272
+ return (isPrimitive
273
+ ? result.response
274
+ : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response)) as TResponse;
275
+ }
266
276
  }
@@ -37,6 +37,11 @@ export class CommandResults implements ICommandResult {
37
37
  return this.isAnyTrue(_ => _.hasExceptions);
38
38
  }
39
39
 
40
+ /** @inheritdoc */
41
+ get isMissingHandler(): boolean {
42
+ return this.isAnyTrue(_ => _.isMissingHandler === true);
43
+ }
44
+
40
45
  /** @inheritdoc */
41
46
  get validationResults(): ValidationResult[] {
42
47
  const errors: ValidationResult[] = [];
@@ -54,6 +54,9 @@ import { ValidationResult } from '../validation/ValidationResult.js';
54
54
  */
55
55
  readonly isRetryable?: boolean;
56
56
 
57
+ /** Gets whether the command has no registered server handler. Servers that do not report it are read as false. */
58
+ readonly isMissingHandler?: boolean;
59
+
57
60
  /**
58
61
  * Gets the stack trace if there was an exception.
59
62
  */
@@ -0,0 +1,17 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { Command } from '../Command.js';
5
+ import { CommandResult } from '../CommandResult.js';
6
+ import { CommandResults } from '../CommandResults.js';
7
+
8
+ const aggregate = (missing: boolean) => new CommandResults(new Map([
9
+ [{} as Command, CommandResult.empty],
10
+ [{} as Command, Object.assign(CommandResult.failed(['diagnostic']), { isMissingHandler: missing })]
11
+ ]));
12
+
13
+ describe('when aggregating missing handler results', () => {
14
+ it('should report a missing handler when any member does', () => aggregate(true).isMissingHandler.should.be.true);
15
+ it('should not report a missing handler for other failures', () => aggregate(false).isMissingHandler.should.be.false);
16
+ it('should not report a missing handler for no results', () => new CommandResults(new Map()).isMissingHandler.should.be.false);
17
+ });
@@ -0,0 +1,22 @@
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.js';
5
+
6
+ const result = new CommandResult({
7
+ correlationId: '00000000-0000-0000-0000-000000000000',
8
+ isSuccess: false,
9
+ isAuthorized: true,
10
+ isValid: true,
11
+ hasExceptions: true,
12
+ validationResults: [],
13
+ exceptionMessages: ['No handler found for command of type Example'],
14
+ exceptionStackTrace: '',
15
+ authorizationFailureReason: '',
16
+ response: null
17
+ }, Object, false);
18
+
19
+ describe('when an older server omits the missing handler flag', () => {
20
+ it('should default the flag to false without interpreting the message', () => result.isMissingHandler.should.be.false);
21
+ it('should preserve the exception outcome', () => result.hasExceptions.should.be.true);
22
+ });
@@ -0,0 +1,26 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { CommandResult } from '../CommandResult.js';
5
+
6
+ const result = new CommandResult({
7
+ correlationId: '00000000-0000-0000-0000-000000000000',
8
+ isSuccess: false,
9
+ isAuthorized: true,
10
+ isValid: true,
11
+ hasExceptions: true,
12
+ validationResults: [],
13
+ exceptionMessages: ['No handler found for command of type Example'],
14
+ exceptionStackTrace: '',
15
+ authorizationFailureReason: '',
16
+ isMissingHandler: true,
17
+ response: null
18
+ }, Object, false);
19
+
20
+ describe('when the handler is missing', () => {
21
+ it('should identify the missing handler', () => result.isMissingHandler.should.be.true);
22
+ it('should still carry exceptions', () => result.hasExceptions.should.be.true);
23
+ it('should not be successful', () => result.isSuccess.should.be.false);
24
+ it('should not be a denial', () => result.isAuthorized.should.be.true);
25
+ it('should not be retryable', () => result.isRetryable.should.be.false);
26
+ });
@@ -26,6 +26,7 @@ type ServerCommandResult = {
26
26
  exceptionStackTrace: string;
27
27
  authorizationFailureReason: string;
28
28
  isRetryable?: boolean;
29
+ isMissingHandler?: boolean;
29
30
  response: any;
30
31
  };
31
32
  export declare class CommandResult<TResponse = object> implements ICommandResult<TResponse> {
@@ -42,6 +43,7 @@ export declare class CommandResult<TResponse = object> implements ICommandResult
42
43
  readonly exceptionStackTrace: string;
43
44
  readonly authorizationFailureReason: string;
44
45
  readonly isRetryable: boolean;
46
+ readonly isMissingHandler: boolean;
45
47
  readonly response?: TResponse;
46
48
  constructor(result: ServerCommandResult, responseInstanceType: Constructor | undefined, isResponseTypeEnumerable: boolean);
47
49
  onSuccess(callback: OnSuccess): CommandResult<TResponse>;
@@ -51,6 +53,7 @@ export declare class CommandResult<TResponse = object> implements ICommandResult
51
53
  get isNotAvailable(): boolean;
52
54
  onNotAvailable(callback: OnNotAvailable): CommandResult<TResponse>;
53
55
  onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse>;
56
+ private deserializeResponse;
54
57
  }
55
58
  export {};
56
59
  //# sourceMappingURL=CommandResult.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CommandResult.d.ts","sourceRoot":"","sources":["../../../commands/CommandResult.ts"],"names":[],"mappings":"AAGA,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gBAAgB,EAAE,OAAO,CAAC;IAGnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAQ9B,YAAY,MAAM,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,WAAW,YAAS,EAAE,wBAAwB,EAAE,OAAO,EAgBrH;IAOD,SAAS,CAAC,QAAQ,EAAE,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,CAKvD;IAOD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,aAAa,CAAC,SAAS,CAAC,CAKhE;IAOD,WAAW,CAAC,QAAQ,EAAE,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC,CAK3D;IAOD,cAAc,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC,SAAS,CAAC,CAKjE;IAMD,IAAI,cAAc,IAAI,OAAO,CAE5B;IAOD,cAAc,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC,SAAS,CAAC,CAKjE;IAOD,mBAAmB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,aAAa,CAAC,SAAS,CAAC,CAK3E;IAED,OAAO,CAAC,mBAAmB;CAgB9B"}
@@ -66,6 +66,7 @@ var isNotAvailable = require('../availability/isNotAvailable.js');
66
66
  /** @inheritdoc */ exceptionStackTrace;
67
67
  /** @inheritdoc */ authorizationFailureReason;
68
68
  /** @inheritdoc */ isRetryable;
69
+ /** Whether no server handler was registered, so execution or validation did not run. */ isMissingHandler;
69
70
  /** @inheritdoc */ response;
70
71
  /**
71
72
  * Creates an instance of command result.
@@ -84,14 +85,9 @@ var isNotAvailable = require('../availability/isNotAvailable.js');
84
85
  this.authorizationFailureReason = result.authorizationFailureReason;
85
86
  // Older servers do not report retryable failures; none of their results are.
86
87
  this.isRetryable = result.isRetryable ?? false;
87
- if (result.response !== undefined && result.response !== null) {
88
- const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;
89
- if (isResponseTypeEnumerable) {
90
- this.response = Array.isArray(result.response) ? isPrimitive ? Array.from(result.response) : fundamentals.JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response) : [];
91
- } else {
92
- this.response = isPrimitive ? result.response : fundamentals.JsonSerializer.deserializeFromInstance(responseInstanceType, result.response);
93
- }
94
- }
88
+ // Older servers do not identify missing handlers.
89
+ this.isMissingHandler = result.isMissingHandler ?? false;
90
+ this.response = this.deserializeResponse(result, responseInstanceType, isResponseTypeEnumerable);
95
91
  }
96
92
  /**
97
93
  * Set up a callback for when the command was successful.
@@ -159,6 +155,16 @@ var isNotAvailable = require('../availability/isNotAvailable.js');
159
155
  }
160
156
  return this;
161
157
  }
158
+ deserializeResponse(result, responseInstanceType, isResponseTypeEnumerable) {
159
+ if (result.response === undefined || result.response === null) {
160
+ return undefined;
161
+ }
162
+ const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;
163
+ if (isResponseTypeEnumerable) {
164
+ return Array.isArray(result.response) ? isPrimitive ? Array.from(result.response) : fundamentals.JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response) : [];
165
+ }
166
+ return isPrimitive ? result.response : fundamentals.JsonSerializer.deserializeFromInstance(responseInstanceType, result.response);
167
+ }
162
168
  }
163
169
 
164
170
  exports.CommandResult = CommandResult;
@@ -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.js';\nimport { ValidationResult } from '../validation/ValidationResult.js';\nimport { isNotAvailable } from '../availability/isNotAvailable.js';\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 onNotAvailable callback.\n */\ntype OnNotAvailable = () => 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 reason?: string;\n reasonDetail?: string;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n isRetryable?: boolean;\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 reason: _.reason,\n reasonDetail: _.reasonDetail\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 isRetryable: boolean;\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, _.reason, _.reasonDetail));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n // Older servers do not report retryable failures; none of their results are.\n this.isRetryable = result.isRetryable ?? false;\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 * Gets whether the command was refused because its part of the application is not available to the caller.\n * This is not the same as being forbidden: the caller is not told whether it would have been allowed.\n */\n get isNotAvailable(): boolean {\n return isNotAvailable(this);\n }\n\n /**\n * Set up a callback for when the command was refused because its part of the application is not available.\n * @param {OnNotAvailable} callback The callback to call when the command was not available.\n * @returns {CommandResult} The instance of the command result.\n */\n onNotAvailable(callback: OnNotAvailable): CommandResult<TResponse> {\n if (this.isNotAvailable) {\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":["CommandResult","empty","correlationId","Guid","toString","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","authorizationFailureReason","response","Object","failed","validationFailed","map","_","severity","message","members","state","reason","reasonDetail","isRetryable","result","responseInstanceType","isResponseTypeEnumerable","parse","ValidationResult","undefined","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance","onSuccess","callback","onFailed","onException","onUnauthorized","isNotAvailable","onNotAvailable","onValidationFailure"],"mappings":";;;;;;AAAA;AACA;AA8DA;;AAEC,IACM,MAAMA,aAAAA,CAAAA;IAET,OAAOC,KAAAA,GAAuB,IAAID,aAAAA,CAAc;QAC5CE,aAAAA,EAAeC,iBAAAA,CAAKF,KAAK,CAACG,QAAQ,EAAA;QAClCC,SAAAA,EAAW,IAAA;QACXC,YAAAA,EAAc,IAAA;QACdC,OAAAA,EAAS,IAAA;QACTC,aAAAA,EAAe,KAAA;AACfC,QAAAA,iBAAAA,EAAmB,EAAE;AACrBC,QAAAA,iBAAAA,EAAmB,EAAE;QACrBC,mBAAAA,EAAqB,EAAA;QACrBC,0BAAAA,EAA4B,EAAA;QAC5BC,QAAAA,EAAU;AACd,KAAA,EAAGC,QAAQ,KAAA,CAAA;AAEX,IAAA,OAAOC,SAAS,CAACL,iBAAAA,GAAAA;AACb,QAAA,OAAO,IAAIV,aAAAA,CAAc;YACrBE,aAAAA,EAAeC,iBAAAA,CAAKF,KAAK,CAACG,QAAQ,EAAA;YAClCC,SAAAA,EAAW,KAAA;YACXC,YAAAA,EAAc,IAAA;YACdC,OAAAA,EAAS,IAAA;YACTC,aAAAA,EAAe,IAAA;AACfC,YAAAA,iBAAAA,EAAmB,EAAE;YACrBC,iBAAAA,EAAmBA,iBAAAA;YACnBC,mBAAAA,EAAqB,EAAA;YACrBC,0BAAAA,EAA4B,EAAA;YAC5BC,QAAAA,EAAU;AACd,SAAA,EAAGC,MAAAA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IAAI,CAAC,IAAI,CAACpC,OAAO,EAAE;YACfoC,QAAAA,CAAS,IAAI,CAAClC,iBAAiB,CAAA;AACnC,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AACJ;;"}
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.js';\nimport { ValidationResult } from '../validation/ValidationResult.js';\nimport { isNotAvailable } from '../availability/isNotAvailable.js';\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 onNotAvailable callback.\n */\ntype OnNotAvailable = () => 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 reason?: string;\n reasonDetail?: string;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n isRetryable?: boolean;\n isMissingHandler?: boolean;\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 reason: _.reason,\n reasonDetail: _.reasonDetail\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 isRetryable: boolean;\n\n /** Whether no server handler was registered, so execution or validation did not run. */\n readonly isMissingHandler: boolean;\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, _.reason, _.reasonDetail));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n // Older servers do not report retryable failures; none of their results are.\n this.isRetryable = result.isRetryable ?? false;\n\n // Older servers do not identify missing handlers.\n this.isMissingHandler = result.isMissingHandler ?? false;\n this.response = this.deserializeResponse(result, responseInstanceType, isResponseTypeEnumerable);\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 * Gets whether the command was refused because its part of the application is not available to the caller.\n * This is not the same as being forbidden: the caller is not told whether it would have been allowed.\n */\n get isNotAvailable(): boolean {\n return isNotAvailable(this);\n }\n\n /**\n * Set up a callback for when the command was refused because its part of the application is not available.\n * @param {OnNotAvailable} callback The callback to call when the command was not available.\n * @returns {CommandResult} The instance of the command result.\n */\n onNotAvailable(callback: OnNotAvailable): CommandResult<TResponse> {\n if (this.isNotAvailable) {\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 private deserializeResponse(result: ServerCommandResult, responseInstanceType: Constructor, isResponseTypeEnumerable: boolean): TResponse | undefined {\n if (result.response === undefined || result.response === null) {\n return undefined;\n }\n const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;\n if (isResponseTypeEnumerable) {\n return (Array.isArray(result.response)\n ? (isPrimitive\n ? Array.from(result.response)\n : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))\n : []) as TResponse;\n }\n return (isPrimitive\n ? result.response\n : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response)) as TResponse;\n }\n}\n"],"names":["CommandResult","empty","correlationId","Guid","toString","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","authorizationFailureReason","response","Object","failed","validationFailed","map","_","severity","message","members","state","reason","reasonDetail","isRetryable","isMissingHandler","result","responseInstanceType","isResponseTypeEnumerable","parse","ValidationResult","deserializeResponse","onSuccess","callback","onFailed","onException","onUnauthorized","isNotAvailable","onNotAvailable","onValidationFailure","undefined","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance"],"mappings":";;;;;;AAAA;AACA;AA+DA;;AAEC,IACM,MAAMA,aAAAA,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13
13
  get isValid(): boolean;
14
14
  get hasExceptions(): boolean;
15
+ get isMissingHandler(): boolean;
15
16
  get validationResults(): ValidationResult[];
16
17
  get exceptionMessages(): string[];
17
18
  get authorizationFailureReason(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"CommandResults.d.ts","sourceRoot":"","sources":["../../../commands/CommandResults.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,KAAK,gBAAgB,GAAG,CAAC,aAAa,EAAE,aAAa,KAAK,OAAO,CAAC;AAGlE,qBAAa,cAAe,YAAW,cAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,yBAAyB;IAAtD,YAA6B,yBAAyB,EAAE,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,EAClF;IAGD,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAc;IAG1C,IAAI,SAAS,IAAI,OAAO,CAEvB;IAGD,IAAI,YAAY,IAAI,OAAO,CAE1B;IAGD,IAAI,OAAO,IAAI,OAAO,CAErB;IAGD,IAAI,aAAa,IAAI,OAAO,CAE3B;IAGD,IAAI,iBAAiB,IAAI,gBAAgB,EAAE,CAQ1C;IAGD,IAAI,iBAAiB,IAAI,MAAM,EAAE,CAQhC;IAGD,IAAI,0BAA0B,IAAI,MAAM,CAUvC;IAGD,IAAI,mBAAmB,IAAI,MAAM,CAShC;IAGD,UAAU,CAAC,QAAQ,EAAE,gBAAgB,WAOpC;IAED,SAAS,CAAC,QAAQ,EAAE,gBAAgB,WAOnC;CACJ"}
1
+ {"version":3,"file":"CommandResults.d.ts","sourceRoot":"","sources":["../../../commands/CommandResults.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,KAAK,gBAAgB,GAAG,CAAC,aAAa,EAAE,aAAa,KAAK,OAAO,CAAC;AAGlE,qBAAa,cAAe,YAAW,cAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,yBAAyB;IAAtD,YAA6B,yBAAyB,EAAE,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,EAClF;IAGD,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAc;IAG1C,IAAI,SAAS,IAAI,OAAO,CAEvB;IAGD,IAAI,YAAY,IAAI,OAAO,CAE1B;IAGD,IAAI,OAAO,IAAI,OAAO,CAErB;IAGD,IAAI,aAAa,IAAI,OAAO,CAE3B;IAGD,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAGD,IAAI,iBAAiB,IAAI,gBAAgB,EAAE,CAQ1C;IAGD,IAAI,iBAAiB,IAAI,MAAM,EAAE,CAQhC;IAGD,IAAI,0BAA0B,IAAI,MAAM,CAUvC;IAGD,IAAI,mBAAmB,IAAI,MAAM,CAShC;IAGD,UAAU,CAAC,QAAQ,EAAE,gBAAgB,WAOpC;IAED,SAAS,CAAC,QAAQ,EAAE,gBAAgB,WAOnC;CACJ"}
@@ -22,6 +22,9 @@ class CommandResults {
22
22
  /** @inheritdoc */ get hasExceptions() {
23
23
  return this.isAnyTrue((_)=>_.hasExceptions);
24
24
  }
25
+ /** @inheritdoc */ get isMissingHandler() {
26
+ return this.isAnyTrue((_)=>_.isMissingHandler === true);
27
+ }
25
28
  /** @inheritdoc */ get validationResults() {
26
29
  const errors = [];
27
30
  for (const result of this._commandResultsPerCommand.values()){
@@ -1 +1 @@
1
- {"version":3,"file":"CommandResults.js","sources":["../../../commands/CommandResults.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 { ValidationResult } from '../validation/ValidationResult.js';\nimport { Command } from './Command.js';\nimport { CommandResult } from './CommandResult.js';\nimport { ICommandResult } from './ICommandResult.js';\n\ntype GetSpecificState = (commandResult: CommandResult) => boolean;\n\n\nexport class CommandResults implements ICommandResult {\n constructor(private readonly _commandResultsPerCommand: Map<Command, CommandResult>) {\n }\n\n /** @inheritdoc */\n readonly correlationId: Guid = Guid.empty;\n\n /** @inheritdoc */\n get isSuccess(): boolean {\n return this.isAnyFalse(_ => _.isSuccess);\n }\n\n /** @inheritdoc */\n get isAuthorized(): boolean {\n return this.isAnyFalse(_ => _.isAuthorized);\n }\n\n /** @inheritdoc */\n get isValid(): boolean {\n return this.isAnyFalse(_ => _.isValid);\n }\n\n /** @inheritdoc */\n get hasExceptions(): boolean {\n return this.isAnyTrue(_ => _.hasExceptions);\n }\n\n /** @inheritdoc */\n get validationResults(): ValidationResult[] {\n const errors: ValidationResult[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n result.validationResults.forEach(_ => errors.push(_));\n }\n\n return errors;\n }\n\n /** @inheritdoc */\n get exceptionMessages(): string[] {\n const messages: string[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n result.exceptionMessages.forEach(_ => messages.push(_));\n }\n\n return messages;\n }\n\n /** @inheritdoc */\n get authorizationFailureReason(): string {\n const reasons: string[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n if (result.authorizationFailureReason) {\n reasons.push(result.authorizationFailureReason);\n }\n }\n\n return reasons.join('; ');\n }\n\n /** @inheritdoc */\n get exceptionStackTrace(): string {\n let stackTraces = '';\n\n for (const result of this._commandResultsPerCommand.values()) {\n stackTraces = stackTraces + '\\n' + result.exceptionStackTrace;\n }\n\n return stackTraces;\n\n }\n\n\n isAnyFalse(callback: GetSpecificState) {\n for (const result of this._commandResultsPerCommand.values()) {\n if (!callback(result)) {\n return false;\n }\n }\n return true;\n }\n\n isAnyTrue(callback: GetSpecificState) {\n for (const result of this._commandResultsPerCommand.values()) {\n if (callback(result)) {\n return true;\n }\n }\n return false;\n }\n}\n"],"names":["CommandResults","_commandResultsPerCommand","correlationId","Guid","empty","isSuccess","isAnyFalse","_","isAuthorized","isValid","hasExceptions","isAnyTrue","validationResults","errors","result","values","forEach","push","exceptionMessages","messages","authorizationFailureReason","reasons","join","exceptionStackTrace","stackTraces","callback"],"mappings":";;;;AAAA;AACA;AAWO,MAAMA,cAAAA,CAAAA;;IACT,WAAA,CAA6BC,yBAAsD,CAAE;aAAxDA,yBAAAA,GAAAA,yBAAAA;AAC7B,IAAA;AAEA,uBACSC,aAAAA,GAAsBC,iBAAAA,CAAKC,KAAK;uBAGzC,IAAIC,SAAAA,GAAqB;AACrB,QAAA,OAAO,IAAI,CAACC,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEF,SAAS,CAAA;AAC3C,IAAA;uBAGA,IAAIG,YAAAA,GAAwB;AACxB,QAAA,OAAO,IAAI,CAACF,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEC,YAAY,CAAA;AAC9C,IAAA;uBAGA,IAAIC,OAAAA,GAAmB;AACnB,QAAA,OAAO,IAAI,CAACH,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEE,OAAO,CAAA;AACzC,IAAA;uBAGA,IAAIC,aAAAA,GAAyB;AACzB,QAAA,OAAO,IAAI,CAACC,SAAS,CAACJ,CAAAA,CAAAA,GAAKA,EAAEG,aAAa,CAAA;AAC9C,IAAA;uBAGA,IAAIE,iBAAAA,GAAwC;AACxC,QAAA,MAAMC,SAA6B,EAAE;AAErC,QAAA,KAAK,MAAMC,MAAAA,IAAU,IAAI,CAACb,yBAAyB,CAACc,MAAM,EAAA,CAAI;YAC1DD,MAAAA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A,EAAS;gBACnB,OAAO,KAAA;AACX,YAAA;AACJ,QAAA;QACA,OAAO,IAAA;AACX,IAAA;AAEAH,IAAAA,SAAAA,CAAUc,QAA0B,EAAE;AAClC,QAAA,KAAK,MAAMX,MAAAA,IAAU,IAAI,CAACb,yBAAyB,CAACc,MAAM,EAAA,CAAI;AAC1D,YAAA,IAAIU,SAASX,MAAAA,CAAAA,EAAS;gBAClB,OAAO,IAAA;AACX,YAAA;AACJ,QAAA;QACA,OAAO,KAAA;AACX,IAAA;AACJ;;"}
1
+ {"version":3,"file":"CommandResults.js","sources":["../../../commands/CommandResults.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 { ValidationResult } from '../validation/ValidationResult.js';\nimport { Command } from './Command.js';\nimport { CommandResult } from './CommandResult.js';\nimport { ICommandResult } from './ICommandResult.js';\n\ntype GetSpecificState = (commandResult: CommandResult) => boolean;\n\n\nexport class CommandResults implements ICommandResult {\n constructor(private readonly _commandResultsPerCommand: Map<Command, CommandResult>) {\n }\n\n /** @inheritdoc */\n readonly correlationId: Guid = Guid.empty;\n\n /** @inheritdoc */\n get isSuccess(): boolean {\n return this.isAnyFalse(_ => _.isSuccess);\n }\n\n /** @inheritdoc */\n get isAuthorized(): boolean {\n return this.isAnyFalse(_ => _.isAuthorized);\n }\n\n /** @inheritdoc */\n get isValid(): boolean {\n return this.isAnyFalse(_ => _.isValid);\n }\n\n /** @inheritdoc */\n get hasExceptions(): boolean {\n return this.isAnyTrue(_ => _.hasExceptions);\n }\n\n /** @inheritdoc */\n get isMissingHandler(): boolean {\n return this.isAnyTrue(_ => _.isMissingHandler === true);\n }\n\n /** @inheritdoc */\n get validationResults(): ValidationResult[] {\n const errors: ValidationResult[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n result.validationResults.forEach(_ => errors.push(_));\n }\n\n return errors;\n }\n\n /** @inheritdoc */\n get exceptionMessages(): string[] {\n const messages: string[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n result.exceptionMessages.forEach(_ => messages.push(_));\n }\n\n return messages;\n }\n\n /** @inheritdoc */\n get authorizationFailureReason(): string {\n const reasons: string[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n if (result.authorizationFailureReason) {\n reasons.push(result.authorizationFailureReason);\n }\n }\n\n return reasons.join('; ');\n }\n\n /** @inheritdoc */\n get exceptionStackTrace(): string {\n let stackTraces = '';\n\n for (const result of this._commandResultsPerCommand.values()) {\n stackTraces = stackTraces + '\\n' + result.exceptionStackTrace;\n }\n\n return stackTraces;\n\n }\n\n\n isAnyFalse(callback: GetSpecificState) {\n for (const result of this._commandResultsPerCommand.values()) {\n if (!callback(result)) {\n return false;\n }\n }\n return true;\n }\n\n isAnyTrue(callback: GetSpecificState) {\n for (const result of this._commandResultsPerCommand.values()) {\n if (callback(result)) {\n return true;\n }\n }\n return false;\n }\n}\n"],"names":["CommandResults","_commandResultsPerCommand","correlationId","Guid","empty","isSuccess","isAnyFalse","_","isAuthorized","isValid","hasExceptions","isAnyTrue","isMissingHandler","validationResults","errors","result","values","forEach","push","exceptionMessages","messages","authorizationFailureReason","reasons","join","exceptionStackTrace","stackTraces","callback"],"mappings":";;;;AAAA;AACA;AAWO,MAAMA,cAAAA,CAAAA;;IACT,WAAA,CAA6BC,yBAAsD,CAAE;aAAxDA,yBAAAA,GAAAA,yBAAAA;AAC7B,IAAA;AAEA,uBACSC,aAAAA,GAAsBC,iBAAAA,CAAKC,KAAK;uBAGzC,IAAIC,SAAAA,GAAqB;AACrB,QAAA,OAAO,IAAI,CAACC,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEF,SAAS,CAAA;AAC3C,IAAA;uBAGA,IAAIG,YAAAA,GAAwB;AACxB,QAAA,OAAO,IAAI,CAACF,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEC,YAAY,CAAA;AAC9C,IAAA;uBAGA,IAAIC,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M,0BAA0B,CAAA;AAClD,YAAA;AACJ,QAAA;QAEA,OAAOC,OAAAA,CAAQC,IAAI,CAAC,IAAA,CAAA;AACxB,IAAA;uBAGA,IAAIC,mBAAAA,GAA8B;AAC9B,QAAA,IAAIC,WAAAA,GAAc,EAAA;AAElB,QAAA,KAAK,MAAMV,MAAAA,IAAU,IAAI,CAACd,yBAAyB,CAACe,MAAM,EAAA,CAAI;YAC1DS,WAAAA,GAAcA,WAAAA,GAAc,IAAA,GAAOV,MAAAA,CAAOS,mBAAmB;AACjE,QAAA;QAEA,OAAOC,WAAAA;AAEX,IAAA;AAGAnB,IAAAA,UAAAA,CAAWoB,QAA0B,EAAE;AACnC,QAAA,KAAK,MAAMX,MAAAA,IAAU,IAAI,CAACd,yBAAyB,CAACe,MAAM,EAAA,CAAI;YAC1D,IAAI,CAACU,SAASX,MAAAA,CAAAA,EAAS;gBACnB,OAAO,KAAA;AACX,YAAA;AACJ,QAAA;QACA,OAAO,IAAA;AACX,IAAA;AAEAJ,IAAAA,SAAAA,CAAUe,QAA0B,EAAE;AAClC,QAAA,KAAK,MAAMX,MAAAA,IAAU,IAAI,CAACd,yBAAyB,CAACe,MAAM,EAAA,CAAI;AAC1D,YAAA,IAAIU,SAASX,MAAAA,CAAAA,EAAS;gBAClB,OAAO,IAAA;AACX,YAAA;AACJ,QAAA;QACA,OAAO,KAAA;AACX,IAAA;AACJ;;"}
@@ -10,6 +10,7 @@ export interface ICommandResult<TResponse = object> {
10
10
  readonly exceptionMessages: string[];
11
11
  readonly authorizationFailureReason: string;
12
12
  readonly isRetryable?: boolean;
13
+ readonly isMissingHandler?: boolean;
13
14
  readonly exceptionStackTrace: string;
14
15
  readonly response?: TResponse;
15
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ICommandResult.d.ts","sourceRoot":"","sources":["../../../commands/ICommandResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,gB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M5C,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAGhC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAKnC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IAKrC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAClC"}
@@ -26,6 +26,7 @@ type ServerCommandResult = {
26
26
  exceptionStackTrace: string;
27
27
  authorizationFailureReason: string;
28
28
  isRetryable?: boolean;
29
+ isMissingHandler?: boolean;
29
30
  response: any;
30
31
  };
31
32
  export declare class CommandResult<TResponse = object> implements ICommandResult<TResponse> {
@@ -42,6 +43,7 @@ export declare class CommandResult<TResponse = object> implements ICommandResult
42
43
  readonly exceptionStackTrace: string;
43
44
  readonly authorizationFailureReason: string;
44
45
  readonly isRetryable: boolean;
46
+ readonly isMissingHandler: boolean;
45
47
  readonly response?: TResponse;
46
48
  constructor(result: ServerCommandResult, responseInstanceType: Constructor | undefined, isResponseTypeEnumerable: boolean);
47
49
  onSuccess(callback: OnSuccess): CommandResult<TResponse>;
@@ -51,6 +53,7 @@ export declare class CommandResult<TResponse = object> implements ICommandResult
51
53
  get isNotAvailable(): boolean;
52
54
  onNotAvailable(callback: OnNotAvailable): CommandResult<TResponse>;
53
55
  onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse>;
56
+ private deserializeResponse;
54
57
  }
55
58
  export {};
56
59
  //# sourceMappingURL=CommandResult.d.ts.map
@@ -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,qBAAqB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAKnE,KAAK,SAAS,GAAG,CA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,CAAC,SAAS,CAAC,CAKvD;IAOD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,aAAa,CAAC,SAAS,CAAC,CAKhE;IAOD,WAAW,CAAC,QAAQ,EAAE,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC,CAK3D;IAOD,cAAc,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC,SAAS,CAAC,CAKjE;IAMD,IAAI,cAAc,IAAI,OAAO,CAE5B;IAOD,cAAc,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC,SAAS,CAAC,CAKjE;IAOD,mBAAmB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,aAAa,CAAC,SAAS,CAAC,CAK3E;IAED,OAAO,CAAC,mBAAmB;CAgB9B"}
@@ -64,6 +64,7 @@ import { isNotAvailable } from '../availability/isNotAvailable.js';
64
64
  /** @inheritdoc */ exceptionStackTrace;
65
65
  /** @inheritdoc */ authorizationFailureReason;
66
66
  /** @inheritdoc */ isRetryable;
67
+ /** Whether no server handler was registered, so execution or validation did not run. */ isMissingHandler;
67
68
  /** @inheritdoc */ response;
68
69
  /**
69
70
  * Creates an instance of command result.
@@ -82,14 +83,9 @@ import { isNotAvailable } from '../availability/isNotAvailable.js';
82
83
  this.authorizationFailureReason = result.authorizationFailureReason;
83
84
  // Older servers do not report retryable failures; none of their results are.
84
85
  this.isRetryable = result.isRetryable ?? false;
85
- if (result.response !== undefined && result.response !== null) {
86
- const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;
87
- if (isResponseTypeEnumerable) {
88
- this.response = Array.isArray(result.response) ? isPrimitive ? Array.from(result.response) : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response) : [];
89
- } else {
90
- this.response = isPrimitive ? result.response : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response);
91
- }
92
- }
86
+ // Older servers do not identify missing handlers.
87
+ this.isMissingHandler = result.isMissingHandler ?? false;
88
+ this.response = this.deserializeResponse(result, responseInstanceType, isResponseTypeEnumerable);
93
89
  }
94
90
  /**
95
91
  * Set up a callback for when the command was successful.
@@ -157,6 +153,16 @@ import { isNotAvailable } from '../availability/isNotAvailable.js';
157
153
  }
158
154
  return this;
159
155
  }
156
+ deserializeResponse(result, responseInstanceType, isResponseTypeEnumerable) {
157
+ if (result.response === undefined || result.response === null) {
158
+ return undefined;
159
+ }
160
+ const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;
161
+ if (isResponseTypeEnumerable) {
162
+ return Array.isArray(result.response) ? isPrimitive ? Array.from(result.response) : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response) : [];
163
+ }
164
+ return isPrimitive ? result.response : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response);
165
+ }
160
166
  }
161
167
 
162
168
  export { CommandResult };
@@ -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.js';\nimport { ValidationResult } from '../validation/ValidationResult.js';\nimport { isNotAvailable } from '../availability/isNotAvailable.js';\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 onNotAvailable callback.\n */\ntype OnNotAvailable = () => 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 reason?: string;\n reasonDetail?: string;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n isRetryable?: boolean;\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 reason: _.reason,\n reasonDetail: _.reasonDetail\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 isRetryable: boolean;\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, _.reason, _.reasonDetail));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n // Older servers do not report retryable failures; none of their results are.\n this.isRetryable = result.isRetryable ?? false;\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 * Gets whether the command was refused because its part of the application is not available to the caller.\n * This is not the same as being forbidden: the caller is not told whether it would have been allowed.\n */\n get isNotAvailable(): boolean {\n return isNotAvailable(this);\n }\n\n /**\n * Set up a callback for when the command was refused because its part of the application is not available.\n * @param {OnNotAvailable} callback The callback to call when the command was not available.\n * @returns {CommandResult} The instance of the command result.\n */\n onNotAvailable(callback: OnNotAvailable): CommandResult<TResponse> {\n if (this.isNotAvailable) {\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":["CommandResult","empty","correlationId","Guid","toString","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","authorizationFailureReason","response","Object","failed","validationFailed","map","_","severity","message","members","state","reason","reasonDetail","isRetryable","result","responseInstanceType","isResponseTypeEnumerable","parse","ValidationResult","undefined","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance","onSuccess","callback","onFailed","onException","onUnauthorized","isNotAvailable","onNotAvailable","onValidationFailure"],"mappings":";;;;AAAA;AACA;AA8DA;;AAEC,IACM,MAAMA,aAAAA,CAAAA;IAET,OAAOC,KAAAA,GAAuB,IAAID,aAAAA,CAAc;QAC5CE,aAAAA,EAAeC,IAAAA,CAAKF,KAAK,CAACG,QAAQ,EAAA;QAClCC,SAAAA,EAAW,IAAA;QACXC,YAAAA,EAAc,IAAA;QACdC,OAAAA,EAAS,IAAA;QACTC,aAAAA,EAAe,KAAA;AACfC,QAAAA,iBAAAA,EAAmB,EAAE;AACrBC,QAAAA,iBAAAA,EAAmB,EAAE;QACrBC,mBAAAA,EAAqB,EAAA;QACrBC,0BAAAA,EAA4B,EAAA;QAC5BC,QAAAA,EAAU;AACd,KAAA,EAAGC,QAAQ,KAAA,CAAA;AAEX,IAAA,OAAOC,SAAS,CAACL,iBAAAA,GAAAA;AACb,QAAA,OAAO,IAAIV,aAAAA,CAAc;YACrBE,aAAAA,EAAeC,IAAAA,CAAKF,KAAK,CAACG,QAAQ,EAAA;YAClCC,SAAAA,EAAW,KAAA;YACXC,YAAAA,EAAc,IAAA;YACdC,OAAAA,EAAS,IAAA;YACTC,aAAAA,EAAe,IAAA;AACfC,YAAAA,iBAAAA,EAAmB,EAAE;YACrBC,iBAAAA,EAAmBA,iBAAAA;YACnBC,mBAAAA,EAAqB,EAAA;YACrBC,0BAAAA,EAA4B,EAAA;YAC5BC,QAAAA,EAAU;AACd,SAAA,EAAGC,MAAAA,EAAQ,KAAA,CAAA;IACf,CAAA;AAEA,IAAA,OAAOE,mBAAmB,CAACP,iBAAAA,GAAAA;AACvB,QAAA,OAAO,IAAIT,aAAAA,CAAc;YACrBE,aAAAA,EAAeC,IAAAA,CAAKF,KAAK,CAACG,QAAQ,EAAA;YAClCC,SAAAA,EAAW,KAAA;YACXC,YAAAA,EAAc,IAAA;YACdC,OAAAA,EAAS,KAAA;YACTC,aAA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AAS,IAAI,CAAC9B,QAAQ,CAAA;AAC1B,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKA+B,QAAAA,CAASD,QAA6B,EAA4B;AAC9D,QAAA,IAAI,CAAC,IAAI,CAACtC,SAAS,EAAE;AACjBsC,YAAAA,QAAAA,CAAS,IAAI,CAAA;AACjB,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAE,WAAAA,CAAYF,QAAqB,EAA4B;QACzD,IAAI,IAAI,CAACnC,aAAa,EAAE;AACpBmC,YAAAA,QAAAA,CAAS,IAAI,CAACjC,iBAAiB,EAAE,IAAI,CAACC,mBAAmB,CAAA;AAC7D,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAmC,cAAAA,CAAeH,QAAwB,EAA4B;AAC/D,QAAA,IAAI,CAAC,IAAI,CAACrC,YAAY,EAAE;AACpBqC,YAAAA,QAAAA,EAAAA;AACJ,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;AAGC,QACD,IAAII,cAAAA,GAA0B;AAC1B,QAAA,OAAOA,eAAe,IAAI,CAAA;AAC9B,IAAA;AAEA;;;;QAKAC,cAAAA,CAAeL,QAAwB,EAA4B;QAC/D,IAAI,IAAI,CAACI,cAAc,EAAE;AACrBJ,YAAAA,QAAAA,EAAAA;AACJ,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAM,mBAAAA,CAAoBN,QAA6B,EAA4B;AACzE,QAAA,IAAI,CAAC,IAAI,CAACpC,OAAO,EAAE;YACfoC,QAAAA,CAAS,IAAI,CAAClC,iBAAiB,CAAA;AACnC,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AACJ;;"}
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.js';\nimport { ValidationResult } from '../validation/ValidationResult.js';\nimport { isNotAvailable } from '../availability/isNotAvailable.js';\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 onNotAvailable callback.\n */\ntype OnNotAvailable = () => 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 reason?: string;\n reasonDetail?: string;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n isRetryable?: boolean;\n isMissingHandler?: boolean;\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 reason: _.reason,\n reasonDetail: _.reasonDetail\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 isRetryable: boolean;\n\n /** Whether no server handler was registered, so execution or validation did not run. */\n readonly isMissingHandler: boolean;\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, _.reason, _.reasonDetail));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n // Older servers do not report retryable failures; none of their results are.\n this.isRetryable = result.isRetryable ?? false;\n\n // Older servers do not identify missing handlers.\n this.isMissingHandler = result.isMissingHandler ?? false;\n this.response = this.deserializeResponse(result, responseInstanceType, isResponseTypeEnumerable);\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 * Gets whether the command was refused because its part of the application is not available to the caller.\n * This is not the same as being forbidden: the caller is not told whether it would have been allowed.\n */\n get isNotAvailable(): boolean {\n return isNotAvailable(this);\n }\n\n /**\n * Set up a callback for when the command was refused because its part of the application is not available.\n * @param {OnNotAvailable} callback The callback to call when the command was not available.\n * @returns {CommandResult} The instance of the command result.\n */\n onNotAvailable(callback: OnNotAvailable): CommandResult<TResponse> {\n if (this.isNotAvailable) {\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 private deserializeResponse(result: ServerCommandResult, responseInstanceType: Constructor, isResponseTypeEnumerable: boolean): TResponse | undefined {\n if (result.response === undefined || result.response === null) {\n return undefined;\n }\n const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;\n if (isResponseTypeEnumerable) {\n return (Array.isArray(result.response)\n ? (isPrimitive\n ? Array.from(result.response)\n : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))\n : []) as TResponse;\n }\n return (isPrimitive\n ? result.response\n : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response)) as TResponse;\n }\n}\n"],"names":["CommandResult","empty","correlationId","Guid","toString","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","authorizationFailureReason","response","Object","failed","validationFailed","map","_","severity","message","members","state","reason","reasonDetail","isRetryable","isMissingHandler","result","responseInstanceType","isResponseTypeEnumerable","parse","ValidationResult","deserializeResponse","onSuccess","callback","onFailed","onException","onUnauthorized","isNotAvailable","onNotAvailable","onValidationFailure","undefined","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance"],"mappings":";;;;AAAA;AACA;AA+DA;;AAEC,IACM,MAAMA,aAAAA,CAAAA;IAET,OAAOC,KAAAA,GAAuB,IAAID,aAAAA,CAAc;QAC5CE,aAAAA,EAAeC,IAAAA,CAAKF,KAAK,CAACG,QAAQ,EAAA;QAClCC,SAAAA,EAAW,IAAA;QACXC,YAAAA,EAAc,IAAA;QACdC,OAAAA,EAAS,IAAA;QACTC,aAAAA,EAAe,KAAA;AACfC,QAAAA,iBAAAA,EAAmB,EAAE;AACrBC,QAAAA,iBAAAA,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A,CAAoBN,QAA6B,EAA4B;AACzE,QAAA,IAAI,CAAC,IAAI,CAAC3B,OAAO,EAAE;YACf2B,QAAAA,CAAS,IAAI,CAACzB,iBAAiB,CAAA;AACnC,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEQuB,IAAAA,mBAAAA,CAAoBL,MAA2B,EAAEC,oBAAiC,EAAEC,wBAAiC,EAAyB;AAClJ,QAAA,IAAIF,OAAOd,QAAQ,KAAK4B,aAAad,MAAAA,CAAOd,QAAQ,KAAK,IAAA,EAAM;YAC3D,OAAO4B,SAAAA;AACX,QAAA;AACA,QAAA,MAAMC,WAAAA,GAAcd,oBAAAA,KAAyBe,MAAAA,IAAUf,oBAAAA,KAAyBgB,UAAUhB,oBAAAA,KAAyBiB,OAAAA;AACnH,QAAA,IAAIhB,wBAAAA,EAA0B;YAC1B,OAAQiB,KAAAA,CAAMC,OAAO,CAACpB,MAAAA,CAAOd,QAAQ,CAAA,GAC9B6B,WAAAA,GACGI,MAAME,IAAI,CAACrB,OAAOd,QAAQ,CAAA,GAC1BoC,eAAeC,4BAA4B,CAACtB,sBAAsBD,MAAAA,CAAOd,QAAQ,IACrF,EAAE;AACZ,QAAA;QACA,OAAQ6B,WAAAA,GACFf,OAAOd,QAAQ,GACfoC,eAAeE,uBAAuB,CAACvB,oBAAAA,EAAsBD,MAAAA,CAAOd,QAAQ,CAAA;AACtF,IAAA;AACJ;;"}
@@ -12,6 +12,7 @@ export declare class CommandResults implements ICommandResult {
12
12
  get isAuthorized(): boolean;
13
13
  get isValid(): boolean;
14
14
  get hasExceptions(): boolean;
15
+ get isMissingHandler(): boolean;
15
16
  get validationResults(): ValidationResult[];
16
17
  get exceptionMessages(): string[];
17
18
  get authorizationFailureReason(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"CommandResults.d.ts","sourceRoot":"","sources":["../../../commands/CommandResults.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5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AG,CAAC,aAAa,EAAE,aAAa,KAAK,OAAO,CAAC;AAGlE,qBAAa,cAAe,YAAW,cAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,yBAAyB;IAAtD,YAA6B,yBAAyB,EAAE,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,EAClF;IAGD,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAc;IAG1C,IAAI,SAAS,IAAI,OAAO,CAEvB;IAGD,IAAI,YAAY,IAAI,OAAO,CAE1B;IAGD,IAAI,OAAO,IAAI,OAAO,CAErB;IAGD,IAAI,aAAa,IAAI,OAAO,CAE3B;IAGD,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAGD,IAAI,iBAAiB,IAAI,gBAAgB,EAAE,CAQ1C;IAGD,IAAI,iBAAiB,IAAI,MAAM,EAAE,CAQhC;IAGD,IAAI,0BAA0B,IAAI,MAAM,CAUvC;IAGD,IAAI,mBAAmB,IAAI,MAAM,CAShC;IAGD,UAAU,CAAC,QAAQ,EAAE,gBAAgB,WAOpC;IAED,SAAS,CAAC,QAAQ,EAAE,gBAAgB,WAOnC;CACJ"}
@@ -20,6 +20,9 @@ class CommandResults {
20
20
  /** @inheritdoc */ get hasExceptions() {
21
21
  return this.isAnyTrue((_)=>_.hasExceptions);
22
22
  }
23
+ /** @inheritdoc */ get isMissingHandler() {
24
+ return this.isAnyTrue((_)=>_.isMissingHandler === true);
25
+ }
23
26
  /** @inheritdoc */ get validationResults() {
24
27
  const errors = [];
25
28
  for (const result of this._commandResultsPerCommand.values()){
@@ -1 +1 @@
1
- {"version":3,"file":"CommandResults.js","sources":["../../../commands/CommandResults.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 { ValidationResult } from '../validation/ValidationResult.js';\nimport { Command } from './Command.js';\nimport { CommandResult } from './CommandResult.js';\nimport { ICommandResult } from './ICommandResult.js';\n\ntype GetSpecificState = (commandResult: CommandResult) => boolean;\n\n\nexport class CommandResults implements ICommandResult {\n constructor(private readonly _commandResultsPerCommand: Map<Command, CommandResult>) {\n }\n\n /** @inheritdoc */\n readonly correlationId: Guid = Guid.empty;\n\n /** @inheritdoc */\n get isSuccess(): boolean {\n return this.isAnyFalse(_ => _.isSuccess);\n }\n\n /** @inheritdoc */\n get isAuthorized(): boolean {\n return this.isAnyFalse(_ => _.isAuthorized);\n }\n\n /** @inheritdoc */\n get isValid(): boolean {\n return this.isAnyFalse(_ => _.isValid);\n }\n\n /** @inheritdoc */\n get hasExceptions(): boolean {\n return this.isAnyTrue(_ => _.hasExceptions);\n }\n\n /** @inheritdoc */\n get validationResults(): ValidationResult[] {\n const errors: ValidationResult[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n result.validationResults.forEach(_ => errors.push(_));\n }\n\n return errors;\n }\n\n /** @inheritdoc */\n get exceptionMessages(): string[] {\n const messages: string[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n result.exceptionMessages.forEach(_ => messages.push(_));\n }\n\n return messages;\n }\n\n /** @inheritdoc */\n get authorizationFailureReason(): string {\n const reasons: string[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n if (result.authorizationFailureReason) {\n reasons.push(result.authorizationFailureReason);\n }\n }\n\n return reasons.join('; ');\n }\n\n /** @inheritdoc */\n get exceptionStackTrace(): string {\n let stackTraces = '';\n\n for (const result of this._commandResultsPerCommand.values()) {\n stackTraces = stackTraces + '\\n' + result.exceptionStackTrace;\n }\n\n return stackTraces;\n\n }\n\n\n isAnyFalse(callback: GetSpecificState) {\n for (const result of this._commandResultsPerCommand.values()) {\n if (!callback(result)) {\n return false;\n }\n }\n return true;\n }\n\n isAnyTrue(callback: GetSpecificState) {\n for (const result of this._commandResultsPerCommand.values()) {\n if (callback(result)) {\n return true;\n }\n }\n return false;\n }\n}\n"],"names":["CommandResults","_commandResultsPerCommand","correlationId","Guid","empty","isSuccess","isAnyFalse","_","isAuthorized","isValid","hasExceptions","isAnyTrue","validationResults","errors","result","values","forEach","push","exceptionMessages","messages","authorizationFailureReason","reasons","join","exceptionStackTrace","stackTraces","callback"],"mappings":";;AAAA;AACA;AAWO,MAAMA,cAAAA,CAAAA;;IACT,WAAA,CAA6BC,yBAAsD,CAAE;aAAxDA,yBAAAA,GAAAA,yBAAAA;AAC7B,IAAA;AAEA,uBACSC,aAAAA,GAAsBC,IAAAA,CAAKC,KAAK;uBAGzC,IAAIC,SAAAA,GAAqB;AACrB,QAAA,OAAO,IAAI,CAACC,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEF,SAAS,CAAA;AAC3C,IAAA;uBAGA,IAAIG,YAAAA,GAAwB;AACxB,QAAA,OAAO,IAAI,CAACF,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEC,YAAY,CAAA;AAC9C,IAAA;uBAGA,IAAIC,OAAAA,GAAmB;AACnB,QAAA,OAAO,IAAI,CAACH,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEE,OAAO,CAAA;AACzC,IAAA;uBAGA,IAAIC,aAAAA,GAAyB;AACzB,QAAA,OAAO,IAAI,CAACC,SAAS,CAACJ,CAAAA,CAAAA,GAAKA,EAAEG,aAAa,CAAA;AAC9C,IAAA;uBAGA,IAAIE,iBAAAA,GAAwC;AACxC,QAAA,MAAMC,SAA6B,EAAE;AAErC,QAAA,KAAK,MAAMC,MAAAA,IAAU,IAAI,CAACb,yBAAyB,CAACc,MAAM,EAAA,CAAI;YAC1DD,MAAAA,CAAOF,iBAAiB,CAACI,OAAO,CAACT,CAAAA,CAAAA,GAAKM,MAAAA,CAAOI,IAAI,CAACV,CAAAA,CAAAA,CAAAA;AACtD,QAAA;QAEA,OAAOM,MAAAA;AACX,IAAA;uBAGA,IAAIK,iBAAAA,GAA8B;AAC9B,QAAA,MAAMC,WAAqB,EAAE;AAE7B,QAAA,KAAK,MAAML,MAAAA,IAAU,IAAI,CAACb,yBAAyB,CAACc,MAAM,EAAA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AAA;QACA,OAAO,KAAA;AACX,IAAA;AACJ;;"}
1
+ {"version":3,"file":"CommandResults.js","sources":["../../../commands/CommandResults.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 { ValidationResult } from '../validation/ValidationResult.js';\nimport { Command } from './Command.js';\nimport { CommandResult } from './CommandResult.js';\nimport { ICommandResult } from './ICommandResult.js';\n\ntype GetSpecificState = (commandResult: CommandResult) => boolean;\n\n\nexport class CommandResults implements ICommandResult {\n constructor(private readonly _commandResultsPerCommand: Map<Command, CommandResult>) {\n }\n\n /** @inheritdoc */\n readonly correlationId: Guid = Guid.empty;\n\n /** @inheritdoc */\n get isSuccess(): boolean {\n return this.isAnyFalse(_ => _.isSuccess);\n }\n\n /** @inheritdoc */\n get isAuthorized(): boolean {\n return this.isAnyFalse(_ => _.isAuthorized);\n }\n\n /** @inheritdoc */\n get isValid(): boolean {\n return this.isAnyFalse(_ => _.isValid);\n }\n\n /** @inheritdoc */\n get hasExceptions(): boolean {\n return this.isAnyTrue(_ => _.hasExceptions);\n }\n\n /** @inheritdoc */\n get isMissingHandler(): boolean {\n return this.isAnyTrue(_ => _.isMissingHandler === true);\n }\n\n /** @inheritdoc */\n get validationResults(): ValidationResult[] {\n const errors: ValidationResult[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n result.validationResults.forEach(_ => errors.push(_));\n }\n\n return errors;\n }\n\n /** @inheritdoc */\n get exceptionMessages(): string[] {\n const messages: string[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n result.exceptionMessages.forEach(_ => messages.push(_));\n }\n\n return messages;\n }\n\n /** @inheritdoc */\n get authorizationFailureReason(): string {\n const reasons: string[] = [];\n\n for (const result of this._commandResultsPerCommand.values()) {\n if (result.authorizationFailureReason) {\n reasons.push(result.authorizationFailureReason);\n }\n }\n\n return reasons.join('; ');\n }\n\n /** @inheritdoc */\n get exceptionStackTrace(): string {\n let stackTraces = '';\n\n for (const result of this._commandResultsPerCommand.values()) {\n stackTraces = stackTraces + '\\n' + result.exceptionStackTrace;\n }\n\n return stackTraces;\n\n }\n\n\n isAnyFalse(callback: GetSpecificState) {\n for (const result of this._commandResultsPerCommand.values()) {\n if (!callback(result)) {\n return false;\n }\n }\n return true;\n }\n\n isAnyTrue(callback: GetSpecificState) {\n for (const result of this._commandResultsPerCommand.values()) {\n if (callback(result)) {\n return true;\n }\n }\n return false;\n }\n}\n"],"names":["CommandResults","_commandResultsPerCommand","correlationId","Guid","empty","isSuccess","isAnyFalse","_","isAuthorized","isValid","hasExceptions","isAnyTrue","isMissingHandler","validationResults","errors","result","values","forEach","push","exceptionMessages","messages","authorizationFailureReason","reasons","join","exceptionStackTrace","stackTraces","callback"],"mappings":";;AAAA;AACA;AAWO,MAAMA,cAAAA,CAAAA;;IACT,WAAA,CAA6BC,yBAAsD,CAAE;aAAxDA,yBAAAA,GAAAA,yBAAAA;AAC7B,IAAA;AAEA,uBACSC,aAAAA,GAAsBC,IAAAA,CAAKC,KAAK;uBAGzC,IAAIC,SAAAA,GAAqB;AACrB,QAAA,OAAO,IAAI,CAACC,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEF,SAAS,CAAA;AAC3C,IAAA;uBAGA,IAAIG,YAAAA,GAAwB;AACxB,QAAA,OAAO,IAAI,CAACF,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEC,YAAY,CAAA;AAC9C,IAAA;uBAGA,IAAIC,OAAAA,GAAmB;AACnB,QAAA,OAAO,IAAI,CAACH,UAAU,CAACC,CAAAA,CAAAA,GAAKA,EAAEE,OAAO,CAAA;AACzC,IAAA;uBAGA,IAAIC,aAAAA,GAAyB;AACzB,QAAA,OAAO,IAAI,CAACC,SAAS,CAACJ,CAAAA,CAAAA,GAAKA,EAAEG,aAAa,CAAA;AAC9C,IAAA;uBAGA,IAAIE,gBAAAA,GAA4B;QAC5B,OAAO,IAAI,CAACD,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