@cratis/arc 21.9.2 → 21.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/commands/CommandResult.ts +5 -2
  2. package/commands/for_CommandResult/when_constructing_from_a_server_result_with_a_constraint_violation.ts +48 -0
  3. package/commands/for_CommandResult/when_creating_a_validation_failed_result.ts +25 -0
  4. package/dist/cjs/commands/CommandResult.js +4 -2
  5. package/dist/cjs/commands/CommandResult.js.map +1 -1
  6. package/dist/cjs/queries/QueryResult.js +4 -2
  7. package/dist/cjs/queries/QueryResult.js.map +1 -1
  8. package/dist/cjs/validation/ValidationResult.js +6 -1
  9. package/dist/cjs/validation/ValidationResult.js.map +1 -1
  10. package/dist/esm/commands/CommandResult.d.ts +1 -0
  11. package/dist/esm/commands/CommandResult.d.ts.map +1 -1
  12. package/dist/esm/commands/CommandResult.js +4 -2
  13. package/dist/esm/commands/CommandResult.js.map +1 -1
  14. package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_a_constraint_violation.d.ts +2 -0
  15. package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_a_constraint_violation.d.ts.map +1 -0
  16. package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_a_constraint_violation.js +38 -0
  17. package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_a_constraint_violation.js.map +1 -0
  18. package/dist/esm/commands/for_CommandResult/when_creating_a_validation_failed_result.d.ts +2 -0
  19. package/dist/esm/commands/for_CommandResult/when_creating_a_validation_failed_result.d.ts.map +1 -0
  20. package/dist/esm/commands/for_CommandResult/when_creating_a_validation_failed_result.js +12 -0
  21. package/dist/esm/commands/for_CommandResult/when_creating_a_validation_failed_result.js.map +1 -0
  22. package/dist/esm/queries/QueryResult.d.ts +1 -0
  23. package/dist/esm/queries/QueryResult.d.ts.map +1 -1
  24. package/dist/esm/queries/QueryResult.js +4 -2
  25. package/dist/esm/queries/QueryResult.js.map +1 -1
  26. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.d.ts +2 -0
  27. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.d.ts.map +1 -0
  28. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.js +28 -0
  29. package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.js.map +1 -0
  30. package/dist/esm/queries/for_QueryResult/when_creating_a_validation_failed_result.d.ts +2 -0
  31. package/dist/esm/queries/for_QueryResult/when_creating_a_validation_failed_result.d.ts.map +1 -0
  32. package/dist/esm/queries/for_QueryResult/when_creating_a_validation_failed_result.js +12 -0
  33. package/dist/esm/queries/for_QueryResult/when_creating_a_validation_failed_result.js.map +1 -0
  34. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  35. package/dist/esm/validation/ValidationResult.d.ts +2 -1
  36. package/dist/esm/validation/ValidationResult.d.ts.map +1 -1
  37. package/dist/esm/validation/ValidationResult.js +6 -1
  38. package/dist/esm/validation/ValidationResult.js.map +1 -1
  39. package/package.json +1 -1
  40. package/queries/QueryResult.ts +5 -2
  41. package/queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.ts +35 -0
  42. package/queries/for_QueryResult/when_creating_a_validation_failed_result.ts +27 -0
  43. package/validation/ValidationResult.ts +5 -1
@@ -6,6 +6,7 @@ export declare class ValidationResult {
6
6
  readonly members: string[];
7
7
  readonly state: any;
8
8
  readonly reason: ValidationResultReason;
9
- constructor(severity: ValidationResultSeverity, message: string, members: string[], state: any, reason?: ValidationResultReason);
9
+ readonly reasonDetail?: string | undefined;
10
+ constructor(severity: ValidationResultSeverity, message: string, members: string[], state: any, reason?: ValidationResultReason, reasonDetail?: string | undefined);
10
11
  }
11
12
  //# sourceMappingURL=ValidationResult.d.ts.map
