@cratis/arc 22.161.0 → 22.163.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/Command.ts +14 -4
- package/commands/for_Command/GeneratedCommand.ts +32 -0
- package/commands/for_Command/when_executing/with_a_failed_submission.ts +40 -0
- package/commands/for_Command/when_executing/with_an_edit_during_submission.ts +33 -0
- package/commands/for_Command/when_executing/with_generated_property_accessors.ts +54 -0
- package/commands/for_Command/when_executing/with_submitted_falsy_values.ts +30 -0
- package/commands/for_Command/when_setting_initial_values_from_current_values.ts +28 -0
- package/dist/cjs/commands/Command.d.ts +1 -0
- package/dist/cjs/commands/Command.d.ts.map +1 -1
- package/dist/cjs/commands/Command.js +13 -4
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.d.ts +1 -0
- package/dist/cjs/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.js +6 -2
- package/dist/cjs/queries/QueryInstanceCache.js.map +1 -1
- package/dist/esm/commands/Command.d.ts +1 -0
- package/dist/esm/commands/Command.d.ts.map +1 -1
- package/dist/esm/commands/Command.js +13 -4
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/for_Command/GeneratedCommand.d.ts +15 -0
- package/dist/esm/commands/for_Command/GeneratedCommand.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/GeneratedCommand.js +24 -0
- package/dist/esm/commands/for_Command/GeneratedCommand.js.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_a_failed_submission.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/with_a_failed_submission.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_a_failed_submission.js +34 -0
- package/dist/esm/commands/for_Command/when_executing/with_a_failed_submission.js.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_an_edit_during_submission.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/with_an_edit_during_submission.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_an_edit_during_submission.js +26 -0
- package/dist/esm/commands/for_Command/when_executing/with_an_edit_during_submission.js.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_generated_property_accessors.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/with_generated_property_accessors.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_generated_property_accessors.js +44 -0
- package/dist/esm/commands/for_Command/when_executing/with_generated_property_accessors.js.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_submitted_falsy_values.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/with_submitted_falsy_values.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_submitted_falsy_values.js +24 -0
- package/dist/esm/commands/for_Command/when_executing/with_submitted_falsy_values.js.map +1 -0
- package/dist/esm/commands/for_Command/when_setting_initial_values_from_current_values.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_setting_initial_values_from_current_values.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_setting_initial_values_from_current_values.js +24 -0
- package/dist/esm/commands/for_Command/when_setting_initial_values_from_current_values.js.map +1 -0
- package/dist/esm/queries/QueryInstanceCache.d.ts +1 -0
- package/dist/esm/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/esm/queries/QueryInstanceCache.js +6 -2
- package/dist/esm/queries/QueryInstanceCache.js.map +1 -1
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_changed_metadata.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_changed_metadata.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_changed_metadata.js +51 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_changed_metadata.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_equivalent_metadata.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_equivalent_metadata.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_equivalent_metadata.js +27 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_equivalent_metadata.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/queries/QueryInstanceCache.ts +17 -4
- package/queries/for_QueryInstanceCache/when_setting_last_result/with_changed_metadata.ts +58 -0
- package/queries/for_QueryInstanceCache/when_setting_last_result/with_equivalent_metadata.ts +39 -0
package/commands/Command.ts
CHANGED
|
@@ -104,8 +104,12 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
104
104
|
actualRoute = route;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
const submittedValues = this.captureCurrentValues();
|
|
107
108
|
const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);
|
|
108
|
-
|
|
109
|
+
if (result.isSuccess) {
|
|
110
|
+
this._initialValues = submittedValues;
|
|
111
|
+
this.updateHasChanges();
|
|
112
|
+
}
|
|
109
113
|
return result;
|
|
110
114
|
}
|
|
111
115
|
|
|
@@ -286,13 +290,19 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
286
290
|
|
|
287
291
|
/** @inheritdoc */
|
|
288
292
|
setInitialValuesFromCurrentValues() {
|
|
293
|
+
this._initialValues = this.captureCurrentValues();
|
|
294
|
+
this.updateHasChanges();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
private captureCurrentValues(): object {
|
|
298
|
+
const values = {};
|
|
289
299
|
this.propertyDescriptors.forEach(propertyDescriptor => {
|
|
290
300
|
const property = propertyDescriptor.name;
|
|
291
|
-
if (this
|
|
292
|
-
|
|
301
|
+
if (property in this) {
|
|
302
|
+
values[property] = this[property];
|
|
293
303
|
}
|
|
294
304
|
});
|
|
295
|
-
|
|
305
|
+
return values;
|
|
296
306
|
}
|
|
297
307
|
|
|
298
308
|
/** @inheritdoc */
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { Command } from '../Command.js';
|
|
5
|
+
import { PropertyDescriptor } from '../../reflection/PropertyDescriptor.js';
|
|
6
|
+
|
|
7
|
+
export class GeneratedCommand extends Command<{ value: unknown }> {
|
|
8
|
+
readonly route = '/save';
|
|
9
|
+
readonly propertyDescriptors = [new PropertyDescriptor('value', Object, true)];
|
|
10
|
+
#value: unknown;
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
super(Object, false);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get requestParameters(): string[] {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get properties(): string[] {
|
|
21
|
+
return ['value'];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get value(): unknown {
|
|
25
|
+
return this.#value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
set value(value: unknown) {
|
|
29
|
+
this.#value = value;
|
|
30
|
+
this.propertyChanged('value');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { a_command } from '../given/a_command.js';
|
|
5
|
+
|
|
6
|
+
for (const failure of ['server rejection', 'not found', 'network error', 'invalid JSON']) {
|
|
7
|
+
describe(`when executing with ${failure}`, () => {
|
|
8
|
+
let context: a_command;
|
|
9
|
+
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
context = new a_command();
|
|
12
|
+
context.command.setInitialValues({ someProperty: 'accepted' });
|
|
13
|
+
context.command.someProperty = 'rejected';
|
|
14
|
+
context.command.propertyChanged('someProperty');
|
|
15
|
+
|
|
16
|
+
if (failure === 'network error') {
|
|
17
|
+
context.fetchStub.rejects(new Error('offline'));
|
|
18
|
+
} else {
|
|
19
|
+
context.fetchStub.resolves({
|
|
20
|
+
status: failure === 'not found' ? 404 : 200,
|
|
21
|
+
json: async () => {
|
|
22
|
+
if (failure === 'invalid JSON') {
|
|
23
|
+
throw new Error('invalid JSON');
|
|
24
|
+
}
|
|
25
|
+
return { correlationId: '00000000-0000-0000-0000-000000000000', isSuccess: false, validationResults: [], exceptionMessages: ['rejected'] };
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
await context.command.execute();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => context.fetchHelper.restore());
|
|
33
|
+
|
|
34
|
+
it('should keep the command dirty', () => context.command.hasChanges.should.be.true);
|
|
35
|
+
it('should revert to the last accepted values', () => {
|
|
36
|
+
context.command.revertChanges();
|
|
37
|
+
context.command.someProperty.should.equal('accepted');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { a_command } from '../given/a_command.js';
|
|
5
|
+
|
|
6
|
+
describe('when executing with an edit during submission', () => {
|
|
7
|
+
let context: a_command;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
context = new a_command();
|
|
11
|
+
context.command.setInitialValues({ someProperty: 'accepted' });
|
|
12
|
+
context.command.someProperty = 'submitted';
|
|
13
|
+
context.command.propertyChanged('someProperty');
|
|
14
|
+
let complete!: (response: object) => void;
|
|
15
|
+
context.fetchStub.returns(new Promise(resolve => { complete = resolve; }));
|
|
16
|
+
|
|
17
|
+
const execution = context.command.execute();
|
|
18
|
+
context.command.someProperty = 'unsent edit';
|
|
19
|
+
context.command.propertyChanged('someProperty');
|
|
20
|
+
complete({ status: 200, json: async () => ({ correlationId: '00000000-0000-0000-0000-000000000000', isSuccess: true, validationResults: [] }) });
|
|
21
|
+
await execution;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => context.fetchHelper.restore());
|
|
25
|
+
|
|
26
|
+
it('should send the submitted value', () => JSON.parse(context.fetchStub.firstCall.args[1].body).someProperty.should.equal('submitted'));
|
|
27
|
+
it('should preserve the unsent edit', () => context.command.someProperty.should.equal('unsent edit'));
|
|
28
|
+
it('should keep the command dirty', () => context.command.hasChanges.should.be.true);
|
|
29
|
+
it('should revert to the submitted value', () => {
|
|
30
|
+
context.command.revertChanges();
|
|
31
|
+
context.command.someProperty.should.equal('submitted');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -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
|
+
import sinon from 'sinon';
|
|
5
|
+
import { GeneratedCommand } from '../GeneratedCommand.js';
|
|
6
|
+
import { createFetchHelper } from '../../../helpers/fetchHelper.js';
|
|
7
|
+
|
|
8
|
+
for (const value of ['submitted', '', 0, false, null, undefined]) {
|
|
9
|
+
for (const isSuccess of [true, false]) {
|
|
10
|
+
describe(`when executing generated property accessors with ${String(value)} and success is ${isSuccess}`, () => {
|
|
11
|
+
let command: GeneratedCommand;
|
|
12
|
+
let fetchHelper: ReturnType<typeof createFetchHelper>;
|
|
13
|
+
let fetchStub: sinon.SinonStub;
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
command = new GeneratedCommand();
|
|
17
|
+
command.setOrigin('http://localhost');
|
|
18
|
+
command.setInitialValues({ value: 'accepted' });
|
|
19
|
+
command.value = value;
|
|
20
|
+
fetchHelper = createFetchHelper();
|
|
21
|
+
fetchStub = fetchHelper.stubFetch();
|
|
22
|
+
fetchStub.resolves({ status: 200, json: async () => ({ correlationId: '00000000-0000-0000-0000-000000000000', isSuccess, validationResults: [] }) });
|
|
23
|
+
await command.execute();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => fetchHelper.restore());
|
|
27
|
+
|
|
28
|
+
it('should only accept successful submissions as clean', () => command.hasChanges.should.equal(!isSuccess));
|
|
29
|
+
it('should revert to the last accepted value', () => {
|
|
30
|
+
command.value = 'later edit';
|
|
31
|
+
command.revertChanges();
|
|
32
|
+
(command.value === (isSuccess ? value : 'accepted')).should.be.true;
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('when capturing current values through generated property accessors', () => {
|
|
39
|
+
let command: GeneratedCommand;
|
|
40
|
+
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
command = new GeneratedCommand();
|
|
43
|
+
command.value = false;
|
|
44
|
+
command.setInitialValuesFromCurrentValues();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should capture the current value as clean', () => command.hasChanges.should.be.false);
|
|
48
|
+
it('should revert through the setter to the captured value', () => {
|
|
49
|
+
command.value = 'later edit';
|
|
50
|
+
command.revertChanges();
|
|
51
|
+
(command.value === false).should.be.true;
|
|
52
|
+
command.hasChanges.should.be.false;
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -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 { a_command } from '../given/a_command.js';
|
|
5
|
+
import { PropertyDescriptor } from '../../../reflection/PropertyDescriptor.js';
|
|
6
|
+
|
|
7
|
+
for (const value of ['', 0, false, null, undefined]) {
|
|
8
|
+
describe(`when executing with submitted value ${String(value)}`, () => {
|
|
9
|
+
let context: a_command;
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
context = new a_command();
|
|
13
|
+
context.command.propertyDescriptors = [new PropertyDescriptor('someProperty', String, true)];
|
|
14
|
+
context.command.setInitialValues({ someProperty: 'accepted' });
|
|
15
|
+
context.command.someProperty = value as unknown as string;
|
|
16
|
+
context.command.propertyChanged('someProperty');
|
|
17
|
+
context.fetchStub.resolves({ status: 200, json: async () => ({ correlationId: '00000000-0000-0000-0000-000000000000', isSuccess: true, validationResults: [] }) });
|
|
18
|
+
await context.command.execute();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => context.fetchHelper.restore());
|
|
22
|
+
|
|
23
|
+
it('should accept the submitted value as clean', () => context.command.hasChanges.should.be.false);
|
|
24
|
+
it('should revert to the submitted value', () => {
|
|
25
|
+
context.command.someProperty = 'later edit';
|
|
26
|
+
context.command.revertChanges();
|
|
27
|
+
(context.command.someProperty === value).should.be.true;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { SomeCommand } from './SomeCommand.js';
|
|
5
|
+
|
|
6
|
+
for (const value of ['', 0, false, null, undefined, 'missing']) {
|
|
7
|
+
describe(`when setting initial values from current value ${String(value)}`, () => {
|
|
8
|
+
let command: SomeCommand;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
command = new SomeCommand();
|
|
12
|
+
command.setInitialValues({ someProperty: 'accepted' });
|
|
13
|
+
if (value === 'missing') {
|
|
14
|
+
Reflect.deleteProperty(command, 'someProperty');
|
|
15
|
+
} else {
|
|
16
|
+
command.someProperty = value as unknown as string;
|
|
17
|
+
}
|
|
18
|
+
command.setInitialValuesFromCurrentValues();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should mark the current values as clean', () => command.hasChanges.should.be.false);
|
|
22
|
+
it('should revert to the captured value', () => {
|
|
23
|
+
command.someProperty = 'later edit';
|
|
24
|
+
command.revertChanges();
|
|
25
|
+
(command.someProperty === (value === 'missing' ? undefined : value)).should.be.true;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -39,6 +39,7 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
|
|
|
39
39
|
clear(): void;
|
|
40
40
|
setInitialValues(values: TCommandContent): void;
|
|
41
41
|
setInitialValuesFromCurrentValues(): void;
|
|
42
|
+
private captureCurrentValues;
|
|
42
43
|
revertChanges(): void;
|
|
43
44
|
get hasChanges(): boolean;
|
|
44
45
|
propertyChanged(property: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Command.d.ts","sourceRoot":"","sources":["../../../commands/Command.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAInE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAcrF,8BAAsB,OAAO,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,YAAW,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;IA6BzH,QAAQ,CAAC,aAAa,EAAE,WAAW;IAAW,QAAQ,CAAC,yBAAyB,EAAE,OAAO;IAzBrG,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAuB;IAEnE,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO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E9B;IAGD,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAErD;IAGK,OAAO,CAAC,eAAe,CAAC,EAAE,wBAAwB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CA4B5H;IAGK,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CA2BzD;IAGD,kBAAkB,IAAI,aAAa,CAAC,gBAAgB,CAAC,CAwBpD;IAED,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,0BAA0B;IAoBlC,OAAO,CAAC,iCAAiC;IAczC,OAAO,CAAC,YAAY;YAuBN,cAAc;IA+B5B,KAAK,IAAI,IAAI,CAOZ;IAGD,gBAAgB,CAAC,MAAM,EAAE,eAAe,QASvC;IAGD,iCAAiC,SAGhC;IAED,OAAO,CAAC,oBAAoB;IAY5B,aAAa,IAAI,IAAI,CAKpB;IAGD,IAAI,UAAU,YAEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM,QAY/B;IAGD,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,QAK3D;IAED,OAAO,CAAC,gBAAgB;CAM3B"}
|
|
@@ -74,8 +74,12 @@ var ValidationResultReasonDetail = require('../validation/ValidationResultReason
|
|
|
74
74
|
const { route } = UrlHelpers.UrlHelpers.replaceRouteParameters(this.route, payload);
|
|
75
75
|
actualRoute = route;
|
|
76
76
|
}
|
|
77
|
+
const submittedValues = this.captureCurrentValues();
|
|
77
78
|
const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);
|
|
78
|
-
|
|
79
|
+
if (result.isSuccess) {
|
|
80
|
+
this._initialValues = submittedValues;
|
|
81
|
+
this.updateHasChanges();
|
|
82
|
+
}
|
|
79
83
|
return result;
|
|
80
84
|
}
|
|
81
85
|
/** @inheritdoc */ async validate() {
|
|
@@ -228,13 +232,18 @@ var ValidationResultReasonDetail = require('../validation/ValidationResultReason
|
|
|
228
232
|
this.updateHasChanges();
|
|
229
233
|
}
|
|
230
234
|
/** @inheritdoc */ setInitialValuesFromCurrentValues() {
|
|
235
|
+
this._initialValues = this.captureCurrentValues();
|
|
236
|
+
this.updateHasChanges();
|
|
237
|
+
}
|
|
238
|
+
captureCurrentValues() {
|
|
239
|
+
const values = {};
|
|
231
240
|
this.propertyDescriptors.forEach((propertyDescriptor)=>{
|
|
232
241
|
const property = propertyDescriptor.name;
|
|
233
|
-
if (this
|
|
234
|
-
|
|
242
|
+
if (property in this) {
|
|
243
|
+
values[property] = this[property];
|
|
235
244
|
}
|
|
236
245
|
});
|
|
237
|
-
|
|
246
|
+
return values;
|
|
238
247
|
}
|
|
239
248
|
/** @inheritdoc */ revertChanges() {
|
|
240
249
|
this.propertyDescriptors.forEach((propertyDescriptor)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Command.js","sources":["../../../commands/Command.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 { ICommand, PropertyChanged } from './ICommand.js';\nimport { CommandResult } from \"./CommandResult.js\";\nimport { CommandValidator } from './CommandValidator.js';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals.js';\nimport { joinPaths } from '../joinPaths.js';\nimport { UrlHelpers } from '../UrlHelpers.js';\nimport { GetHttpHeaders } from '../GetHttpHeaders.js';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor.js';\nimport { SliceLocation } from '../reflection/SliceLocation.js';\nimport { ValidationResult } from '../validation/ValidationResult.js';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity.js';\nimport { ValidationResultReason } from '../validation/ValidationResultReason.js';\nimport { ValidationResultReasonDetail } from '../validation/ValidationResultReasonDetail.js';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n * Missing required properties produce a {@link ValidationResultReason.Rule} result with\n * {@link ValidationResultReasonDetail.Required}, without contacting the server.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n /**\n * Gets the {@link SliceLocation} of the command. Generated proxies override it with the location resolved from the backend namespace.\n */\n static readonly sliceLocation: SliceLocation = SliceLocation.empty;\n\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n /** Inclusive minimum blocking severity declared by a model-bound command proxy. */\n readonly blockOnValidationSeverity?: ValidationResultSeverity;\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n async execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n actualRoute = `${actualRoute}/validate`;\n const result = await this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n if (result.isSuccess && clientValidationErrors.length > 0) {\n return Object.assign(result, { validationResults: [...result.validationResults, ...clientValidationErrors] });\n }\n return result;\n }\n\n /** @inheritdoc */\n validateClientSide(): CommandResult<TCommandResponse> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n const advisoryResults = [...clientValidationErrors, ...validationErrors];\n if (advisoryResults.length === 0) {\n return CommandResult.empty as CommandResult<TCommandResponse>;\n }\n\n return new CommandResult({\n ...CommandResult.empty,\n correlationId: CommandResult.empty.correlationId.toString(),\n validationResults: advisoryResults,\n response: null\n }, Object, false) as CommandResult<TCommandResponse>;\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null) {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null,\n ValidationResultReason.Rule,\n ValidationResultReasonDetail.Required\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\n if (this.blockOnValidationSeverity !== undefined) {\n const effectiveAllowed = Math.min(allowedSeverity ?? ValidationResultSeverity.Error, this.blockOnValidationSeverity - 1);\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Unknown || result.severity > effectiveAllowed);\n }\n if (ignoreWarnings === true) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n if (allowedSeverity === undefined) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n return validationResults.filter(result => result.severity > allowedSeverity);\n }\n\n private buildHeaders(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n if (allowedSeverity !== undefined) {\n headers['X-Allowed-Severity'] = allowedSeverity.toString();\n }\n\n if (ignoreWarnings === true) {\n headers['X-Ignore-Warnings'] = 'true';\n }\n\n return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string,\n allowedSeverity?: ValidationResultSeverity,\n ignoreWarnings?: boolean\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders(allowedSeverity, ignoreWarnings);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Command","sliceLocation","SliceLocation","empty","_microservice","_apiBasePath","_origin","_httpHeadersCallback","validation","roles","blockOnValidationSeverity","_initialValues","_hasChanges","_callbacks","_responseType","Object","_isResponseTypeEnumerable","Globals","microservice","apiBasePath","origin","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","execute","allowedSeverity","ignoreWarnings","clientValidationErrors","validate","filteredClientErrors","filterValidationResultsBySeverity","length","CommandResult","validationFailed","validationErrors","validateRequiredProperties","filteredRequiredErrors","actualRoute","route","requestParameters","payload","buildPayload","UrlHelpers","replaceRouteParameters","result","performRequest","setInitialValuesFromCurrentValues","isSuccess","assign","validationResults","validateClientSide","advisoryResults","correlationId","toString","response","propertyDescriptors","forEach","propertyDescriptor","property","name","isOptional","includes","value","undefined","push","ValidationResult","ValidationResultSeverity","Error","ValidationResultReason","Rule","ValidationResultReasonDetail","Required","effectiveAllowed","Math","min","filter","severity","Unknown","buildHeaders","customHeaders","headers","microserviceHttpHeader","notFoundMessage","errorMessage","joinPaths","url","createUrlFrom","fetch","method","body","JsonSerializer","serialize","status","failed","json","ex","clear","setInitialValues","values","prototype","hasOwnProperty","call","updateHasChanges","revertChanges","hasChanges","propertyChanged","callbackContainer","deref","thisArg","_","onPropertyChanged","WeakRef","some"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AAsBA;;;;AAIC,IACM,MAAeA,OAAAA,CAAAA;;;AAClB;;AAEC,QACD,OAAgBC,aAAAA,GAA+BC,2BAAAA,CAAcC,KAAK;IAE1DC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;4DAGR,UAASC;AACT,2DACSC,KAAAA,GAAkB,EAAE;wFAE7B,yBAASC;AAIDC,IAAAA,cAAAA,GAAyB,EAAC;AAC1BC,IAAAA,WAAAA,GAAc,KAAA;AACdC,IAAAA,UAAAA,GAAyB,EAAE;AAEnC;;;;AAIC,QACD,YAAY,aAASC,GAA6BC,MAAM,EAAWC,yBAAkC,CAAE;aAAlFF,aAAAA,GAAAA,aAAAA;aAA8CE,yBAAAA,GAAAA,yBAAAA;AAC/D,QAAA,IAAI,CAACZ,aAAa,GAAGa,eAAAA,CAAQC,YAAY,IAAI,EAAA;AAC7C,QAAA,IAAI,CAACb,YAAY,GAAGY,eAAAA,CAAQE,WAAW,IAAI,EAAA;AAC3C,QAAA,IAAI,CAACb,OAAO,GAAGW,eAAAA,CAAQG,MAAM,IAAI,EAAA;AACjC,QAAA,IAAI,CAACb,oBAAoB,GAAG,KAAO,EAAC,CAAA;AACxC,IAAA;uBAGAc,eAAAA,CAAgBH,YAAoB,EAAE;QAClC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GAAKA,CAAAA,CAAEtF,QAAQ,KAAKmF,kBAAkBnF,QAAQ,CAAA;AAC3F,YAAA;AACJ,QAAA,CAAA,CAAA;AACJ,IAAA;AAEA,uBACAuF,iBAAAA,CAAkBvF,QAAyB,EAAEqF,OAAe,EAAE;AAC1D,QAAA,IAAI,CAACjG,UAAU,CAACqD,IAAI,CAAC;AACjBzC,YAAAA,QAAAA,EAAU,IAAIwF,OAAAA,CAAQxF,QAAAA,CAAAA;AACtBqF,YAAAA,OAAAA,EAAS,IAAIG,OAAAA,CAAQH,OAAAA;AACzB,SAAA,CAAA;AACJ,IAAA;IAEQN,gBAAAA,GAAmB;QACvB,IAAI,CAAC5F,WAAW,GAAG,IAAI,CAAC6C,mBAAmB,CAACyD,IAAI,CAACvD,CAAAA,kBAAAA,GAAAA;YAC7C,MAAMC,QAAAA,GAAWD,mBAAmBE,IAAI;YACxC,OAAO,IAAI,CAACD,QAAAA,CAAS,KAAK,IAAI,CAACjD,cAAc,CAACiD,QAAAA,CAAS;AAC3D,QAAA,CAAA,CAAA;AACJ,IAAA;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"Command.js","sources":["../../../commands/Command.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 { ICommand, PropertyChanged } from './ICommand.js';\nimport { CommandResult } from \"./CommandResult.js\";\nimport { CommandValidator } from './CommandValidator.js';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals.js';\nimport { joinPaths } from '../joinPaths.js';\nimport { UrlHelpers } from '../UrlHelpers.js';\nimport { GetHttpHeaders } from '../GetHttpHeaders.js';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor.js';\nimport { SliceLocation } from '../reflection/SliceLocation.js';\nimport { ValidationResult } from '../validation/ValidationResult.js';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity.js';\nimport { ValidationResultReason } from '../validation/ValidationResultReason.js';\nimport { ValidationResultReasonDetail } from '../validation/ValidationResultReasonDetail.js';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n * Missing required properties produce a {@link ValidationResultReason.Rule} result with\n * {@link ValidationResultReasonDetail.Required}, without contacting the server.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n /**\n * Gets the {@link SliceLocation} of the command. Generated proxies override it with the location resolved from the backend namespace.\n */\n static readonly sliceLocation: SliceLocation = SliceLocation.empty;\n\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n /** Inclusive minimum blocking severity declared by a model-bound command proxy. */\n readonly blockOnValidationSeverity?: ValidationResultSeverity;\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n async execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const submittedValues = this.captureCurrentValues();\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);\n if (result.isSuccess) {\n this._initialValues = submittedValues;\n this.updateHasChanges();\n }\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n actualRoute = `${actualRoute}/validate`;\n const result = await this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n if (result.isSuccess && clientValidationErrors.length > 0) {\n return Object.assign(result, { validationResults: [...result.validationResults, ...clientValidationErrors] });\n }\n return result;\n }\n\n /** @inheritdoc */\n validateClientSide(): CommandResult<TCommandResponse> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n const advisoryResults = [...clientValidationErrors, ...validationErrors];\n if (advisoryResults.length === 0) {\n return CommandResult.empty as CommandResult<TCommandResponse>;\n }\n\n return new CommandResult({\n ...CommandResult.empty,\n correlationId: CommandResult.empty.correlationId.toString(),\n validationResults: advisoryResults,\n response: null\n }, Object, false) as CommandResult<TCommandResponse>;\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null) {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null,\n ValidationResultReason.Rule,\n ValidationResultReasonDetail.Required\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\n if (this.blockOnValidationSeverity !== undefined) {\n const effectiveAllowed = Math.min(allowedSeverity ?? ValidationResultSeverity.Error, this.blockOnValidationSeverity - 1);\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Unknown || result.severity > effectiveAllowed);\n }\n if (ignoreWarnings === true) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n if (allowedSeverity === undefined) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n return validationResults.filter(result => result.severity > allowedSeverity);\n }\n\n private buildHeaders(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n if (allowedSeverity !== undefined) {\n headers['X-Allowed-Severity'] = allowedSeverity.toString();\n }\n\n if (ignoreWarnings === true) {\n headers['X-Ignore-Warnings'] = 'true';\n }\n\n return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string,\n allowedSeverity?: ValidationResultSeverity,\n ignoreWarnings?: boolean\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders(allowedSeverity, ignoreWarnings);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this._initialValues = this.captureCurrentValues();\n this.updateHasChanges();\n }\n\n private captureCurrentValues(): object {\n const values = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (property in this) {\n values[property] = this[property];\n }\n });\n return values;\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Command","sliceLocation","SliceLocation","empty","_microservice","_apiBasePath","_origin","_httpHeadersCallback","validation","roles","blockOnValidationSeverity","_initialValues","_hasChanges","_callbacks","_responseType","Object","_isResponseTypeEnumerable","Globals","microservice","apiBasePath","origin","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","execute","allowedSeverity","ignoreWarnings","clientValidationErrors","validate","filteredClientErrors","filterValidationResultsBySeverity","length","CommandResult","validationFailed","validationErrors","validateRequiredProperties","filteredRequiredErrors","actualRoute","route","requestParameters","payload","buildPayload","UrlHelpers","replaceRouteParameters","submittedValues","captureCurrentValues","result","performRequest","isSuccess","updateHasChanges","assign","validationResults","validateClientSide","advisoryResults","correlationId","toString","response","propertyDescriptors","forEach","propertyDescriptor","property","name","isOptional","includes","value","undefined","push","ValidationResult","ValidationResultSeverity","Error","ValidationResultReason","Rule","ValidationResultReasonDetail","Required","effectiveAllowed","Math","min","filter","severity","Unknown","buildHeaders","customHeaders","headers","microserviceHttpHeader","notFoundMessage","errorMessage","joinPaths","url","createUrlFrom","fetch","method","body","JsonSerializer","serialize","status","failed","json","ex","clear","setInitialValues","values","prototype","hasOwnProperty","call","setInitialValuesFromCurrentValues","revertChanges","hasChanges","propertyChanged","callbackContainer","deref","thisArg","_","onPropertyChanged","WeakRef","some"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AAsBA;;;;AAIC,IACM,MAAeA,OAAAA,CAAAA;;;AAClB;;AAEC,QACD,OAAgBC,aAAAA,GAA+BC,2BAAAA,CAAcC,KAAK;IAE1DC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;4DAGR,UAASC;AACT,2DACSC,KAAAA,GAAkB,EAAE;wFAE7B,yBAASC;AAIDC,IAAAA,cAAAA,GAAyB,EAAC;AAC1BC,IAAAA,WAAAA,GAAc,KAAA;AACdC,IAAAA,UAAAA,GAAyB,EAAE;AAEnC;;;;AAIC,QACD,YAAY,aAASC,GAA6BC,MAAM,EAAWC,yBAAkC,CAAE;aAAlFF,aAAAA,GAAAA,aAAAA;aAA8CE,yBAAAA,GAAAA,yBAAAA;AAC/D,QAAA,IAAI,CAACZ,aAAa,GAAGa,eAAAA,CAAQC,YAAY,IAAI,EAAA;AAC7C,QAAA,IAAI,C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Cache {
|
|
|
25
25
|
getLastResult<TDataType>(key: QueryCacheKey): QueryResultWithState<TDataType> | undefined;
|
|
26
26
|
setLastResult<TDataType>(key: QueryCacheKey, result: QueryResultWithState<TDataType>): void;
|
|
27
27
|
private withReconciledData;
|
|
28
|
+
private hasEquivalentMetadata;
|
|
28
29
|
addListener<TDataType>(key: QueryCacheKey, listener: QueryCacheListener<TDataType>): void;
|
|
29
30
|
removeListener<TDataType>(key: QueryCacheKey, listener: QueryCacheListener<TDataType>): void;
|
|
30
31
|
setTeardown(key: QueryCacheKey, teardown: () => void): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryInstanceCache.d.ts","sourceRoot":"","sources":["../../../queries/QueryInstanceCache.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EACR,gBAAgB,EAEnB,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"QueryInstanceCache.d.ts","sourceRoot":"","sources":["../../../queries/QueryInstanceCache.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EACR,gBAAgB,EAEnB,MAAM,yCAAyC,CAAC;AAOjD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAKnC,MAAM,MAAM,kBAAkB,CAAC,SAAS,IAAI,CACxC,MAAM,EAAE,oBAAoB,CAAC,SAAS,CAAC,KACtC,IAAI,CAAC;AAMV,MAAM,WAAW,eAAe,CAAC,SAAS;IAItC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAK3B,UAAU,CAAC,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAK7C,eAAe,EAAE,MAAM,CAAC;IAKxB,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAC;IAMvD,QAAQ,CAAC,EAAE,MAAM,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D,OAAO,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAuBhC;IAOD,GAAG,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAE/B;IAYD,wBAAwB,IAAI,IAAI,CAW/B;IAOD,OAAO,IAAI,IAAI,CAad;IAWD,YAAY,IAAI,IAAI,CASnB;IAQD,oBAAoB,IAAI,IAAI,CAK3B;IAMD,sBAAsB,IAAI,gBAAgB,CAwCzC;CACJ"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var QueryResultWithState = require('./QueryResultWithState.js');
|
|
4
4
|
var reconcileQueryData = require('./reconcileQueryData.js');
|
|
5
|
+
var deepEqual = require('../deepEqual.js');
|
|
5
6
|
|
|
6
7
|
// Copyright (c) Cratis. All rights reserved.
|
|
7
8
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
@@ -112,9 +113,9 @@ var reconcileQueryData = require('./reconcileQueryData.js');
|
|
|
112
113
|
const reconciled = previousResult === undefined ? result : this.withReconciledData(previousResult, result);
|
|
113
114
|
entry.lastResult = reconciled;
|
|
114
115
|
// Reconciliation returns the previous data reference when nothing changed, so identity is
|
|
115
|
-
// enough to detect it. Data
|
|
116
|
+
// enough to detect it. Data and result metadata affect what the user sees; changeSet is
|
|
116
117
|
// ephemeral and does not independently require a notification.
|
|
117
|
-
if (previousResult !== undefined && previousResult.
|
|
118
|
+
if (previousResult !== undefined && previousResult.data === reconciled.data && this.hasEquivalentMetadata(previousResult, reconciled)) {
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
121
|
for (const listener of entry.listeners){
|
|
@@ -135,6 +136,9 @@ var reconcileQueryData = require('./reconcileQueryData.js');
|
|
|
135
136
|
}
|
|
136
137
|
return new QueryResultWithState.QueryResultWithState(reconciledData, next.paging, next.isSuccess, next.isAuthorized, next.isValid, next.validationResults, next.hasExceptions, next.exceptionMessages, next.exceptionStackTrace, next.isPerforming, next.changeSet, next.isReady);
|
|
137
138
|
}
|
|
139
|
+
hasEquivalentMetadata(result, previous) {
|
|
140
|
+
return result.isPerforming === previous.isPerforming && result.isSuccess === previous.isSuccess && result.isReady === previous.isReady && result.isAuthorized === previous.isAuthorized && result.isValid === previous.isValid && result.hasExceptions === previous.hasExceptions && result.exceptionStackTrace === previous.exceptionStackTrace && deepEqual.deepEqual(result.paging, previous.paging) && deepEqual.deepEqual(result.exceptionMessages, previous.exceptionMessages) && deepEqual.deepEqual(result.validationResults, previous.validationResults);
|
|
141
|
+
}
|
|
138
142
|
/**
|
|
139
143
|
* Registers a listener that is invoked whenever the cached result for the given key changes.
|
|
140
144
|
* @template TDataType The type of data returned by the query.
|