@cratis/arc 23.19.0 → 23.20.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 +5 -0
- package/commands/ICommandResult.ts +3 -0
- package/commands/for_CommandResult/when_receiving_a_mapped_failure.ts +32 -0
- package/dist/cjs/commands/CommandResult.d.ts +2 -0
- package/dist/cjs/commands/CommandResult.d.ts.map +1 -1
- package/dist/cjs/commands/CommandResult.js +2 -0
- package/dist/cjs/commands/CommandResult.js.map +1 -1
- package/dist/cjs/commands/ICommandResult.d.ts +1 -0
- package/dist/cjs/commands/ICommandResult.d.ts.map +1 -1
- package/dist/cjs/queries/IQueryResult.d.ts +1 -0
- package/dist/cjs/queries/IQueryResult.d.ts.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.js +2 -2
- package/dist/cjs/queries/QueryInstanceCache.js.map +1 -1
- package/dist/cjs/queries/QueryResult.d.ts +2 -0
- package/dist/cjs/queries/QueryResult.d.ts.map +1 -1
- package/dist/cjs/queries/QueryResult.js +2 -0
- package/dist/cjs/queries/QueryResult.js.map +1 -1
- package/dist/cjs/queries/QueryResultWithState.d.ts +2 -1
- package/dist/cjs/queries/QueryResultWithState.d.ts.map +1 -1
- package/dist/cjs/queries/QueryResultWithState.js +5 -2
- package/dist/cjs/queries/QueryResultWithState.js.map +1 -1
- package/dist/esm/commands/CommandResult.d.ts +2 -0
- package/dist/esm/commands/CommandResult.d.ts.map +1 -1
- package/dist/esm/commands/CommandResult.js +2 -0
- package/dist/esm/commands/CommandResult.js.map +1 -1
- package/dist/esm/commands/ICommandResult.d.ts +1 -0
- package/dist/esm/commands/ICommandResult.d.ts.map +1 -1
- package/dist/esm/commands/for_CommandResult/when_receiving_a_mapped_failure.d.ts +2 -0
- package/dist/esm/commands/for_CommandResult/when_receiving_a_mapped_failure.d.ts.map +1 -0
- package/dist/esm/commands/for_CommandResult/when_receiving_a_mapped_failure.js +24 -0
- package/dist/esm/commands/for_CommandResult/when_receiving_a_mapped_failure.js.map +1 -0
- package/dist/esm/queries/IQueryResult.d.ts +1 -0
- package/dist/esm/queries/IQueryResult.d.ts.map +1 -1
- package/dist/esm/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/esm/queries/QueryInstanceCache.js +2 -2
- package/dist/esm/queries/QueryInstanceCache.js.map +1 -1
- package/dist/esm/queries/QueryResult.d.ts +2 -0
- package/dist/esm/queries/QueryResult.d.ts.map +1 -1
- package/dist/esm/queries/QueryResult.js +2 -0
- package/dist/esm/queries/QueryResult.js.map +1 -1
- package/dist/esm/queries/QueryResultWithState.d.ts +2 -1
- package/dist/esm/queries/QueryResultWithState.d.ts.map +1 -1
- package/dist/esm/queries/QueryResultWithState.js +5 -2
- package/dist/esm/queries/QueryResultWithState.js.map +1 -1
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.js +25 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.js.map +1 -0
- package/dist/esm/queries/for_QueryResult/when_receiving_a_mapped_failure.d.ts +2 -0
- package/dist/esm/queries/for_QueryResult/when_receiving_a_mapped_failure.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryResult/when_receiving_a_mapped_failure.js +37 -0
- package/dist/esm/queries/for_QueryResult/when_receiving_a_mapped_failure.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/queries/IQueryResult.ts +3 -0
- package/queries/QueryInstanceCache.ts +2 -0
- package/queries/QueryResult.ts +5 -0
- package/queries/QueryResultWithState.ts +3 -0
- package/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.ts +30 -0
- 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.
|
|
4
|
+
"version": "23.20.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",
|
package/queries/IQueryResult.ts
CHANGED
|
@@ -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
|
package/queries/QueryResult.ts
CHANGED
|
@@ -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
|
}
|
package/queries/for_QueryInstanceCache/when_setting_last_result/with_only_error_code_changed.ts
ADDED
|
@@ -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
|
+
});
|