@@ -1 +1 @@
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
+ {"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;IAarB,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;IACvC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM;IANlC,YACa,QAAQ,EAAE,wBAAwB,EAClC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,GAAG,EACV,MAAM,GAAE,sBAAoD,EAC5D,YAAY,CAAC,EAAE,MAAM,YAAA,EACjC;CACJ"}
@@ -10,6 +10,7 @@ import { ValidationResultReason } from './ValidationResultReason.js';
10
10
  members;
11
11
  state;
12
12
  reason;
13
+ reasonDetail;
13
14
  /**
14
15
  * Initializes a new instance of the {@link ValidationResult} class.
15
16
  * @param severity The severity of the result.
@@ -17,12 +18,16 @@ import { ValidationResultReason } from './ValidationResultReason.js';
17
18
  * @param members The members the result is attributed to.
18
19
  * @param state State associated with the result - the rule author's, carried straight through.
19
20
  * @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){
21
+ * @param reasonDetail Which specific thing within {@link reason} produced the result - the name of the violated
22
+ * constraint for `constraintViolation`, for instance. Undefined when the reason carries no finer identity.
23
+ * Branch on this rather than matching {@link message}, which is prose and free to change.
24
+ */ constructor(severity, message, members, state, reason = ValidationResultReason.Rule, reasonDetail){
21
25
  this.severity = severity;
22
26
  this.message = message;
23
27
  this.members = members;
24
28
  this.state = state;
25
29
  this.reason = reason;
30
+ this.reasonDetail = reasonDetail;
26
31
  }
27
32
  }
28
33
 
@@ -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 { 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;;;;"}
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 * @param reasonDetail Which specific thing within {@link reason} produced the result - the name of the violated\n * constraint for `constraintViolation`, for instance. Undefined when the reason carries no finer identity.\n * Branch on this rather than matching {@link message}, which is prose and free to change.\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 readonly reasonDetail?: string) {\n }\n}\n"],"names":["ValidationResult","reason","ValidationResultReason","Rule","reasonDetail","severity","message","members","state"],"mappings":";;AAAA;AACA;AAKA;;AAIC,IACM,MAAMA,gBAAAA,CAAAA;;;;;;;AACT;;;;;;;;;;QAWA,WAAA,CACI,QAA2C,EAC3C,OAAwB,EACxB,OAA0B,EAC1B,KAAmB,EACnB,MAASC,GAAiCC,sBAAAA,CAAuBC,IAAI,EAC5DC,YAAqB,CAAE;aALvBC,QAAAA,GAAAA,QAAAA;aACAC,OAAAA,GAAAA,OAAAA;aACAC,OAAAA,GAAAA,OAAAA;aACAC,KAAAA,GAAAA,KAAAA;aACAP,MAAAA,GAAAA,MAAAA;aACAG,YAAAA,GAAAA,YAAAA;AACb,IAAA;AACJ;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/arc",
3
- "version": "21.9.2",
3
+ "version": "21.11.0",
4
4
  "description": "",
5
5
  "author": "Cratis",
6
6
  "license": "MIT",
@@ -38,6 +38,7 @@ type ServerValidationResult = {
38
38
  members: string[];
39
39
  state: object;
40
40
  reason?: string;
41
+ reasonDetail?: string;
41
42
  }
42
43
 
43
44
  type ServerPagingInfo = {
@@ -94,7 +95,9 @@ export class QueryResult<TDataType = object> implements IQueryResult<TDataType>
94
95
  severity: _.severity,
95
96
  message: _.message,
96
97
  members: _.members,
97
- state: _.state
98
+ state: _.state,
99
+ reason: _.reason,
100
+ reasonDetail: _.reasonDetail
98
101
  })),
99
102
  exceptionMessages: [],
100
103
  exceptionStackTrace: '',
@@ -154,7 +157,7 @@ export class QueryResult<TDataType = object> implements IQueryResult<TDataType>
154
157
  this.isAuthorized = result.isAuthorized;
155
158
  this.isValid = result.isValid;
