@cratis/arc 23.19.1 → 23.21.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 (61) hide show
  1. package/commands/CommandResult.ts +5 -0
  2. package/commands/ICommandResult.ts +3 -0
  3. package/commands/for_CommandResult/when_receiving_a_mapped_failure.ts +32 -0
  4. package/dist/cjs/commands/CommandResult.d.ts +2 -0
  5. package/dist/cjs/commands/CommandResult.d.ts.map +1 -1
  6. package/dist/cjs/commands/CommandResult.js +2 -0
  7. package/dist/cjs/commands/CommandResult.js.map +1 -1
  8. package/dist/cjs/commands/ICommandResult.d.ts +1 -0
  9. package/dist/cjs/commands/ICommandResult.d.ts.map +1 -1
  10. package/dist/cjs/queries/IQueryResult.d.ts +1 -0
  11. package/dist/cjs/queries/IQueryResult.d.ts.map +1 -1
  12. package/dist/cjs/queries/QueryInstanceCache.d.ts.map +1 -1
  13. package/dist/cjs/queries/QueryInstanceCache.js +2 -2
  14. package/dist/cjs/queries/QueryInstanceCache.js.map +1 -1
  15. package/dist/cjs/queries/QueryResult.d.ts +2 -0
  16. package/dist/cjs/queries/QueryResult.d.ts.map +1 -1
  17. package/dist/cjs/queries/QueryResult.js +2 -0
  18. package/dist/cjs/queries/QueryResult.js.map +1 -1
  19. package/dist/cjs/queries/QueryResultWithState.d.ts +2 -1
  20. package/dist/cjs/queries/QueryResultWithState.d.ts.map +1 -1
  21. package/dist/cjs/queries/QueryResultWithState.js +5 -2
  22. package/dist/cjs/queries/QueryResultWithState.js.map +1 -1
  23. package/dist/esm/commands/CommandResult.d.ts +2 -0
  24. package/dist/esm/commands/CommandResult.d.ts.map +1 -1
  25. package/dist/esm/commands/CommandResult.js +2 -0
  26. package/dist/esm/commands/CommandResult.js.map +1 -1
  27. package/dist/esm/commands/ICommandResult.d.ts +1 -0
  28. package/dist/esm/commands/ICommandResult.d.ts.map +1 -1
  29. package/dist/esm/commands/for_CommandResult/when_receiving_a_mapped_failure.d.ts +2 -0
  30. package/dist/esm/commands/for_CommandResult/when_receiving_a_mapped_failure.d.ts.map +1 -0
  31. package/dist/esm/commands/for_CommandResult/when_receiving_a_mapped_failure.js +24 -0
  32. package/dist/esm/commands/for_CommandResult/when_receiving_a_mapped_failure.js.map +1 -0
  33. package/dist/esm/queries/IQueryResult.d.ts +1 -0
  34. package/dist/esm/queries/IQueryResult.d.ts.map +1 -1
  35. package/dist/esm/queries/QueryInstanceCache.d.ts.map +1 -1
  36. package/dist/esm/queries/QueryInstanceCache.js +2 -2
  37. package/dist/esm/queries/QueryInstanceCache.js.map +1 -1
  38. package/dist/esm/queries/QueryResult.d.ts +2 -0
  39. package/dist/esm/queries/QueryResult.d.ts.map +1 -1
  40. package/dist/esm/queries/QueryResult.js +2 -0
  41. package/dist/esm/queries/QueryResult.js.map +1 -1
  42. package/dist/esm/queries/QueryResultWithState.d.ts +2 -1
  43. package/dist/esm/queries/QueryResultWithState.d.ts.map +1 -1
  44. package/dist/esm/queries/QueryResultWithState.js +5 -2
  45. package/dist/esm/queries/QueryResultWithState.js.map +1 -1
  46. package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.d.ts +2 -0
  47. package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.d.ts.map +1 -0
  48. package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.js +25 -0
  49. package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.js.map +1 -0
  50. package/dist/esm/queries/for_QueryResult/when_receiving_a_mapped_failure.d.ts +2 -0
  51. package/dist/esm/queries/for_QueryResult/when_receiving_a_mapped_failure.d.ts.map +1 -0
  52. package/dist/esm/queries/for_QueryResult/when_receiving_a_mapped_failure.js +37 -0
  53. package/dist/esm/queries/for_QueryResult/when_receiving_a_mapped_failure.js.map +1 -0
  54. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  55. package/package.json +1 -1
  56. package/queries/IQueryResult.ts +3 -0
  57. package/queries/QueryInstanceCache.ts +2 -0
  58. package/queries/QueryResult.ts +5 -0
  59. package/queries/QueryResultWithState.ts +3 -0
  60. package/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.ts +30 -0
  61. package/queries/for_QueryResult/when_receiving_a_mapped_failure.ts +45 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@cratis/arc",
