@cratis/arc 20.69.3 → 21.0.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.
- package/commands/CommandResult.ts +2 -1
- package/commands/for_CommandResult/when_constructing_from_a_server_result_with_reasons.ts +47 -0
- package/dist/cjs/commands/CommandResult.js +1 -1
- package/dist/cjs/commands/CommandResult.js.map +1 -1
- package/dist/cjs/queries/QueryResult.js +1 -1
- package/dist/cjs/queries/QueryResult.js.map +1 -1
- package/dist/cjs/validation/ValidationResult.js +12 -1
- package/dist/cjs/validation/ValidationResult.js.map +1 -1
- package/dist/cjs/validation/ValidationResultReason.js +40 -0
- package/dist/cjs/validation/ValidationResultReason.js.map +1 -0
- package/dist/cjs/validation/index.js +2 -0
- package/dist/cjs/validation/index.js.map +1 -1
- package/dist/esm/commands/CommandResult.d.ts +1 -0
- package/dist/esm/commands/CommandResult.d.ts.map +1 -1
- package/dist/esm/commands/CommandResult.js +1 -1
- package/dist/esm/commands/CommandResult.js.map +1 -1
- package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_reasons.d.ts +2 -0
- package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_reasons.d.ts.map +1 -0
- package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_reasons.js +37 -0
- package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_reasons.js.map +1 -0
- package/dist/esm/for_packageManifest/when_declaring_the_fundamentals_range.d.ts +2 -0
- package/dist/esm/for_packageManifest/when_declaring_the_fundamentals_range.d.ts.map +1 -0
- package/dist/esm/for_packageManifest/when_declaring_the_fundamentals_range.js +13 -0
- package/dist/esm/for_packageManifest/when_declaring_the_fundamentals_range.js.map +1 -0
- package/dist/esm/queries/QueryResult.d.ts +1 -0
- package/dist/esm/queries/QueryResult.d.ts.map +1 -1
- package/dist/esm/queries/QueryResult.js +1 -1
- package/dist/esm/queries/QueryResult.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/validation/ValidationResult.d.ts +3 -1
- package/dist/esm/validation/ValidationResult.d.ts.map +1 -1
- package/dist/esm/validation/ValidationResult.js +12 -1
- package/dist/esm/validation/ValidationResult.js.map +1 -1
- package/dist/esm/validation/ValidationResultReason.d.ts +10 -0
- package/dist/esm/validation/ValidationResultReason.d.ts.map +1 -0
- package/dist/esm/validation/ValidationResultReason.js +38 -0
- package/dist/esm/validation/ValidationResultReason.js.map +1 -0
- package/dist/esm/validation/index.d.ts +1 -0
- package/dist/esm/validation/index.d.ts.map +1 -1
- package/dist/esm/validation/index.js +1 -0
- package/dist/esm/validation/index.js.map +1 -1
- package/for_packageManifest/when_declaring_the_fundamentals_range.ts +44 -0
- package/package.json +5 -2
- package/queries/QueryResult.ts +2 -1
- package/validation/ValidationResult.ts +15 -3
- package/validation/ValidationResultReason.ts +54 -0
- package/validation/index.ts +1 -0
|
@@ -42,6 +42,7 @@ type ServerCommandResult = {
|
|
|
42
42
|
message: string;
|
|
43
43
|
members: string[];
|
|
44
44
|
state: object;
|
|
45
|
+
reason?: string;
|
|
45
46
|
}[];
|
|
46
47
|
exceptionMessages: string[];
|
|
47
48
|
exceptionStackTrace: string;
|
|
@@ -147,7 +148,7 @@ export class CommandResult<TResponse = object> implements ICommandResult<TRespon
|
|
|
147
148
|
this.isAuthorized = result.isAuthorized;
|
|
148
149
|
this.isValid = result.isValid;
|
|
149
150
|
this.hasExceptions = result.hasExceptions;
|
|
150
|
-
this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));
|
|
151
|
+
this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state, _.reason));
|
|
151
152
|
this.exceptionMessages = result.exceptionMessages;
|
|
152
153
|
this.exceptionStackTrace = result.exceptionStackTrace;
|
|
153
154
|
this.authorizationFailureReason = result.authorizationFailureReason;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { ValidationResultReason } from '../../validation/ValidationResultReason';
|
|
5
|
+
import { ValidationResultSeverity } from '../../validation/ValidationResultSeverity';
|
|
6
|
+
import { CommandResult } from '../CommandResult';
|
|
7
|
+
|
|
8
|
+
describe('when constructing from a server result with reasons', () => {
|
|
9
|
+
const result = new CommandResult({
|
|
10
|
+
correlationId: '0c0ee8c8-b5a6-4999-b030-6e6a0c931b91',
|
|
11
|
+
isSuccess: false,
|
|
12
|
+
isAuthorized: true,
|
|
13
|
+
isValid: false,
|
|
14
|
+
hasExceptions: false,
|
|
15
|
+
validationResults: [
|
|
16
|
+
{
|
|
17
|
+
severity: ValidationResultSeverity.Error,
|
|
18
|
+
message: 'Concurrency violation for event source abc: Expected sequence number 10, but actual is 15',
|
|
19
|
+
members: [],
|
|
20
|
+
state: {},
|
|
21
|
+
reason: ValidationResultReason.ConcurrencyViolation
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
severity: ValidationResultSeverity.Error,
|
|
25
|
+
message: 'Name is required',
|
|
26
|
+
members: ['name'],
|
|
27
|
+
state: {}
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
exceptionMessages: [],
|
|
31
|
+
exceptionStackTrace: '',
|
|
32
|
+
authorizationFailureReason: '',
|
|
33
|
+
response: null
|
|
34
|
+
}, String, false);
|
|
35
|
+
|
|
36
|
+
it('should carry the reason across the wire', () =>
|
|
37
|
+
result.validationResults[0].reason.should.equal(ValidationResultReason.ConcurrencyViolation));
|
|
38
|
+
|
|
39
|
+
// A server that predates the reason sends nothing, and an authored rule rejection is what that used to mean.
|
|
40
|
+
it('should treat a missing reason as an authored rule', () =>
|
|
41
|
+
result.validationResults[1].reason.should.equal(ValidationResultReason.Rule));
|
|
42
|
+
|
|
43
|
+
it('should let a client separate the two without reading the message', () =>
|
|
44
|
+
result.validationResults
|
|
45
|
+
.filter(_ => _.reason === ValidationResultReason.ConcurrencyViolation)
|
|
46
|
+
.length.should.equal(1));
|
|
47
|
+
});
|
|
@@ -74,7 +74,7 @@ var ValidationResult = require('../validation/ValidationResult.js');
|
|
|
74
74
|
this.isAuthorized = result.isAuthorized;
|
|
75
75
|
this.isValid = result.isValid;
|
|
76
76
|
this.hasExceptions = result.hasExceptions;
|
|
77
|
-
this.validationResults = result.validationResults.map((_)=>new ValidationResult.ValidationResult(_.severity, _.message, _.members, _.state));
|
|
77
|
+
this.validationResults = result.validationResults.map((_)=>new ValidationResult.ValidationResult(_.severity, _.message, _.members, _.state, _.reason));
|
|
78
78
|
this.exceptionMessages = result.exceptionMessages;
|
|
79
79
|
this.exceptionStackTrace = result.exceptionStackTrace;
|
|
80
80
|
this.authorizationFailureReason = result.authorizationFailureReason;
|
|
@@ -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 !== 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":["CommandResult","empty","correlationId","Guid","toString","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","authorizationFailureReason","response","Object","failed","validationFailed","map","_","severity","message","members","state","result","responseInstanceType","isResponseTypeEnumerable","parse","ValidationResult","undefined","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance","onSuccess","callback","onFailed","onException","onUnauthorized","onValidationFailure"],"mappings":";;;;;AAAA;AACA;AAqDA;;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,CAA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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 reason?: string;\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, _.reason));\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":["CommandResult","empty","correlationId","Guid","toString","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","authorizationFailureReason","response","Object","failed","validationFailed","map","_","severity","message","members","state","result","responseInstanceType","isResponseTypeEnumerable","parse","ValidationResult","reason","undefined","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance","onSuccess","callback","onFailed","onException","onUnauthorized","onValidationFailure"],"mappings":";;;;;AAAA;AACA;AAsDA;;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,EAAQ,KAAA,CAAA;IACf,CAAA;AAEA,IAAA,OAAOE,mBAAmB,CAACP,iBAAAA,GAAAA;AACvB,QAAA,OAAO,IAAIT,aAAAA,CAAc;YACrBE,aAAAA,EAAeC,iBAAAA,CAAKF,KAAK,CAACG,QAAQ,EA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AAC9D,QAAA,IAAI,CAAC,IAAI,CAACpC,SAAS,EAAE;AACjBoC,YAAAA,QAAAA,CAAS,IAAI,CAAA;AACjB,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAE,WAAAA,CAAYF,QAAqB,EAA4B;QACzD,IAAI,IAAI,CAACjC,aAAa,EAAE;AACpBiC,YAAAA,QAAAA,CAAS,IAAI,CAAC/B,iBAAiB,EAAE,IAAI,CAACC,mBAAmB,CAAA;AAC7D,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAiC,cAAAA,CAAeH,QAAwB,EAA4B;AAC/D,QAAA,IAAI,CAAC,IAAI,CAACnC,YAAY,EAAE;AACpBmC,YAAAA,QAAAA,EAAAA;AACJ,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAI,mBAAAA,CAAoBJ,QAA6B,EAA4B;AACzE,QAAA,IAAI,CAAC,IAAI,CAAClC,OAAO,EAAE;YACfkC,QAAAA,CAAS,IAAI,CAAChC,iBAAiB,CAAA;AACnC,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AACJ;;;;"}
|
|
@@ -102,7 +102,7 @@ var deserializeQueryModel = require('./deserializeQueryModel.js');
|
|
|
102
102
|
this.isAuthorized = result.isAuthorized;
|
|
103
103
|
this.isValid = result.isValid;
|
|
104
104
|
this.hasExceptions = result.hasExceptions;
|
|
105
|
-
this.validationResults = result.validationResults.map((_)=>new ValidationResult.ValidationResult(_.severity, _.message, _.members, _.state));
|
|
105
|
+
this.validationResults = result.validationResults.map((_)=>new ValidationResult.ValidationResult(_.severity, _.message, _.members, _.state, _.reason));
|
|
106
106
|
this.exceptionMessages = result.exceptionMessages;
|
|
107
107
|
this.exceptionStackTrace = result.exceptionStackTrace;
|
|
108
108
|
this.paging = new PagingInfo.PagingInfo();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryResult.js","sources":["../../../queries/QueryResult.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 { Constructor } from '@cratis/fundamentals';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { IQueryResult } from './IQueryResult';\nimport { PagingInfo } from './PagingInfo';\nimport { ChangeSet } from './ChangeSet';\nimport { deserializeQueryModel, deserializeQueryModels } from './deserializeQueryModel';\n\ntype ServerQueryResult = {\n /* eslint-disable @typescript-eslint/no-explicit-any */\n data: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: ServerValidationResult[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n paging: ServerPagingInfo;\n changeSet?: ServerChangeSet;\n}\n\ntype ServerChangeSet = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n added: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n replaced: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n removed: any[];\n}\n\ntype ServerValidationResult = {\n severity: number;\n message: string;\n members: string[];\n state: object;\n}\n\ntype ServerPagingInfo = {\n page: number;\n size: number; \n totalItems: number;\n totalPages: number;\n}\n\n/**\n * Represents the result from executing a {@link IQueryFor}.\n * @template TDataType The data type.\n */\nexport class QueryResult<TDataType = object> implements IQueryResult<TDataType> {\n\n static empty<TDataType>(defaultValue: TDataType): QueryResult<TDataType> {\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n\n }, Object, false);\n }\n\n /**\n * Creates a {@link QueryResult} representing a query rejected by client-side validation, mirroring\n * {@link CommandResult.validationFailed} so a caller reads a failed query the same way it reads a failed command.\n * @param {ValidationResult[]} validationResults The validation results that caused the failure.\n * @param {object} query The query being rejected, which describes how to shape its own result.\n * @returns {QueryResult<TDataType>} A result that is neither successful nor valid.\n */\n static validationFailed<TDataType>(\n validationResults: ValidationResult[],\n query: { readonly defaultValue: TDataType; readonly modelType: Constructor; readonly enumerable: boolean }): QueryResult<TDataType> {\n const { defaultValue, modelType, enumerable } = query;\n return new QueryResult({\n data: defaultValue as object,\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 paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, modelType, enumerable) as QueryResult<TDataType>;\n }\n\n static unauthorized<TDataType>(): QueryResult<TDataType> {\n return new QueryResult({\n data: null as unknown as object,\n isSuccess: false,\n isAuthorized: false,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n }\n\n static noSuccess: QueryResult = new QueryResult({\n data: {},\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n\n /**\n * Creates an instance of query result.\n * @param {*} result The raw result from the backend.\n * @param {Constructor} instanceType The type of instance to deserialize.\n * @param {boolean} enumerable Whether or not the result is supposed be an enumerable or not.\n */\n constructor(result: ServerQueryResult, instanceType: Constructor, enumerable: boolean) {\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.paging = new PagingInfo();\n this.paging.page = result.paging.page;\n this.paging.size = result.paging.size;\n this.paging.totalItems = result.paging.totalItems;\n this.paging.totalPages = result.paging.totalPages;\n\n if (result.data) {\n this.data = (enumerable\n ? deserializeQueryModels(instanceType, result.data)\n : deserializeQueryModel(instanceType, result.data)) as TDataType;\n } else {\n this.data = (enumerable ? [] : null) as TDataType;\n }\n\n if (enumerable && result.changeSet) {\n this.changeSet = {\n added: deserializeQueryModels(instanceType, result.changeSet.added ?? []),\n replaced: deserializeQueryModels(instanceType, result.changeSet.replaced ?? []),\n removed: deserializeQueryModels(instanceType, result.changeSet.removed ?? []),\n } as ChangeSet<unknown>;\n }\n }\n\n /** @inheritdoc */\n readonly data: TDataType;\n\n /** @inheritdoc */\n readonly paging: PagingInfo;\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 /**\n * Gets the optional change set describing what changed since the previous update.\n * Set by the server when the delta transfer mode is active.\n * When present, clients can apply the delta to their local state rather than replacing\n * the full dataset.\n */\n readonly changeSet?: ChangeSet<unknown>;\n\n /**\n * Gets whether or not the query has data.\n */\n get hasData(): boolean {\n if (this.data) {\n if (Array.isArray(this.data)) {\n return this.data.length > 0;\n }\n return true;\n }\n return false;\n }\n}\n"],"names":["QueryResult","empty","defaultValue","data","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","paging","totalItems","totalPages","page","size","Object","validationFailed","query","modelType","enumerable","map","_","severity","message","members","state","unauthorized","noSuccess","result","instanceType","ValidationResult","PagingInfo","deserializeQueryModels","deserializeQueryModel","changeSet","added","replaced","removed","hasData","Array","isArray","length"],"mappings":";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AA,IAAcS,MAAAA,CAAOM,SAAS,EAAE;YAChC,IAAI,CAACA,SAAS,GAAG;AACbC,gBAAAA,KAAAA,EAAOH,6CAAuBH,YAAAA,EAAcD,MAAAA,CAAOM,SAAS,CAACC,KAAK,IAAI,EAAE,CAAA;AACxEC,gBAAAA,QAAAA,EAAUJ,6CAAuBH,YAAAA,EAAcD,MAAAA,CAAOM,SAAS,CAACE,QAAQ,IAAI,EAAE,CAAA;AAC9EC,gBAAAA,OAAAA,EAASL,6CAAuBH,YAAAA,EAAcD,MAAAA,CAAOM,SAAS,CAACG,OAAO,IAAI,EAAE;AAChF,aAAA;AACJ,QAAA;AACJ,IAAA;uBAGA,IAASnC;uBAGT,MAASQ;uBAGT,SAASP;uBAGT,YAASC;uBAGT,OAASC;uBAGT,aAASC;uBAGT,iBAASC;uBAGT,iBAASC;uBAGT,mBAASC;AAET;;;;;AAKC,QACD,SAASyB;AAET;;AAEC,QACD,IAAII,OAAAA,GAAmB;QACnB,IAAI,IAAI,CAACpC,IAAI,EAAE;AACX,YAAA,IAAIqC,MAAMC,OAAO,CAAC,IAAI,CAACtC,IAAI,CAAA,EAAG;AAC1B,gBAAA,OAAO,IAAI,CAACA,IAAI,CAACuC,MAAM,GAAG,CAAA;AAC9B,YAAA;YACA,OAAO,IAAA;AACX,QAAA;QACA,OAAO,KAAA;AACX,IAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"QueryResult.js","sources":["../../../queries/QueryResult.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 { Constructor } from '@cratis/fundamentals';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { IQueryResult } from './IQueryResult';\nimport { PagingInfo } from './PagingInfo';\nimport { ChangeSet } from './ChangeSet';\nimport { deserializeQueryModel, deserializeQueryModels } from './deserializeQueryModel';\n\ntype ServerQueryResult = {\n /* eslint-disable @typescript-eslint/no-explicit-any */\n data: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: ServerValidationResult[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n paging: ServerPagingInfo;\n changeSet?: ServerChangeSet;\n}\n\ntype ServerChangeSet = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n added: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n replaced: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n removed: any[];\n}\n\ntype ServerValidationResult = {\n severity: number;\n message: string;\n members: string[];\n state: object;\n reason?: string;\n}\n\ntype ServerPagingInfo = {\n page: number;\n size: number; \n totalItems: number;\n totalPages: number;\n}\n\n/**\n * Represents the result from executing a {@link IQueryFor}.\n * @template TDataType The data type.\n */\nexport class QueryResult<TDataType = object> implements IQueryResult<TDataType> {\n\n static empty<TDataType>(defaultValue: TDataType): QueryResult<TDataType> {\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n\n }, Object, false);\n }\n\n /**\n * Creates a {@link QueryResult} representing a query rejected by client-side validation, mirroring\n * {@link CommandResult.validationFailed} so a caller reads a failed query the same way it reads a failed command.\n * @param {ValidationResult[]} validationResults The validation results that caused the failure.\n * @param {object} query The query being rejected, which describes how to shape its own result.\n * @returns {QueryResult<TDataType>} A result that is neither successful nor valid.\n */\n static validationFailed<TDataType>(\n validationResults: ValidationResult[],\n query: { readonly defaultValue: TDataType; readonly modelType: Constructor; readonly enumerable: boolean }): QueryResult<TDataType> {\n const { defaultValue, modelType, enumerable } = query;\n return new QueryResult({\n data: defaultValue as object,\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 paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, modelType, enumerable) as QueryResult<TDataType>;\n }\n\n static unauthorized<TDataType>(): QueryResult<TDataType> {\n return new QueryResult({\n data: null as unknown as object,\n isSuccess: false,\n isAuthorized: false,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n }\n\n static noSuccess: QueryResult = new QueryResult({\n data: {},\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n\n /**\n * Creates an instance of query result.\n * @param {*} result The raw result from the backend.\n * @param {Constructor} instanceType The type of instance to deserialize.\n * @param {boolean} enumerable Whether or not the result is supposed be an enumerable or not.\n */\n constructor(result: ServerQueryResult, instanceType: Constructor, enumerable: boolean) {\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));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.paging = new PagingInfo();\n this.paging.page = result.paging.page;\n this.paging.size = result.paging.size;\n this.paging.totalItems = result.paging.totalItems;\n this.paging.totalPages = result.paging.totalPages;\n\n if (result.data) {\n this.data = (enumerable\n ? deserializeQueryModels(instanceType, result.data)\n : deserializeQueryModel(instanceType, result.data)) as TDataType;\n } else {\n this.data = (enumerable ? [] : null) as TDataType;\n }\n\n if (enumerable && result.changeSet) {\n this.changeSet = {\n added: deserializeQueryModels(instanceType, result.changeSet.added ?? []),\n replaced: deserializeQueryModels(instanceType, result.changeSet.replaced ?? []),\n removed: deserializeQueryModels(instanceType, result.changeSet.removed ?? []),\n } as ChangeSet<unknown>;\n }\n }\n\n /** @inheritdoc */\n readonly data: TDataType;\n\n /** @inheritdoc */\n readonly paging: PagingInfo;\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 /**\n * Gets the optional change set describing what changed since the previous update.\n * Set by the server when the delta transfer mode is active.\n * When present, clients can apply the delta to their local state rather than replacing\n * the full dataset.\n */\n readonly changeSet?: ChangeSet<unknown>;\n\n /**\n * Gets whether or not the query has data.\n */\n get hasData(): boolean {\n if (this.data) {\n if (Array.isArray(this.data)) {\n return this.data.length > 0;\n }\n return true;\n }\n return false;\n }\n}\n"],"names":["QueryResult","empty","defaultValue","data","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","paging","totalItems","totalPages","page","size","Object","validationFailed","query","modelType","enumerable","map","_","severity","message","members","state","unauthorized","noSuccess","result","instanceType","ValidationResult","reason","PagingInfo","deserializeQueryModels","deserializeQueryModel","changeSet","added","replaced","removed","hasData","Array","isArray","length"],"mappings":";;;;;;AAAA;AACA;AAgDA;;;AAGC,IACM,MAAMA,WAAAA,CAAAA;IAET,OAAOC,KAAAA,CAAiBC,YAAuB,EAA0B;AACrE,QAAA,OAAO,IAAIF,WAAAA,CAAY;YACnBG,IAAAA,EAAMD,YAAAA;YACNE,SAAAA,EAAW,IAAA;YACXC,YAAAA,EAAc,IAAA;YACdC,OAAAA,EAAS,IAAA;YACTC,aAAAA,EAAe,KAAA;AACfC,YAAAA,iBAAAA,EAAmB,EAAE;AACr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;AAC9EC,gBAAAA,OAAAA,EAASL,6CAAuBJ,YAAAA,EAAcD,MAAAA,CAAOO,SAAS,CAACG,OAAO,IAAI,EAAE;AAChF,aAAA;AACJ,QAAA;AACJ,IAAA;uBAGA,IAASpC;uBAGT,MAASQ;uBAGT,SAASP;uBAGT,YAASC;uBAGT,OAASC;uBAGT,aAASC;uBAGT,iBAASC;uBAGT,iBAASC;uBAGT,mBAASC;AAET;;;;;AAKC,QACD,SAAS0B;AAET;;AAEC,QACD,IAAII,OAAAA,GAAmB;QACnB,IAAI,IAAI,CAACrC,IAAI,EAAE;AACX,YAAA,IAAIsC,MAAMC,OAAO,CAAC,IAAI,CAACvC,IAAI,CAAA,EAAG;AAC1B,gBAAA,OAAO,IAAI,CAACA,IAAI,CAACwC,MAAM,GAAG,CAAA;AAC9B,YAAA;YACA,OAAO,IAAA;AACX,QAAA;QACA,OAAO,KAAA;AACX,IAAA;AACJ;;;;"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var ValidationResultReason = require('./ValidationResultReason.js');
|
|
4
|
+
|
|
3
5
|
// Copyright (c) Cratis. All rights reserved.
|
|
4
6
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
7
|
/* eslint-disable @typescript-eslint/no-explicit-any */ /**
|
|
@@ -9,11 +11,20 @@
|
|
|
9
11
|
message;
|
|
10
12
|
members;
|
|
11
13
|
state;
|
|
12
|
-
|
|
14
|
+
reason;
|
|
15
|
+
/**
|
|
16
|
+
* Initializes a new instance of the {@link ValidationResult} class.
|
|
17
|
+
* @param severity The severity of the result.
|
|
18
|
+
* @param message The message. A developer diagnostic when {@link reason} is anything but `rule`.
|
|
19
|
+
* @param members The members the result is attributed to.
|
|
20
|
+
* @param state State associated with the result - the rule author's, carried straight through.
|
|
21
|
+
* @param reason What composed the result. Defaults to `rule`, meaning an authored rule rejected the input.
|
|
22
|
+
*/ constructor(severity, message, members, state, reason = ValidationResultReason.ValidationResultReason.Rule){
|
|
13
23
|
this.severity = severity;
|
|
14
24
|
this.message = message;
|
|
15
25
|
this.members = members;
|
|
16
26
|
this.state = state;
|
|
27
|
+
this.reason = reason;
|
|
17
28
|
}
|
|
18
29
|
}
|
|
19
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationResult.js","sources":["../../../validation/ValidationResult.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 { ValidationResultSeverity } from './ValidationResultSeverity';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Represents a validation error with a message for one or more members.\n */\nexport class ValidationResult {\n constructor(readonly severity: ValidationResultSeverity
|
|
1
|
+
{"version":3,"file":"ValidationResult.js","sources":["../../../validation/ValidationResult.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 { ValidationResultReason } from './ValidationResultReason';\nimport { ValidationResultSeverity } from './ValidationResultSeverity';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Represents a validation error with a message for one or more members.\n */\nexport class ValidationResult {\n /**\n * Initializes a new instance of the {@link ValidationResult} class.\n * @param severity The severity of the result.\n * @param message The message. A developer diagnostic when {@link reason} is anything but `rule`.\n * @param members The members the result is attributed to.\n * @param state State associated with the result - the rule author's, carried straight through.\n * @param reason What composed the result. Defaults to `rule`, meaning an authored rule rejected the input.\n */\n constructor(\n readonly severity: ValidationResultSeverity,\n readonly message: string,\n readonly members: string[],\n readonly state: any,\n readonly reason: ValidationResultReason = ValidationResultReason.Rule) {\n }\n}\n"],"names":["ValidationResult","message","members","reason","ValidationResultReason","Rule","severity","state"],"mappings":";;;;AAAA;AACA;AAKA;;AAIC,IACM,MAAMA,gBAAAA,CAAAA;;;;;;AACT;;;;;;;AAOC,QACD,YACI,QAA2C,EAClCC,OAAe,EACfC,OAAiB,EAC1B,KAAmB,EACnB,MAASC,GAAiCC,6CAAAA,CAAuBC,IAAI,CAAE;aAJ9DC,QAAAA,GAAAA,QAAAA;aACAL,OAAAA,GAAAA,OAAAA;aACAC,OAAAA,GAAAA,OAAAA;aACAK,KAAAA,GAAAA,KAAAA;aACAJ,MAAAA,GAAAA,MAAAA;AACb,IAAA;AACJ;;;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
4
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
|
+
/**
|
|
6
|
+
* Holds the well-known values for what composed a validation result - the machine-readable counterpart to its
|
|
7
|
+
* message.
|
|
8
|
+
* @remarks
|
|
9
|
+
* A rejection's message is a developer diagnostic, not copy to show a user. Branch on this instead of matching the
|
|
10
|
+
* message, and render your own wording for anything the framework composed.
|
|
11
|
+
*
|
|
12
|
+
* This is deliberately not an enum. Rejections are composed in Arc, in Chronicle and in application code, so the set
|
|
13
|
+
* is open: treat an unrecognized value the way you would treat {@link ValidationResultReason.Rule} rather than as an
|
|
14
|
+
* error.
|
|
15
|
+
*/ const ValidationResultReason = {
|
|
16
|
+
/**
|
|
17
|
+
* A rule authored by the application rejected the input. The message is the author's, and is meant to be shown.
|
|
18
|
+
*/ Rule: 'rule',
|
|
19
|
+
/**
|
|
20
|
+
* The append was rejected because the event source moved on since it was read. Retryable - re-read and resubmit.
|
|
21
|
+
*/ ConcurrencyViolation: 'concurrencyViolation',
|
|
22
|
+
/**
|
|
23
|
+
* A constraint on the event store rejected the append.
|
|
24
|
+
*/ ConstraintViolation: 'constraintViolation',
|
|
25
|
+
/**
|
|
26
|
+
* A validator threw, and the framework substituted this result for the one the validator would have produced.
|
|
27
|
+
* Nothing the author wrote survives, so the message is not theirs to show.
|
|
28
|
+
*/ ValidatorFailed: 'validatorFailed',
|
|
29
|
+
/**
|
|
30
|
+
* Something the command needed in order to be evaluated was not available, most often the read model a
|
|
31
|
+
* validator depends on. Raised before any rule ran, so nothing about the command's own rules was decided.
|
|
32
|
+
*/ DependencyUnavailable: 'dependencyUnavailable',
|
|
33
|
+
/**
|
|
34
|
+
* The request itself could not be read - a malformed body, or a value that could not be bound. No rule was
|
|
35
|
+
* reached.
|
|
36
|
+
*/ MalformedRequest: 'malformedRequest'
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.ValidationResultReason = ValidationResultReason;
|
|
40
|
+
//# sourceMappingURL=ValidationResultReason.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationResultReason.js","sources":["../../../validation/ValidationResultReason.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\n/**\n * Holds the well-known values for what composed a validation result - the machine-readable counterpart to its\n * message.\n * @remarks\n * A rejection's message is a developer diagnostic, not copy to show a user. Branch on this instead of matching the\n * message, and render your own wording for anything the framework composed.\n *\n * This is deliberately not an enum. Rejections are composed in Arc, in Chronicle and in application code, so the set\n * is open: treat an unrecognized value the way you would treat {@link ValidationResultReason.Rule} rather than as an\n * error.\n */\nexport const ValidationResultReason = {\n\n /**\n * A rule authored by the application rejected the input. The message is the author's, and is meant to be shown.\n */\n Rule: 'rule',\n\n /**\n * The append was rejected because the event source moved on since it was read. Retryable - re-read and resubmit.\n */\n ConcurrencyViolation: 'concurrencyViolation',\n\n /**\n * A constraint on the event store rejected the append.\n */\n ConstraintViolation: 'constraintViolation',\n\n /**\n * A validator threw, and the framework substituted this result for the one the validator would have produced.\n * Nothing the author wrote survives, so the message is not theirs to show.\n */\n ValidatorFailed: 'validatorFailed',\n\n /**\n * Something the command needed in order to be evaluated was not available, most often the read model a\n * validator depends on. Raised before any rule ran, so nothing about the command's own rules was decided.\n */\n DependencyUnavailable: 'dependencyUnavailable',\n\n /**\n * The request itself could not be read - a malformed body, or a value that could not be bound. No rule was\n * reached.\n */\n MalformedRequest: 'malformedRequest'\n} as const;\n\n/**\n * The type of a validation result reason. Widened to string because the set is open.\n */\nexport type ValidationResultReason = string;\n"],"names":["ValidationResultReason","Rule","ConcurrencyViolation","ConstraintViolation","ValidatorFailed","DependencyUnavailable","MalformedRequest"],"mappings":";;AAAA;AACA;AAEA;;;;;;;;;;UAWaA,sBAAAA,GAAyB;AAElC;;AAEC,QACDC,IAAAA,EAAM,MAAA;AAEN;;AAEC,QACDC,oBAAAA,EAAsB,sBAAA;AAEtB;;AAEC,QACDC,mBAAAA,EAAqB,qBAAA;AAErB;;;AAGC,QACDC,eAAAA,EAAiB,iBAAA;AAEjB;;;AAGC,QACDC,qBAAAA,EAAuB,uBAAA;AAEvB;;;AAGC,QACDC,gBAAAA,EAAkB;AACtB;;;;"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var Validator = require('./Validator.js');
|
|
4
4
|
var ValidationResult = require('./ValidationResult.js');
|
|
5
|
+
var ValidationResultReason = require('./ValidationResultReason.js');
|
|
5
6
|
var ValidationResultSeverity = require('./ValidationResultSeverity.js');
|
|
6
7
|
var PropertyValidator = require('./PropertyValidator.js');
|
|
7
8
|
var PropertyRule = require('./PropertyRule.js');
|
|
@@ -18,6 +19,7 @@ var ComparisonRules = require('./rules/ComparisonRules.js');
|
|
|
18
19
|
|
|
19
20
|
exports.Validator = Validator.Validator;
|
|
20
21
|
exports.ValidationResult = ValidationResult.ValidationResult;
|
|
22
|
+
exports.ValidationResultReason = ValidationResultReason.ValidationResultReason;
|
|
21
23
|
exports.ValidationResultSeverity = ValidationResultSeverity.ValidationResultSeverity;
|
|
22
24
|
exports.PropertyValidator = PropertyValidator.PropertyValidator;
|
|
23
25
|
exports.PropertyRule = PropertyRule.PropertyRule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../validation/index.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\nexport * from './Validator';\nexport * from './ValidationResult';\nexport * from './ValidationResultSeverity';\nexport * from './IValidationRule';\nexport * from './PropertyValidator';\nexport * from './PropertyRule';\nexport * from './RuleBuilder';\nexport * from './RuleBuilderExtensions';\nexport * from './rules/NotEmptyRule';\nexport * from './rules/LengthRules';\nexport * from './rules/EmailRule';\nexport * from './rules/RegexRule';\nexport * from './rules/ComparisonRules';\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../validation/index.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\nexport * from './Validator';\nexport * from './ValidationResult';\nexport * from './ValidationResultReason';\nexport * from './ValidationResultSeverity';\nexport * from './IValidationRule';\nexport * from './PropertyValidator';\nexport * from './PropertyRule';\nexport * from './RuleBuilder';\nexport * from './RuleBuilderExtensions';\nexport * from './rules/NotEmptyRule';\nexport * from './rules/LengthRules';\nexport * from './rules/EmailRule';\nexport * from './rules/RegexRule';\nexport * from './rules/ComparisonRules';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -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,EA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,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;IAQ9B,YAAY,MAAM,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,WAAW,YAAS,EAAE,wBAAwB,EAAE,OAAO,EAyBrH;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;IAOD,mBAAmB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,aAAa,CAAC,SAAS,CAAC,CAK3E;CACJ"}
|
|
@@ -72,7 +72,7 @@ import { ValidationResult } from '../validation/ValidationResult.js';
|
|
|
72
72
|
this.isAuthorized = result.isAuthorized;
|
|
73
73
|
this.isValid = result.isValid;
|
|
74
74
|
this.hasExceptions = result.hasExceptions;
|
|
75
|
-
this.validationResults = result.validationResults.map((_)=>new ValidationResult(_.severity, _.message, _.members, _.state));
|
|
75
|
+
this.validationResults = result.validationResults.map((_)=>new ValidationResult(_.severity, _.message, _.members, _.state, _.reason));
|
|
76
76
|
this.exceptionMessages = result.exceptionMessages;
|
|
77
77
|
this.exceptionStackTrace = result.exceptionStackTrace;
|
|
78
78
|
this.authorizationFailureReason = result.authorizationFailureReason;
|
|
@@ -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 !== 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":["CommandResult","empty","correlationId","Guid","toString","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","authorizationFailureReason","response","Object","failed","validationFailed","map","_","severity","message","members","state","result","responseInstanceType","isResponseTypeEnumerable","parse","ValidationResult","undefined","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance","onSuccess","callback","onFailed","onException","onUnauthorized","onValidationFailure"],"mappings":";;;AAAA;AACA;AAqDA;;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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I;AACf,IAAA;AAEA;;;;QAKAE,WAAAA,CAAYF,QAAqB,EAA4B;QACzD,IAAI,IAAI,CAAChC,aAAa,EAAE;AACpBgC,YAAAA,QAAAA,CAAS,IAAI,CAAC9B,iBAAiB,EAAE,IAAI,CAACC,mBAAmB,CAAA;AAC7D,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAgC,cAAAA,CAAeH,QAAwB,EAA4B;AAC/D,QAAA,IAAI,CAAC,IAAI,CAAClC,YAAY,EAAE;AACpBkC,YAAAA,QAAAA,EAAAA;AACJ,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;;;QAKAI,mBAAAA,CAAoBJ,QAA6B,EAA4B;AACzE,QAAA,IAAI,CAAC,IAAI,CAACjC,OAAO,EAAE;YACfiC,QAAAA,CAAS,IAAI,CAAC/B,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';\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 reason?: string;\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, _.reason));\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":["CommandResult","empty","correlationId","Guid","toString","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","authorizationFailureReason","response","Object","failed","validationFailed","map","_","severity","message","members","state","result","responseInstanceType","isResponseTypeEnumerable","parse","ValidationResult","reason","undefined","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance","onSuccess","callback","onFailed","onException","onUnauthorized","onValidationFailure"],"mappings":";;;AAAA;AACA;AAsDA;;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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AE;YACfkC,QAAAA,CAAS,IAAI,CAAChC,iBAAiB,CAAA;AACnC,QAAA;AACA,QAAA,OAAO,IAAI;AACf,IAAA;AACJ;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_constructing_from_a_server_result_with_reasons.d.ts","sourceRoot":"","sources":["../../../../commands/for_CommandResult/when_constructing_from_a_server_result_with_reasons.ts"],"names":[],"mappings":""}
|
package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_reasons.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ValidationResultReason } from '../../validation/ValidationResultReason';
|
|
2
|
+
import { ValidationResultSeverity } from '../../validation/ValidationResultSeverity';
|
|
3
|
+
import { CommandResult } from '../CommandResult';
|
|
4
|
+
describe('when constructing from a server result with reasons', () => {
|
|
5
|
+
const result = new CommandResult({
|
|
6
|
+
correlationId: '0c0ee8c8-b5a6-4999-b030-6e6a0c931b91',
|
|
7
|
+
isSuccess: false,
|
|
8
|
+
isAuthorized: true,
|
|
9
|
+
isValid: false,
|
|
10
|
+
hasExceptions: false,
|
|
11
|
+
validationResults: [
|
|
12
|
+
{
|
|
13
|
+
severity: ValidationResultSeverity.Error,
|
|
14
|
+
message: 'Concurrency violation for event source abc: Expected sequence number 10, but actual is 15',
|
|
15
|
+
members: [],
|
|
16
|
+
state: {},
|
|
17
|
+
reason: ValidationResultReason.ConcurrencyViolation
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
severity: ValidationResultSeverity.Error,
|
|
21
|
+
message: 'Name is required',
|
|
22
|
+
members: ['name'],
|
|
23
|
+
state: {}
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
exceptionMessages: [],
|
|
27
|
+
exceptionStackTrace: '',
|
|
28
|
+
authorizationFailureReason: '',
|
|
29
|
+
response: null
|
|
30
|
+
}, String, false);
|
|
31
|
+
it('should carry the reason across the wire', () => result.validationResults[0].reason.should.equal(ValidationResultReason.ConcurrencyViolation));
|
|
32
|
+
it('should treat a missing reason as an authored rule', () => result.validationResults[1].reason.should.equal(ValidationResultReason.Rule));
|
|
33
|
+
it('should let a client separate the two without reading the message', () => result.validationResults
|
|
34
|
+
.filter(_ => _.reason === ValidationResultReason.ConcurrencyViolation)
|
|
35
|
+
.length.should.equal(1));
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=when_constructing_from_a_server_result_with_reasons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_constructing_from_a_server_result_with_reasons.js","sourceRoot":"","sources":["../../../../commands/for_CommandResult/when_constructing_from_a_server_result_with_reasons.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,QAAQ,CAAC,qDAAqD,EAAE,GAAG,EAAE;IACjE,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC;QAC7B,aAAa,EAAE,sCAAsC;QACrD,SAAS,EAAE,KAAK;QAChB,YAAY,EAAE,IAAI;QAClB,OAAO,EAAE,KAAK;QACd,aAAa,EAAE,KAAK;QACpB,iBAAiB,EAAE;YACf;gBACI,QAAQ,EAAE,wBAAwB,CAAC,KAAK;gBACxC,OAAO,EAAE,2FAA2F;gBACpG,OAAO,EAAE,EAAE;gBACX,KAAK,EAAE,EAAE;gBACT,MAAM,EAAE,sBAAsB,CAAC,oBAAoB;aACtD;YACD;gBACI,QAAQ,EAAE,wBAAwB,CAAC,KAAK;gBACxC,OAAO,EAAE,kBAAkB;gBAC3B,OAAO,EAAE,CAAC,MAAM,CAAC;gBACjB,KAAK,EAAE,EAAE;aACZ;SACJ;QACD,iBAAiB,EAAE,EAAE;QACrB,mBAAmB,EAAE,EAAE;QACvB,0BAA0B,EAAE,EAAE;QAC9B,QAAQ,EAAE,IAAI;KACjB,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAElB,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE,CAC/C,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAGlG,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE,CACzD,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;IAElF,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE,CACxE,MAAM,CAAC,iBAAiB;SACnB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,sBAAsB,CAAC,oBAAoB,CAAC;SACrE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_declaring_the_fundamentals_range.d.ts","sourceRoot":"","sources":["../../../for_packageManifest/when_declaring_the_fundamentals_range.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
describe('when declaring the fundamentals range', () => {
|
|
5
|
+
const manifest = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf-8'));
|
|
6
|
+
const dependency = manifest.dependencies?.['@cratis/fundamentals'];
|
|
7
|
+
const pinned = manifest.devDependencies?.['@cratis/fundamentals'];
|
|
8
|
+
it('should declare fundamentals as an ordinary dependency', () => dependency.should.not.be.undefined);
|
|
9
|
+
it('should pin one concrete version to build against', () => pinned.should.match(/^\d+\.\d+\.\d+$/));
|
|
10
|
+
it('should admit no version below the one it builds against', () => dependency.should.equal(`^${pinned}`));
|
|
11
|
+
it('should not require the consumer to declare it', () => (manifest.peerDependencies?.['@cratis/fundamentals'] === undefined).should.be.true);
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=when_declaring_the_fundamentals_range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_declaring_the_fundamentals_range.js","sourceRoot":"","sources":["../../../for_packageManifest/when_declaring_the_fundamentals_range.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAUzC,QAAQ,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CACvB,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAIzF,CAAC;IAEN,MAAM,UAAU,GAAG,QAAQ,CAAC,YAAY,EAAE,CAAC,sBAAsB,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,QAAQ,CAAC,eAAe,EAAE,CAAC,sBAAsB,CAAC,CAAC;IAElE,EAAE,CAAC,uDAAuD,EAAE,GAAG,EAAE,CAAC,UAAW,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;IAEvG,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE,CAAC,MAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAEtG,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE,CAAC,UAAW,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,EAAE,CAAC,CA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Model } from './deserializeQuer
|
|
|
100
100
|
this.isAuthorized = result.isAuthorized;
|
|
101
101
|
this.isValid = result.isValid;
|
|
102
102
|
this.hasExceptions = result.hasExceptions;
|
|
103
|
-
this.validationResults = result.validationResults.map((_)=>new ValidationResult(_.severity, _.message, _.members, _.state));
|
|
103
|
+
this.validationResults = result.validationResults.map((_)=>new ValidationResult(_.severity, _.message, _.members, _.state, _.reason));
|
|
104
104
|
this.exceptionMessages = result.exceptionMessages;
|
|
105
105
|
this.exceptionStackTrace = result.exceptionStackTrace;
|
|
106
106
|
this.paging = new PagingInfo();
|