156
159
  this.hasExceptions = result.hasExceptions;
157
- this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state, _.reason));
160
+ this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state, _.reason, _.reasonDetail));
158
161
  this.exceptionMessages = result.exceptionMessages;
159
162
  this.exceptionStackTrace = result.exceptionStackTrace;
160
163
  this.paging = new PagingInfo();
@@ -0,0 +1,35 @@
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 { QueryResult } from '../QueryResult';
7
+
8
+ describe('when constructing from a server result with a constraint violation', () => {
9
+ const result = new QueryResult({
10
+ data: {},
11
+ isSuccess: false,
12
+ isAuthorized: true,
13
+ isValid: false,
14
+ hasExceptions: false,
15
+ validationResults: [
16
+ {
17
+ severity: ValidationResultSeverity.Error,
18
+ message: 'The organization number is already in use',
19
+ members: ['organizationNumber'],
20
+ state: {},
21
+ reason: ValidationResultReason.ConstraintViolation,
22
+ reasonDetail: 'UniqueOrganizationNumber'
23
+ }
24
+ ],
25
+ exceptionMessages: [],
26
+ exceptionStackTrace: '',
27
+ paging: { page: 0, size: 0, totalItems: 0, totalPages: 0 }
28
+ }, Object, false);
29
+
30
+ it('should carry what kind of thing rejected the query', () =>
31
+ result.validationResults[0].reason.should.equal(ValidationResultReason.ConstraintViolation));
32
+
33
+ it('should carry the name of the violated constraint', () =>
34
+ result.validationResults[0].reasonDetail!.should.equal('UniqueOrganizationNumber'));
35
+ });
@@ -0,0 +1,27 @@
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 { ValidationResult } from '../../validation/ValidationResult';
5
+ import { ValidationResultReason } from '../../validation/ValidationResultReason';
6
+ import { ValidationResultSeverity } from '../../validation/ValidationResultSeverity';
7
+ import { QueryResult } from '../QueryResult';
8
+
9
+ // The query side is meant to read the same way the command side does, which only holds if it carries
10
+ // the same fields through - so this is the mirror of the CommandResult spec of the same name.
11
+ describe('when creating a validation failed result', () => {
12
+ const result = QueryResult.validationFailed([
13
+ new ValidationResult(
14
+ ValidationResultSeverity.Error,
15
+ 'The organization number is already in use',
16
+ ['organizationNumber'],
17
+ {},
18
+ ValidationResultReason.ConstraintViolation,
19
+ 'UniqueOrganizationNumber')
20
+ ], { defaultValue: {}, modelType: Object, enumerable: false });
21
+
22
+ it('should keep the reason the caller gave it', () =>
23
+ result.validationResults[0].reason.should.equal(ValidationResultReason.ConstraintViolation));
24
+
25
+ it('should keep the name of the violated constraint', () =>
26
+ result.validationResults[0].reasonDetail!.should.equal('UniqueOrganizationNumber'));
27
+ });
@@ -17,12 +17,16 @@ export class ValidationResult {
17
17
  * @param members The members the result is attributed to.
18
18
  * @param state State associated with the result - the rule author's, carried straight through.
19
19
  * @param reason What composed the result. Defaults to `rule`, meaning an authored rule rejected the input.
20
+ * @param reasonDetail Which specific thing within {@link reason} produced the result - the name of the violated
21
+ * constraint for `constraintViolation`, for instance. Undefined when the reason carries no finer identity.
22
+ * Branch on this rather than matching {@link message}, which is prose and free to change.
20
23
  */
21
24
  constructor(
22
25
  readonly severity: ValidationResultSeverity,
23
26
  readonly message: string,
24
27
  readonly members: string[],
25
28
  readonly state: any,
26
- readonly reason: ValidationResultReason = ValidationResultReason.Rule) {
29
+ readonly reason: ValidationResultReason = ValidationResultReason.Rule,
30
+ readonly reasonDetail?: string) {
27
31
  }
28
32
  }