4
- "version": "23.19.1",
4
+ "version": "23.21.0",
5
5
  "description": "TypeScript command, query, validation, identity, and messaging runtime for Cratis Arc — the CQRS application framework for ASP.NET Core — used by generated proxies.",
6
6
  "keywords": [
7
7
  "cratis",
@@ -51,6 +51,9 @@ export interface IQueryResult<TDataType> {
51
51
  */
52
52
  readonly isRetryable?: boolean;
53
53
 
54
+ /** Gets the stable public failure code, if the server mapped the exception. */
55
+ readonly errorCode?: string;
56
+
54
57
  /**
55
58
  * Gets whether or not the query is valid.
56
59
  */
@@ -252,6 +252,7 @@ export class QueryInstanceCache {
252
252
  next.isReady,
253
253
  next.authorizationFailureReason,
254
254
  next.isRetryable,
255
+ next.errorCode,
255
256
  );
256
257
  }
257
258
 
@@ -262,6 +263,7 @@ export class QueryInstanceCache {
262
263
  && result.isAuthorized === previous.isAuthorized
263
264
  && result.authorizationFailureReason === previous.authorizationFailureReason
264
265
  && result.isRetryable === previous.isRetryable
266
+ && result.errorCode === previous.errorCode
265
267
  && result.isValid === previous.isValid
266
268
  && result.hasExceptions === previous.hasExceptions
267
269
  && result.exceptionStackTrace === previous.exceptionStackTrace
@@ -22,6 +22,7 @@ type ServerQueryResult = {
22
22
  exceptionStackTrace: string;
23
23
  authorizationFailureReason?: string;
24
24
  isRetryable?: boolean;
25
+ errorCode?: string;
25
26
  paging: ServerPagingInfo;
26
27
  changeSet?: ServerChangeSet;
27
28
  };
@@ -204,6 +205,7 @@ export class QueryResult<TDataType = object> implements IQueryResult<TDataType>
204
205
  this.isAuthorized = result.isAuthorized;
205
206
  this.authorizationFailureReason = result.authorizationFailureReason ?? '';
206
207
  this.isRetryable = result.isRetryable ?? false;
208
+ this.errorCode = result.errorCode;
207
209
  this.isValid = result.isValid;
208
210
  this.hasExceptions = result.hasExceptions;
209
211
  this.validationResults = result.validationResults.map(
@@ -271,6 +273,9 @@ export class QueryResult<TDataType = object> implements IQueryResult<TDataType>
271
273
  /** @inheritdoc */
272
274
  readonly isRetryable?: boolean;
273
275
 
276
+ /** @inheritdoc */
277
+ readonly errorCode?: string;
278
+
274
279
  /** @inheritdoc */
275
280
  readonly isValid: boolean;
276
281
 
@@ -70,6 +70,7 @@ export class QueryResultWithState<TDataType> implements IQueryResult<TDataType>
70
70
  * @param {ChangeSet<unknown> | undefined} changeSet Optional change set from the server describing the delta since the last update.
71
71
  * @param {boolean} isReady Whether the query has produced a result. Defaults to true so existing constructor calls
72
72
  * represent settled synthetic states; {@link initial} explicitly uses false because no server result exists yet.
73
+ * @param {string | undefined} errorCode Optional stable public failure code.
73
74
  */
74
75
  constructor(
75
76
  readonly data: TDataType,
@@ -86,6 +87,7 @@ export class QueryResultWithState<TDataType> implements IQueryResult<TDataType>
86
87
  readonly isReady: boolean = true,
87
88
  readonly authorizationFailureReason: string = '',
88
89
  readonly isRetryable: boolean = false,
90
+ readonly errorCode?: string,
89
91
  ) {}
90
92
 
91
93
  /** @inheritdoc */
@@ -121,6 +123,7 @@ export class QueryResultWithState<TDataType> implements IQueryResult<TDataType>
121
123
  queryResult.isReady ?? true,
122
124
  queryResult.authorizationFailureReason ?? '',
123
125
  queryResult.isRetryable ?? false,
126
+ queryResult.errorCode,
124
127
  );
125
128
  }
126
129
  }
