@cratis/arc 20.69.2 → 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
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { ValidationResultReason } from './ValidationResultReason';
|
|
1
2
|
import { ValidationResultSeverity } from './ValidationResultSeverity';
|
|
2
3
|
export declare class ValidationResult {
|
|
3
4
|
readonly severity: ValidationResultSeverity;
|
|
4
5
|
readonly message: string;
|
|
5
6
|
readonly members: string[];
|
|
6
7
|
readonly state: any;
|
|
7
|
-
|
|
8
|
+
readonly reason: ValidationResultReason;
|
|
9
|
+
constructor(severity: ValidationResultSeverity, message: string, members: string[], state: any, reason?: ValidationResultReason);
|
|
8
10
|
}
|
|
9
11
|
//# sourceMappingURL=ValidationResult.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationResult.d.ts","sourceRoot":"","sources":["../../../validation/ValidationResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAOtE,qBAAa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"ValidationResult.d.ts","sourceRoot":"","sources":["../../../validation/ValidationResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAOtE,qBAAa,gBAAgB;IAUrB,QAAQ,CAAC,QAAQ,EAAE,wBAAwB;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE;IAC1B,QAAQ,CAAC,KAAK,EAAE,GAAG;IACnB,QAAQ,CAAC,MAAM,EAAE,sBAAsB;IAL3C,YACa,QAAQ,EAAE,wBAAwB,EAClC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,GAAG,EACV,MAAM,GAAE,sBAAoD,EACxE;CACJ"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ValidationResultReason } from './ValidationResultReason.js';
|
|
2
|
+
|
|
1
3
|
// Copyright (c) Cratis. All rights reserved.
|
|
2
4
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
5
|
/* eslint-disable @typescript-eslint/no-explicit-any */ /**
|
|
@@ -7,11 +9,20 @@
|
|
|
7
9
|
message;
|
|
8
10
|
members;
|
|
9
11
|
state;
|
|
10
|
-
|
|
12
|
+
reason;
|
|
13
|
+
/**
|
|
14
|
+
* Initializes a new instance of the {@link ValidationResult} class.
|
|
15
|
+
* @param severity The severity of the result.
|
|
16
|
+
* @param message The message. A developer diagnostic when {@link reason} is anything but `rule`.
|
|
17
|
+
* @param members The members the result is attributed to.
|
|
18
|
+
* @param state State associated with the result - the rule author's, carried straight through.
|
|
19
|
+
* @param reason What composed the result. Defaults to `rule`, meaning an authored rule rejected the input.
|
|
20
|
+
*/ constructor(severity, message, members, state, reason = ValidationResultReason.Rule){
|
|
11
21
|
this.severity = severity;
|
|
12
22
|
this.message = message;
|
|
13
23
|
this.members = members;
|
|
14
24
|
this.state = state;
|
|
25
|
+
this.reason = reason;
|
|
15
26
|
}
|
|
16
27
|
}
|
|
17
28
|
|
|
@@ -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,sBAAAA,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,10 @@
|
|
|
1
|
+
export declare const ValidationResultReason: {
|
|
2
|
+
readonly Rule: 'rule';
|
|
3
|
+
readonly ConcurrencyViolation: 'concurrencyViolation';
|
|
4
|
+
readonly ConstraintViolation: 'constraintViolation';
|
|
5
|
+
readonly ValidatorFailed: 'validatorFailed';
|
|
6
|
+
readonly DependencyUnavailable: 'dependencyUnavailable';
|
|
7
|
+
readonly MalformedRequest: 'malformedRequest';
|
|
8
|
+
};
|
|
9
|
+
export type ValidationResultReason = string;
|
|
10
|
+
//# sourceMappingURL=ValidationResultReason.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationResultReason.d.ts","sourceRoot":"","sources":["../../../validation/ValidationResultReason.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,sBAAsB;aAK/B,IAAI,EAAE,MAAM;aAKZ,oBAAoB,EAAE,sBAAsB;aAK5C,mBAAmB,EAAE,qBAAqB;aAM1C,eAAe,EAAE,iBAAiB;aAMlC,qBAAqB,EAAE,uBAAuB;aAM9C,gBAAgB,EAAE,kBAAkB;CAC9B,CAAC;AAKX,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
* Holds the well-known values for what composed a validation result - the machine-readable counterpart to its
|
|
5
|
+
* message.
|
|
6
|
+
* @remarks
|
|
7
|
+
* A rejection's message is a developer diagnostic, not copy to show a user. Branch on this instead of matching the
|
|
8
|
+
* message, and render your own wording for anything the framework composed.
|
|
9
|
+
*
|
|
10
|
+
* This is deliberately not an enum. Rejections are composed in Arc, in Chronicle and in application code, so the set
|
|
11
|
+
* is open: treat an unrecognized value the way you would treat {@link ValidationResultReason.Rule} rather than as an
|
|
12
|
+
* error.
|
|
13
|
+
*/ const ValidationResultReason = {
|
|
14
|
+
/**
|
|
15
|
+
* A rule authored by the application rejected the input. The message is the author's, and is meant to be shown.
|
|
16
|
+
*/ Rule: 'rule',
|
|
17
|
+
/**
|
|
18
|
+
* The append was rejected because the event source moved on since it was read. Retryable - re-read and resubmit.
|
|
19
|
+
*/ ConcurrencyViolation: 'concurrencyViolation',
|
|
20
|
+
/**
|
|
21
|
+
* A constraint on the event store rejected the append.
|
|
22
|
+
*/ ConstraintViolation: 'constraintViolation',
|
|
23
|
+
/**
|
|
24
|
+
* A validator threw, and the framework substituted this result for the one the validator would have produced.
|
|
25
|
+
* Nothing the author wrote survives, so the message is not theirs to show.
|
|
26
|
+
*/ ValidatorFailed: 'validatorFailed',
|
|
27
|
+
/**
|
|
28
|
+
* Something the command needed in order to be evaluated was not available, most often the read model a
|
|
29
|
+
* validator depends on. Raised before any rule ran, so nothing about the command's own rules was decided.
|
|
30
|
+
*/ DependencyUnavailable: 'dependencyUnavailable',
|
|
31
|
+
/**
|
|
32
|
+
* The request itself could not be read - a malformed body, or a value that could not be bound. No rule was
|
|
33
|
+
* reached.
|
|
34
|
+
*/ MalformedRequest: 'malformedRequest'
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { ValidationResultReason };
|
|
38
|
+
//# 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;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../validation/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../validation/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Validator } from './Validator.js';
|
|
2
2
|
export { ValidationResult } from './ValidationResult.js';
|
|
3
|
+
export { ValidationResultReason } from './ValidationResultReason.js';
|
|
3
4
|
export { ValidationResultSeverity } from './ValidationResultSeverity.js';
|
|
4
5
|
export { PropertyValidator } from './PropertyValidator.js';
|
|
5
6
|
export { PropertyRule } from './PropertyRule.js';
|
|
@@ -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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { readFileSync } from 'node:fs';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The range's lower bound is a compatibility claim; the exact devDependency pin is the only version this package is
|
|
10
|
+
* ever compiled and tested against. When they disagree the range claims support for versions nothing verifies, and
|
|
11
|
+
* nothing fails until a consumer resolves one of them.
|
|
12
|
+
*
|
|
13
|
+
* That is what happened once already: a `^7.16.0` dependency became a `^7` range, widening it by sixteen minor
|
|
14
|
+
* versions while the pin stayed at 7.16.0. Tying the bound to the pin is what stops the two drifting again.
|
|
15
|
+
*/
|
|
16
|
+
describe('when declaring the fundamentals range', () => {
|
|
17
|
+
const manifest = JSON.parse(
|
|
18
|
+
readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf-8')) as {
|
|
19
|
+
dependencies?: Record<string, string>;
|
|
20
|
+
peerDependencies?: Record<string, string>;
|
|
21
|
+
devDependencies?: Record<string, string>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const dependency = manifest.dependencies?.['@cratis/fundamentals'];
|
|
25
|
+
const pinned = manifest.devDependencies?.['@cratis/fundamentals'];
|
|
26
|
+
|
|
27
|
+
it('should declare fundamentals as an ordinary dependency', () => dependency!.should.not.be.undefined);
|
|
28
|
+
|
|
29
|
+
it('should pin one concrete version to build against', () => pinned!.should.match(/^\d+\.\d+\.\d+$/));
|
|
30
|
+
|
|
31
|
+
it('should admit no version below the one it builds against', () => dependency!.should.equal(`^${pinned}`));
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Not a peer. A peer dependency is for a singleton the consuming application owns and has a view on - React is
|
|
35
|
+
* the example `@cratis/arc.react` gets right. Fundamentals is the other kind. The application does import it -
|
|
36
|
+
* the proxy generator emits `import { Guid } from '@cratis/fundamentals'` straight into application code - but
|
|
37
|
+
* it never chose it and has no view on which version is right. Arc does, because Arc's own generated output is
|
|
38
|
+
* what has to compile against it, so requiring the consumer to name a version makes it declare something it has
|
|
39
|
+
* no opinion about - and a peer does not reach it transitively through `@cratis/arc.react` anyway, so the
|
|
40
|
+
* declaration lands on the consumer as a warning to silence rather than a choice to make.
|
|
41
|
+
*/
|
|
42
|
+
it('should not require the consumer to declare it', () =>
|
|
43
|
+
(manifest.peerDependencies?.['@cratis/fundamentals'] === undefined).should.be.true);
|
|
44
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cratis/arc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "21.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Cratis",
|
|
6
6
|
"license": "MIT",
|
|
@@ -69,7 +69,10 @@
|
|
|
69
69
|
"up": "yarn g:up"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@cratis/fundamentals": "^7.
|
|
72
|
+
"@cratis/fundamentals": "^7.17.1",
|
|
73
73
|
"rxjs": "^7.8.2"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@cratis/fundamentals": "7.17.1"
|
|
74
77
|
}
|
|
75
78
|
}
|
package/queries/QueryResult.ts
CHANGED
|
@@ -37,6 +37,7 @@ type ServerValidationResult = {
|
|
|
37
37
|
message: string;
|
|
38
38
|
members: string[];
|
|
39
39
|
state: object;
|
|
40
|
+
reason?: string;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
type ServerPagingInfo = {
|
|
@@ -153,7 +154,7 @@ export class QueryResult<TDataType = object> implements IQueryResult<TDataType>
|
|
|
153
154
|
this.isAuthorized = result.isAuthorized;
|
|
154
155
|
this.isValid = result.isValid;
|
|
155
156
|
this.hasExceptions = result.hasExceptions;
|
|
156
|
-
this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));
|
|
157
|
+
this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state, _.reason));
|
|
157
158
|
this.exceptionMessages = result.exceptionMessages;
|
|
158
159
|
this.exceptionStackTrace = result.exceptionStackTrace;
|
|
159
160
|
this.paging = new PagingInfo();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Cratis. All rights reserved.
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
|
+
import { ValidationResultReason } from './ValidationResultReason';
|
|
4
5
|
import { ValidationResultSeverity } from './ValidationResultSeverity';
|
|
5
6
|
|
|
6
7
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -9,8 +10,19 @@ import { ValidationResultSeverity } from './ValidationResultSeverity';
|
|
|
9
10
|
* Represents a validation error with a message for one or more members.
|
|
10
11
|
*/
|
|
11
12
|
export class ValidationResult {
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Initializes a new instance of the {@link ValidationResult} class.
|
|
15
|
+
* @param severity The severity of the result.
|
|
16
|
+
* @param message The message. A developer diagnostic when {@link reason} is anything but `rule`.
|
|
17
|
+
* @param members The members the result is attributed to.
|
|
18
|
+
* @param state State associated with the result - the rule author's, carried straight through.
|
|
19
|
+
* @param reason What composed the result. Defaults to `rule`, meaning an authored rule rejected the input.
|
|
20
|
+
*/
|
|
21
|
+
constructor(
|
|
22
|
+
readonly severity: ValidationResultSeverity,
|
|
23
|
+
readonly message: string,
|
|
24
|
+
readonly members: string[],
|
|
25
|
+
readonly state: any,
|
|
26
|
+
readonly reason: ValidationResultReason = ValidationResultReason.Rule) {
|
|
13
27
|
}
|
|
14
28
|
}
|
|
15
|
-
|
|
16
|
-
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Holds the well-known values for what composed a validation result - the machine-readable counterpart to its
|
|
6
|
+
* message.
|
|
7
|
+
* @remarks
|
|
8
|
+
* A rejection's message is a developer diagnostic, not copy to show a user. Branch on this instead of matching the
|
|
9
|
+
* message, and render your own wording for anything the framework composed.
|
|
10
|
+
*
|
|
11
|
+
* This is deliberately not an enum. Rejections are composed in Arc, in Chronicle and in application code, so the set
|
|
12
|
+
* is open: treat an unrecognized value the way you would treat {@link ValidationResultReason.Rule} rather than as an
|
|
13
|
+
* error.
|
|
14
|
+
*/
|
|
15
|
+
export const ValidationResultReason = {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A rule authored by the application rejected the input. The message is the author's, and is meant to be shown.
|
|
19
|
+
*/
|
|
20
|
+
Rule: 'rule',
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The append was rejected because the event source moved on since it was read. Retryable - re-read and resubmit.
|
|
24
|
+
*/
|
|
25
|
+
ConcurrencyViolation: 'concurrencyViolation',
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A constraint on the event store rejected the append.
|
|
29
|
+
*/
|
|
30
|
+
ConstraintViolation: 'constraintViolation',
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A validator threw, and the framework substituted this result for the one the validator would have produced.
|
|
34
|
+
* Nothing the author wrote survives, so the message is not theirs to show.
|
|
35
|
+
*/
|
|
36
|
+
ValidatorFailed: 'validatorFailed',
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Something the command needed in order to be evaluated was not available, most often the read model a
|
|
40
|
+
* validator depends on. Raised before any rule ran, so nothing about the command's own rules was decided.
|
|
41
|
+
*/
|
|
42
|
+
DependencyUnavailable: 'dependencyUnavailable',
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The request itself could not be read - a malformed body, or a value that could not be bound. No rule was
|
|
46
|
+
* reached.
|
|
47
|
+
*/
|
|
48
|
+
MalformedRequest: 'malformedRequest'
|
|
49
|
+
} as const;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The type of a validation result reason. Widened to string because the set is open.
|
|
53
|
+
*/
|
|
54
|
+
export type ValidationResultReason = string;
|
package/validation/index.ts
CHANGED