@@ -0,0 +1,30 @@
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 { expect } from 'chai';
5
+ import sinon from 'sinon';
6
+ import { PagingInfo } from '../../PagingInfo.js';
7
+ import { QueryInstanceCache } from '../../QueryInstanceCache.js';
8
+ import { QueryResultWithState } from '../../QueryResultWithState.js';
9
+
10
+ describe('when setting the last result with only the error code changed', () => {
11
+ it('should retain the code when data is reconciled and notify when it clears', () => {
12
+ const cache = new QueryInstanceCache();
13
+ const key = 'MyQuery::';
14
+ const listener = sinon.stub();
15
+ const state = (code?: string) => new QueryResultWithState(
16
+ ['a'], PagingInfo.noPaging, false, true, true, [], true, ['An unexpected error occurred.'], '', false, undefined, true, '', false, code,
17
+ );
18
+ cache.getOrCreate(key, () => ({}));
19
+ cache.addListener<string[]>(key, listener);
20
+ cache.setLastResult(key, state());
21
+ listener.resetHistory();
22
+ cache.setLastResult(key, state('namespace_closing'));
23
+ listener.calledOnce.should.be.true;
24
+ listener.firstCall.args[0].errorCode.should.equal('namespace_closing');
25
+ listener.resetHistory();
26
+ cache.setLastResult(key, state());
27
+ listener.calledOnce.should.be.true;
28
+ expect(listener.firstCall.args[0].errorCode).to.be.undefined;
29
+ });
30
+ });
@@ -0,0 +1,45 @@
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 { expect } from 'chai';
5
+ import { QueryResult } from '../QueryResult.js';
6
+ import { QueryResultWithState } from '../QueryResultWithState.js';
7
+ import { PagingInfo } from '../PagingInfo.js';
8
+
9
+ describe('when receiving a mapped query failure', () => {
10
+ const serverResult = {
11
+ data: {},
12
+ isSuccess: false,
13
+ isAuthorized: true,
14
+ isValid: true,
15
+ hasExceptions: true,
16
+ validationResults: [],
17
+ exceptionMessages: ['An unexpected error occurred.'],
18
+ exceptionStackTrace: '',
19
+ paging: { page: 0, size: 0, totalItems: 0, totalPages: 0 },
20
+ };
21
+
22
+ it('should preserve the code through deserialization and state conversion', () => {
23
+ const result = new QueryResult({ ...serverResult, errorCode: 'namespace_recovery_required' }, Object, false);
24
+ const state = QueryResultWithState.fromQueryResult(result, false);
25
+ result.errorCode!.should.equal('namespace_recovery_required');
26
+ state.errorCode!.should.equal(result.errorCode);
27
+ state.isRetryable.should.be.false;
28
+ });
29
+
30
+ it('should tolerate an older server without a code', () =>
31
+ expect(new QueryResult(serverResult, Object, false).errorCode).to.be.undefined);
32
+
33
+ it('should keep every existing positional constructor argument', () => {
34
+ const state = new QueryResultWithState({}, PagingInfo.noPaging, false, false, true, [], false, [], '', false, undefined, false, 'denied', true);
35
+ state.isReady.should.be.false;
36
+ state.authorizationFailureReason.should.equal('denied');
37
+ state.isRetryable.should.be.true;
38
+ expect(state.errorCode).to.be.undefined;
39
+ });
40
+
41
+ it('should clear the code when a later successful result arrives', () => {
42
+ const result = new QueryResult({ ...serverResult, isSuccess: true, hasExceptions: false, exceptionMessages: [] }, Object, false);
43
+ expect(QueryResultWithState.fromQueryResult(result, false).errorCode).to.be.undefined;
44
+ });
45
+ });