@cratis/arc 18.0.5 → 18.1.1
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 +23 -0
- package/commands/CommandResult.ts +21 -0
- package/commands/for_Command/given/a_command.ts +1 -0
- package/commands/for_Command/when_executing/with_custom_http_headers.ts +1 -0
- package/commands/for_Command/when_executing/with_microservice_header.ts +1 -0
- package/commands/for_Command/when_executing/with_missing_required_property.ts +39 -0
- package/commands/for_Command/when_executing/with_origin_and_api_base_path.ts +1 -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 +16 -0
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/cjs/commands/CommandResult.d.ts +1 -0
- package/dist/cjs/commands/CommandResult.d.ts.map +1 -1
- package/dist/cjs/commands/CommandResult.js +19 -0
- package/dist/cjs/commands/CommandResult.js.map +1 -1
- package/dist/cjs/queries/ObservableQueryFor.d.ts.map +1 -1
- package/dist/cjs/queries/ObservableQueryFor.js +9 -2
- package/dist/cjs/queries/ObservableQueryFor.js.map +1 -1
- package/dist/cjs/validation/ValidationResultSeverity.js +10 -0
- package/dist/cjs/validation/ValidationResultSeverity.js.map +1 -0
- 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 +16 -0
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/CommandResult.d.ts +1 -0
- package/dist/esm/commands/CommandResult.d.ts.map +1 -1
- package/dist/esm/commands/CommandResult.js +19 -0
- package/dist/esm/commands/CommandResult.js.map +1 -1
- package/dist/esm/queries/ObservableQueryFor.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryFor.js +9 -2
- package/dist/esm/queries/ObservableQueryFor.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/validation/ValidationResultSeverity.js +4 -2
- package/dist/esm/validation/ValidationResultSeverity.js.map +1 -1
- package/package.json +1 -1
- package/queries/ObservableQueryFor.ts +11 -3
- package/queries/for_ObservableQueryFor/given/TestQueries.ts +24 -0
- package/queries/for_ObservableQueryFor/given/an_observable_query_for.ts +3 -1
- package/queries/for_ObservableQueryFor/when_subscribing/with_route_and_query_args.ts +59 -0
package/commands/Command.ts
CHANGED
|
@@ -10,6 +10,8 @@ import { joinPaths } from '../joinPaths';
|
|
|
10
10
|
import { UrlHelpers } from '../UrlHelpers';
|
|
11
11
|
import { GetHttpHeaders } from '../GetHttpHeaders';
|
|
12
12
|
import { PropertyDescriptor } from '../reflection/PropertyDescriptor';
|
|
13
|
+
import { ValidationResult } from '../validation/ValidationResult';
|
|
14
|
+
import { ValidationResultSeverity } from '../validation/ValidationResultSeverity';
|
|
13
15
|
|
|
14
16
|
type Callback = {
|
|
15
17
|
callback: WeakRef<PropertyChanged>;
|
|
@@ -68,6 +70,11 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
68
70
|
|
|
69
71
|
/** @inheritdoc */
|
|
70
72
|
async execute(): Promise<CommandResult<TCommandResponse>> {
|
|
73
|
+
const validationErrors = this.validateRequiredProperties();
|
|
74
|
+
if (validationErrors.length > 0) {
|
|
75
|
+
return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;
|
|
76
|
+
}
|
|
77
|
+
|
|
71
78
|
let actualRoute = this.route;
|
|
72
79
|
|
|
73
80
|
if (this.requestParameters && this.requestParameters.length > 0) {
|
|
@@ -95,6 +102,22 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
95
102
|
return payload;
|
|
96
103
|
}
|
|
97
104
|
|
|
105
|
+
private validateRequiredProperties(): ValidationResult[] {
|
|
106
|
+
const validationErrors: ValidationResult[] = [];
|
|
107
|
+
this.properties.forEach(property => {
|
|
108
|
+
const value = this[property];
|
|
109
|
+
if (value === undefined || value === null || value === '') {
|
|
110
|
+
validationErrors.push(new ValidationResult(
|
|
111
|
+
ValidationResultSeverity.Error,
|
|
112
|
+
`${property} is required`,
|
|
113
|
+
[property],
|
|
114
|
+
null
|
|
115
|
+
));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return validationErrors;
|
|
119
|
+
}
|
|
120
|
+
|
|
98
121
|
private buildHeaders(): HeadersInit {
|
|
99
122
|
const customHeaders = this._httpHeadersCallback?.() ?? {};
|
|
100
123
|
const headers = {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { Guid } from '@cratis/fundamentals';
|
|
5
5
|
import { ICommandResult } from './ICommandResult';
|
|
6
6
|
import { ValidationResult } from '../validation/ValidationResult';
|
|
7
|
+
import { ValidationResultSeverity } from '../validation/ValidationResultSeverity';
|
|
7
8
|
import { Constructor, JsonSerializer } from '@cratis/fundamentals';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -85,6 +86,26 @@ export class CommandResult<TResponse = object> implements ICommandResult<TRespon
|
|
|
85
86
|
}, Object, false);
|
|
86
87
|
};
|
|
87
88
|
|
|
89
|
+
static validationFailed = (validationResults: ValidationResult[]): CommandResult => {
|
|
90
|
+
return new CommandResult({
|
|
91
|
+
correlationId: Guid.empty.toString(),
|
|
92
|
+
isSuccess: false,
|
|
93
|
+
isAuthorized: true,
|
|
94
|
+
isValid: false,
|
|
95
|
+
hasExceptions: false,
|
|
96
|
+
validationResults: validationResults.map(_ => ({
|
|
97
|
+
severity: _.severity,
|
|
98
|
+
message: _.message,
|
|
99
|
+
members: _.members,
|
|
100
|
+
state: _.state
|
|
101
|
+
})),
|
|
102
|
+
exceptionMessages: [],
|
|
103
|
+
exceptionStackTrace: '',
|
|
104
|
+
authorizationFailureReason: '',
|
|
105
|
+
response: null
|
|
106
|
+
}, Object, false);
|
|
107
|
+
};
|
|
108
|
+
|
|
88
109
|
/** @inheritdoc */
|
|
89
110
|
readonly correlationId: Guid;
|
|
90
111
|
|
|
@@ -14,6 +14,7 @@ describe("when executing with custom http headers", given(class {
|
|
|
14
14
|
this.command.route = '/test-route';
|
|
15
15
|
this.command.setOrigin('http://localhost');
|
|
16
16
|
this.command.setApiBasePath('/api');
|
|
17
|
+
this.command.someProperty = 'test-value';
|
|
17
18
|
this.command.setHttpHeadersCallback(() => ({
|
|
18
19
|
'X-Custom-Header': 'custom-value',
|
|
19
20
|
'Authorization': 'Bearer token123'
|
|
@@ -16,6 +16,7 @@ describe("when executing with microservice header", given(class {
|
|
|
16
16
|
this.command.route = '/test-route';
|
|
17
17
|
this.command.setOrigin('http://localhost');
|
|
18
18
|
this.command.setApiBasePath('/api');
|
|
19
|
+
this.command.someProperty = 'test-value';
|
|
19
20
|
this.command.setMicroservice('my-microservice');
|
|
20
21
|
this.fetchStub = sinon.stub(globalThis, 'fetch');
|
|
21
22
|
this.originalMicroserviceHeader = Globals.microserviceHttpHeader;
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { SomeCommand } from '../SomeCommand';
|
|
6
|
+
import { given } from '../../../given';
|
|
7
|
+
import { CommandResult } from '../../CommandResult';
|
|
8
|
+
|
|
9
|
+
describe("when executing with missing required property", given(class {
|
|
10
|
+
command: SomeCommand;
|
|
11
|
+
fetchStub: sinon.SinonStub;
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
this.command = new SomeCommand();
|
|
15
|
+
this.command.route = '/test-route';
|
|
16
|
+
this.command.setOrigin('http://localhost');
|
|
17
|
+
this.command.setApiBasePath('/api');
|
|
18
|
+
// Intentionally NOT setting someProperty to test validation
|
|
19
|
+
this.fetchStub = sinon.stub(globalThis, 'fetch');
|
|
20
|
+
}
|
|
21
|
+
}, context => {
|
|
22
|
+
let result: CommandResult<object>;
|
|
23
|
+
|
|
24
|
+
beforeEach(async () => {
|
|
25
|
+
result = await context.command.execute();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
context.fetchStub.restore();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should_not_call_fetch", () => context.fetchStub.called.should.be.false);
|
|
33
|
+
it("should_return_failed_result", () => result.isSuccess.should.be.false);
|
|
34
|
+
it("should_return_invalid_result", () => result.isValid.should.be.false);
|
|
35
|
+
it("should_return_authorized_result", () => result.isAuthorized.should.be.true);
|
|
36
|
+
it("should_have_validation_results", () => result.validationResults.length.should.equal(1));
|
|
37
|
+
it("should_have_validation_message_for_property", () => result.validationResults[0].message.should.equal('someProperty is required'));
|
|
38
|
+
it("should_have_validation_member_for_property", () => result.validationResults[0].members[0].should.equal('someProperty'));
|
|
39
|
+
}));
|
|
@@ -14,6 +14,7 @@ describe("when executing with origin and api base path", given(class {
|
|
|
14
14
|
this.command.route = '/items';
|
|
15
15
|
this.command.setOrigin('https://api.example.com');
|
|
16
16
|
this.command.setApiBasePath('/api/v1');
|
|
17
|
+
this.command.someProperty = 'test-value';
|
|
17
18
|
this.fetchStub = sinon.stub(globalThis, 'fetch');
|
|
18
19
|
}
|
|
19
20
|
}, context => {
|
|
@@ -27,6 +27,7 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
|
|
|
27
27
|
execute(): Promise<CommandResult<TCommandResponse>>;
|
|
28
28
|
validate(): Promise<CommandResult<TCommandResponse>>;
|
|
29
29
|
private buildPayload;
|
|
30
|
+
private validateRequiredProperties;
|
|
30
31
|
private buildHeaders;
|
|
31
32
|
private performRequest;
|
|
32
33
|
clear(): 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,YAAY,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,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,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAkB;gBAOf,aAAa,EAAE,WAAW,YAAS,EAAW,yBAAyB,EAAE,OAAO;IAQrG,eAAe,CAAC,YAAY,EAAE,MAAM;IAKpC,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKzC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKhD,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAoBnD,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAK1D,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,0BAA0B;IAgBlC,OAAO,CAAC,YAAY;YAeN,cAAc;IA6B5B,KAAK,IAAI,IAAI;IASb,gBAAgB,CAAC,MAAM,EAAE,eAAe;IAWxC,iCAAiC;IAUjC,aAAa,IAAI,IAAI;IAOrB,IAAI,UAAU,YAEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM;IAehC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;IAO5D,OAAO,CAAC,gBAAgB;CAG3B"}
|
|
@@ -5,6 +5,8 @@ var fundamentals = require('@cratis/fundamentals');
|
|
|
5
5
|
var Globals = require('../Globals.js');
|
|
6
6
|
var joinPaths = require('../joinPaths.js');
|
|
7
7
|
var UrlHelpers = require('../UrlHelpers.js');
|
|
8
|
+
var ValidationResult = require('../validation/ValidationResult.js');
|
|
9
|
+
var ValidationResultSeverity = require('../validation/ValidationResultSeverity.js');
|
|
8
10
|
|
|
9
11
|
class Command {
|
|
10
12
|
_responseType;
|
|
@@ -37,6 +39,10 @@ class Command {
|
|
|
37
39
|
this._httpHeadersCallback = callback;
|
|
38
40
|
}
|
|
39
41
|
async execute() {
|
|
42
|
+
const validationErrors = this.validateRequiredProperties();
|
|
43
|
+
if (validationErrors.length > 0) {
|
|
44
|
+
return CommandResult.CommandResult.validationFailed(validationErrors);
|
|
45
|
+
}
|
|
40
46
|
let actualRoute = this.route;
|
|
41
47
|
if (this.requestParameters && this.requestParameters.length > 0) {
|
|
42
48
|
const payload = this.buildPayload();
|
|
@@ -58,6 +64,16 @@ class Command {
|
|
|
58
64
|
});
|
|
59
65
|
return payload;
|
|
60
66
|
}
|
|
67
|
+
validateRequiredProperties() {
|
|
68
|
+
const validationErrors = [];
|
|
69
|
+
this.properties.forEach(property => {
|
|
70
|
+
const value = this[property];
|
|
71
|
+
if (value === undefined || value === null || value === '') {
|
|
72
|
+
validationErrors.push(new ValidationResult.ValidationResult(ValidationResultSeverity.ValidationResultSeverity.Error, `${property} is required`, [property], null));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return validationErrors;
|
|
76
|
+
}
|
|
61
77
|
buildHeaders() {
|
|
62
78
|
const customHeaders = this._httpHeadersCallback?.() ?? {};
|
|
63
79
|
const headers = {
|
|
@@ -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';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\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 */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n abstract readonly validation: CommandValidator;\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n abstract get properties(): 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 = '';\n this._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(): Promise<CommandResult<TCommandResponse>> {\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');\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const actualRoute = `${this.route}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n private buildPayload(): object {\n const payload = {};\n this.properties.forEach(property => {\n payload[property] = this[property];\n });\n return payload;\n }\n\n private buildHeaders(): 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 return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\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.properties.forEach(property => {\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.properties.forEach(property => {\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.properties.forEach(property => {\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.properties.forEach(property => {\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.properties.some(property => this[property] !== this._initialValues[property]);\n }\n}\n"],"names":["Globals","UrlHelpers","joinPaths","JsonSerializer","CommandResult"],"mappings":";;;;;;;;MAqBsB,OAAO,CAAA;AAoBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AAnB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;IAOpB,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EAAA;QAAhF,IAAA,CAAA,aAAa,GAAb,aAAa;QAAiC,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QACxF,IAAI,CAAC,aAAa,GAAGA,eAAO,CAAC,YAAY,IAAI,EAAE;AAC/C,QAAA,IAAI,CAAC,YAAY,GAAG,EAAE;AACtB,QAAA,IAAI,CAAC,OAAO,GAAG,EAAE;QACjB,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AAChC,QAAA,IAAI,CAAC,aAAa,GAAG,YAAY;IACrC;AAGA,IAAA,cAAc,CAAC,WAAmB,EAAA;AAC9B,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;IACnC;AAGA,IAAA,SAAS,CAAC,MAAc,EAAA;AACpB,QAAA,IAAI,CAAC,OAAO,GAAG,MAAM;IACzB;AAGA,IAAA,sBAAsB,CAAC,QAAwB,EAAA;AAC3C,QAAA,IAAI,CAAC,oBAAoB,GAAG,QAAQ;IACxC;AAGA,IAAA,MAAM,OAAO,GAAA;AACT,QAAA,IAAI,WAAW,GAAG,IAAI,CAAC,KAAK;AAE5B,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AG,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE;AACjD,YAAA,IAAI,QAAQ,IAAI,OAAO,EAAE;AACrB,gBAAA,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;YACpC;iBAAO;gBACH,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,iBAAiB,CAAC,QAAQ,CAAC;YAC5F;AACJ,QAAA,CAAC,CAAC;IACN;IAGA,iBAAiB,CAAC,QAAyB,EAAE,OAAe,EAAA;AACxD,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;AACjB,YAAA,QAAQ,EAAE,IAAI,OAAO,CAAC,QAAQ,CAAC;AAC/B,YAAA,OAAO,EAAE,IAAI,OAAO,CAAC,OAAO;AAC/B,SAAA,CAAC;IACN;IAEQ,gBAAgB,GAAA;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACzG;AACH;;;;"}
|
|
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';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\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 */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n abstract readonly validation: CommandValidator;\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n abstract get properties(): 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 = '';\n this._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(): Promise<CommandResult<TCommandResponse>> {\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) 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');\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const actualRoute = `${this.route}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n private buildPayload(): object {\n const payload = {};\n this.properties.forEach(property => {\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.properties.forEach(property => {\n const value = this[property];\n if (value === undefined || value === null || value === '') {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${property} is required`,\n [property],\n null\n ));\n }\n });\n return validationErrors;\n }\n\n private buildHeaders(): 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 return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\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.properties.forEach(property => {\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.properties.forEach(property => {\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.properties.forEach(property => {\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.properties.forEach(property => {\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.properties.some(property => this[property] !== this._initialValues[property]);\n }\n}\n"],"names":["Globals","CommandResult","UrlHelpers","ValidationResult","ValidationResultSeverity","joinPaths","JsonSerializer"],"mappings":";;;;;;;;;;MAuBsB,OAAO,CAAA;AAoBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AAnB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;IAOpB,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EAAA;QAAhF,IAAA,CAAA,aAAa,GAAb,aAAa;QAAiC,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QACxF,IAAI,CAAC,aAAa,GAAGA,eAAO,CAAC,YAAY,IAAI,EAAE;AAC/C,QAAA,IAAI,CAAC,YAAY,GAAG,EAAE;AACtB,QAAA,IAAI,CAAC,OAAO,GAAG,EAAE;QACjB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,IAAI,OAAO,EAAE;AACrB,gBAAA,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;YACpC;iBAAO;gBACH,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,iBAAiB,CAAC,QAAQ,CAAC;YAC5F;AACJ,QAAA,CAAC,CAAC;IACN;IAGA,iBAAiB,CAAC,QAAyB,EAAE,OAAe,EAAA;AACxD,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;AACjB,YAAA,QAAQ,EAAE,IAAI,OAAO,CAAC,QAAQ,CAAC;AAC/B,YAAA,OAAO,EAAE,IAAI,OAAO,CAAC,OAAO;AAC/B,SAAA,CAAC;IACN;IAEQ,gBAAgB,GAAA;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACzG;AACH;;;;"}
|
|
@@ -27,6 +27,7 @@ type ServerCommandResult = {
|
|
|
27
27
|
export declare class CommandResult<TResponse = object> implements ICommandResult<TResponse> {
|
|
28
28
|
static empty: CommandResult;
|
|
29
29
|
static failed: (exceptionMessages: string[]) => CommandResult;
|
|
30
|
+
static validationFailed: (validationResults: ValidationResult[]) => CommandResult;
|
|
30
31
|
readonly correlationId: Guid;
|
|
31
32
|
readonly isSuccess: boolean;
|
|
32
33
|
readonly isAuthorized: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandResult.d.ts","sourceRoot":"","sources":["../../../commands/CommandResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,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AAC,SAAS,CAAC;CAM/E"}
|
|
@@ -30,6 +30,25 @@ class CommandResult {
|
|
|
30
30
|
response: null
|
|
31
31
|
}, Object, false);
|
|
32
32
|
};
|
|
33
|
+
static validationFailed = (validationResults) => {
|
|
34
|
+
return new CommandResult({
|
|
35
|
+
correlationId: fundamentals.Guid.empty.toString(),
|
|
36
|
+
isSuccess: false,
|
|
37
|
+
isAuthorized: true,
|
|
38
|
+
isValid: false,
|
|
39
|
+
hasExceptions: false,
|
|
40
|
+
validationResults: validationResults.map(_ => ({
|
|
41
|
+
severity: _.severity,
|
|
42
|
+
message: _.message,
|
|
43
|
+
members: _.members,
|
|
44
|
+
state: _.state
|
|
45
|
+
})),
|
|
46
|
+
exceptionMessages: [],
|
|
47
|
+
exceptionStackTrace: '',
|
|
48
|
+
authorizationFailureReason: '',
|
|
49
|
+
response: null
|
|
50
|
+
}, Object, false);
|
|
51
|
+
};
|
|
33
52
|
correlationId;
|
|
34
53
|
isSuccess;
|
|
35
54
|
isAuthorized;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandResult.js","sources":["../../../commands/CommandResult.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 { Guid } from '@cratis/fundamentals';\nimport { ICommandResult } from './ICommandResult';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\n\n/**\n * Delegate type for the onSuccess callback.\n */\ntype OnSuccess = (<TResponse>(response: TResponse) => void) | (() => void);\n\n/**\n * Delegate type for the onFailed callback.\n */\ntype OnFailed<TResponse> = ((commandResult: CommandResult<TResponse>) => void) | (() => void);\n\n/**\n * Delegate type for the onException callback.\n */\ntype OnException = (messages: string[], stackTrace: string) => void;\n\n/**\n * Delegate type for the onUnauthorized callback.\n */\ntype OnUnauthorized = () => void;\n\n/**\n * Delegate type for the onValidationFailure callback.\n */\ntype OnValidationFailure = (validationResults: ValidationResult[]) => void;\n\ntype ServerCommandResult = {\n correlationId: string;\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: {\n severity: number;\n message: string;\n members: string[];\n state: object;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n response: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n}\n\n/**\n * Represents the result from executing a {@link ICommand}.\n */\nexport class CommandResult<TResponse = object> implements ICommandResult<TResponse> {\n\n static empty: CommandResult = new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n\n static failed = (exceptionMessages: string[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: true,\n validationResults: [],\n exceptionMessages: exceptionMessages,\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n /** @inheritdoc */\n readonly correlationId: Guid;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /** @inheritdoc */\n readonly authorizationFailureReason: string;\n\n /** @inheritdoc */\n readonly response?: TResponse;\n\n /**\n * Creates an instance of command result.\n * @param {*} result The JSON/any representation of the command result;\n * @param {Constructor} responseInstanceType The {@see Constructor} that represents the type of response, if any. Defaults to {@see Object}.\n * @param {boolean} isResponseTypeEnumerable Whether or not the response type is an enumerable or not.\n */\n constructor(result: ServerCommandResult, responseInstanceType: Constructor = Object, isResponseTypeEnumerable: boolean) {\n this.correlationId = Guid.parse(result.correlationId);\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n\n if (result.response) {\n if (isResponseTypeEnumerable) {\n this.response = JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response) as TResponse;\n } else {\n this.response = JsonSerializer.deserializeFromInstance(responseInstanceType, result.response) as TResponse;\n }\n }\n }\n\n /**\n * Set up a callback for when the command was successful.\n * @param {OnSuccess} callback The callback to call when the command was successful.\n * @returns {CommandResult} The instance of the command result.\n */\n onSuccess(callback: OnSuccess): CommandResult<TResponse> {\n if (this.isSuccess) {\n callback(this.response as TResponse);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed.\n * @param {OnFailed} callback The callback to call when the command failed.\n * @returns {CommandResult} The instance of the command result.\n */\n onFailed(callback: OnFailed<TResponse>): CommandResult<TResponse> {\n if (!this.isSuccess) {\n callback(this);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed with an exception.\n * @param {OnException} callback The callback to call when the command had an exception.\n * @returns {CommandResult} The instance of the command result.\n */\n onException(callback: OnException): CommandResult<TResponse> {\n if (this.hasExceptions) {\n callback(this.exceptionMessages, this.exceptionStackTrace);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command was unauthorized.\n * @param {OnUnauthorized} callback The callback to call when the command was unauthorized.\n * @returns {CommandResult} The instance of the command result.\n */\n onUnauthorized(callback: OnUnauthorized): CommandResult<TResponse> {\n if (!this.isAuthorized) {\n callback();\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command had validation errors.\n * @param {OnSuccess} callback The callback to call when the command was invalid.\n * @returns {CommandResult} The instance of the command result.\n */\n onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse> {\n if (!this.isValid) {\n callback(this.validationResults);\n }\n return this;\n }\n}\n"],"names":["Guid","ValidationResult","JsonSerializer"],"mappings":";;;;;MAyDa,aAAa,CAAA;AAEtB,IAAA,OAAO,KAAK,GAAkB,IAAI,aAAa,CAAC;AAC5C,QAAA,aAAa,EAAEA,iBAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;AACpC,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,YAAY,EAAE,IAAI;AAClB,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,aAAa,EAAE,KAAK;AACpB,QAAA,iBAAiB,EAAE,EAAE;AACrB,QAAA,iBAAiB,EAAE,EAAE;AACrB,QAAA,mBAAmB,EAAE,EAAE;AACvB,QAAA,0BAA0B,EAAE,EAAE;AAC9B,QAAA,QAAQ,EAAE;AACb,KAAA,EAAE,MAAM,EAAE,KAAK,CAAC;AAEjB,IAAA,OAAO,MAAM,GAAG,CAAC,iBAA2B,KAAmB;QAC3D,OAAO,IAAI,aAAa,CAAC;AACrB,YAAA,aAAa,EAAEA,iBAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;AACpC,YAAA,SAAS,EAAE,KAAK;AAChB,YAAA,YAAY,EAAE,IAAI;AAClB,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,aAAa,EAAE,IAAI;AACnB,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,iBAAiB,EAAE,iBAAiB;AACpC,YAAA,mBAAmB,EAAE,EAAE;AACvB,YAAA,0BAA0B,EAAE,EAAE;AAC9B,YAAA,QAAQ,EAAE;AACb,SAAA,EAAE,MAAM,EAAE,KAAK,CAAC;AACrB,IAAA,CAAC;AAGQ,IAAA,aAAa;AAGb,IAAA,SAAS;AAGT,IAAA,YAAY;AAGZ,IAAA,OAAO;AAGP,IAAA,aAAa;AAGb,IAAA,iBAAiB;AAGjB,IAAA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S,EAAE;AAChB,YAAA,QAAQ,CAAC,IAAI,CAAC,QAAqB,CAAC;QACxC;AACA,QAAA,OAAO,IAAI;IACf;AAOA,IAAA,QAAQ,CAAC,QAA6B,EAAA;AAClC,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACjB,QAAQ,CAAC,IAAI,CAAC;QAClB;AACA,QAAA,OAAO,IAAI;IACf;AAOA,IAAA,WAAW,CAAC,QAAqB,EAAA;AAC7B,QAAA,IAAI,IAAI,CAAC,aAAa,EAAE;YACpB,QAAQ,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,mBAAmB,CAAC;QAC9D;AACA,QAAA,OAAO,IAAI;IACf;AAOA,IAAA,cAAc,CAAC,QAAwB,EAAA;AACnC,QAAA,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;AACpB,YAAA,QAAQ,EAAE;QACd;AACA,QAAA,OAAO,IAAI;IACf;AAOA,IAAA,mBAAmB,CAAC,QAA6B,EAAA;AAC7C,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;AACf,YAAA,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC;QACpC;AACA,QAAA,OAAO,IAAI;IACf;;;;;"}
|
|
1
|
+
{"version":3,"file":"CommandResult.js","sources":["../../../commands/CommandResult.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 { Guid } from '@cratis/fundamentals';\nimport { ICommandResult } from './ICommandResult';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\n\n/**\n * Delegate type for the onSuccess callback.\n */\ntype OnSuccess = (<TResponse>(response: TResponse) => void) | (() => void);\n\n/**\n * Delegate type for the onFailed callback.\n */\ntype OnFailed<TResponse> = ((commandResult: CommandResult<TResponse>) => void) | (() => void);\n\n/**\n * Delegate type for the onException callback.\n */\ntype OnException = (messages: string[], stackTrace: string) => void;\n\n/**\n * Delegate type for the onUnauthorized callback.\n */\ntype OnUnauthorized = () => void;\n\n/**\n * Delegate type for the onValidationFailure callback.\n */\ntype OnValidationFailure = (validationResults: ValidationResult[]) => void;\n\ntype ServerCommandResult = {\n correlationId: string;\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: {\n severity: number;\n message: string;\n members: string[];\n state: object;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n response: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n}\n\n/**\n * Represents the result from executing a {@link ICommand}.\n */\nexport class CommandResult<TResponse = object> implements ICommandResult<TResponse> {\n\n static empty: CommandResult = new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n\n static failed = (exceptionMessages: string[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: true,\n validationResults: [],\n exceptionMessages: exceptionMessages,\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n static validationFailed = (validationResults: ValidationResult[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: validationResults.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n /** @inheritdoc */\n readonly correlationId: Guid;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /** @inheritdoc */\n readonly authorizationFailureReason: string;\n\n /** @inheritdoc */\n readonly response?: TResponse;\n\n /**\n * Creates an instance of command result.\n * @param {*} result The JSON/any representation of the command result;\n * @param {Constructor} responseInstanceType The {@see Constructor} that represents the type of response, if any. Defaults to {@see Object}.\n * @param {boolean} isResponseTypeEnumerable Whether or not the response type is an enumerable or not.\n */\n constructor(result: ServerCommandResult, responseInstanceType: Constructor = Object, isResponseTypeEnumerable: boolean) {\n this.correlationId = Guid.parse(result.correlationId);\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n\n if (result.response) {\n if (isResponseTypeEnumerable) {\n this.response = JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response) as TResponse;\n } else {\n this.response = JsonSerializer.deserializeFromInstance(responseInstanceType, result.response) as TResponse;\n }\n }\n }\n\n /**\n * Set up a callback for when the command was successful.\n * @param {OnSuccess} callback The callback to call when the command was successful.\n * @returns {CommandResult} The instance of the command result.\n */\n onSuccess(callback: OnSuccess): CommandResult<TResponse> {\n if (this.isSuccess) {\n callback(this.response as TResponse);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed.\n * @param {OnFailed} callback The callback to call when the command failed.\n * @returns {CommandResult} The instance of the command result.\n */\n onFailed(callback: OnFailed<TResponse>): CommandResult<TResponse> {\n if (!this.isSuccess) {\n callback(this);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed with an exception.\n * @param {OnException} callback The callback to call when the command had an exception.\n * @returns {CommandResult} The instance of the command result.\n */\n onException(callback: OnException): CommandResult<TResponse> {\n if (this.hasExceptions) {\n callback(this.exceptionMessages, this.exceptionStackTrace);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command was unauthorized.\n * @param {OnUnauthorized} callback The callback to call when the command was unauthorized.\n * @returns {CommandResult} The instance of the command result.\n */\n onUnauthorized(callback: OnUnauthorized): CommandResult<TResponse> {\n if (!this.isAuthorized) {\n callback();\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command had validation errors.\n * @param {OnSuccess} callback The callback to call when the command was invalid.\n * @returns {CommandResult} The instance of the command result.\n */\n onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse> {\n if (!this.isValid) {\n callback(this.validationResults);\n }\n return this;\n }\n}\n"],"names":["Guid","ValidationResult","JsonSerializer"],"mappings":";;;;;MA0Da,aAAa,CAAA;AAEtB,IAAA,OAAO,KAAK,GAAkB,IAAI,aAAa,CAAC;AAC5C,QAAA,aAAa,EAAEA,iBAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;AACpC,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,YAAY,EAAE,IAAI;AAClB,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,aAAa,EAAE,KAAK;AACpB,QAAA,iBAAiB,EAAE,EAAE;AACrB,QAAA,iBAAiB,EAAE,EAAE;AACrB,QAAA,mBAAmB,EAAE,EAAE;AACvB,QAAA,0BAA0B,EAAE,EAAE;AAC9B,QAAA,QAAQ,EAAE;AACb,KAAA,EAAE,MAAM,EAAE,KAAK,CAAC;AAEjB,IAAA,OAAO,MAAM,GAAG,CAAC,iBAA2B,KAAmB;QAC3D,OAAO,IAAI,aAAa,CAAC;AACrB,YAAA,aAAa,EAAEA,iBAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;AACpC,YAAA,SAAS,EAAE,KAAK;AAChB,YAAA,YAAY,EAAE,IAA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AAE,WAAW,GAAG,2BAA2B,CAAC,SAAS,CAAC;IAqC/G,OAAO,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAyDlE,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,0BAA0B;IAsBlC,OAAO,CAAC,iBAAiB;CAW5B"}
|
|
@@ -50,7 +50,6 @@ class ObservableQueryFor {
|
|
|
50
50
|
this._httpHeadersCallback = callback;
|
|
51
51
|
}
|
|
52
52
|
subscribe(callback, args) {
|
|
53
|
-
const connectionQueryArguments = this.buildQueryArguments();
|
|
54
53
|
if (this._connection) {
|
|
55
54
|
this._connection.disconnect();
|
|
56
55
|
}
|
|
@@ -58,10 +57,18 @@ class ObservableQueryFor {
|
|
|
58
57
|
this._connection = new NullObservableQueryConnection.NullObservableQueryConnection(this.defaultValue);
|
|
59
58
|
}
|
|
60
59
|
else {
|
|
61
|
-
const
|
|
60
|
+
const { route } = UrlHelpers.UrlHelpers.replaceRouteParameters(this.route, args);
|
|
61
|
+
const actualRoute = joinPaths.joinPaths(this._apiBasePath, route);
|
|
62
62
|
const url = UrlHelpers.UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);
|
|
63
63
|
this._connection = new ObservableQueryConnection.ObservableQueryConnection(url, this._microservice);
|
|
64
64
|
}
|
|
65
|
+
const parameterValues = ParametersHelper.ParametersHelper.collectParameterValues(this);
|
|
66
|
+
const { unusedParameters } = UrlHelpers.UrlHelpers.replaceRouteParameters(this.route, args);
|
|
67
|
+
const connectionQueryArguments = {
|
|
68
|
+
...unusedParameters,
|
|
69
|
+
...parameterValues,
|
|
70
|
+
...this.buildQueryArguments()
|
|
71
|
+
};
|
|
65
72
|
const subscriber = new ObservableQuerySubscription.ObservableQuerySubscription(this._connection);
|
|
66
73
|
this._connection.connect(data => {
|
|
67
74
|
const result = data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryFor.js","sources":["../../../queries/ObservableQueryFor.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 { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';\nimport { ObservableQueryConnection } from './ObservableQueryConnection';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\nimport { Constructor } from '@cratis/fundamentals';\nimport { JsonSerializer } from '@cratis/fundamentals';\nimport { QueryResult } from './QueryResult';\nimport { Sorting } from './Sorting';\nimport { Paging } from './Paging';\nimport { SortDirection } from './SortDirection';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class ObservableQueryFor<TDataType, TParameters = object> implements IObservableQueryFor<TDataType, TParameters> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _connection?: IObservableQueryConnection<TDataType>;\n private _httpHeadersCallback: GetHttpHeaders;\n\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n sorting: Sorting;\n paging: Paging;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryFor<,>}} class.\n * @param modelType Type of model, if an enumerable, this is the instance type.\n * @param enumerable Whether or not it is an enumerable.\n */\n constructor(readonly modelType: Constructor, readonly enumerable: boolean) {\n this.sorting = Sorting.none;\n this.paging = Paging.noPaging;\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = '';\n this._origin = '';\n this._httpHeadersCallback = () => ({});\n }\n\n /**\n * Disposes the query.\n */\n dispose() {\n this._connection?.disconnect();\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 subscribe(callback: OnNextResult<QueryResult<TDataType>>, args?: TParameters): ObservableQuerySubscription<TDataType> {\n const connectionQueryArguments: any = this.buildQueryArguments();\n\n if (this._connection) {\n this._connection.disconnect();\n }\n\n if (!this.validateArguments(args)) {\n this._connection = new NullObservableQueryConnection(this.defaultValue);\n } else {\n const actualRoute = this.buildRoute(args);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n this._connection = new ObservableQueryConnection<TDataType>(url, this._microservice);\n }\n\n const subscriber = new ObservableQuerySubscription(this._connection);\n this._connection.connect(data => {\n const result: any = data;\n try {\n this.deserializeResult(result);\n callback(result);\n } catch (ex) {\n console.log(ex);\n }\n }, connectionQueryArguments);\n return subscriber;\n }\n\n /** @inheritdoc */\n async perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n if (!this.validateArguments(args)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n const { route, unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n let actualRoute = joinPaths(this._apiBasePath, route);\n \n const additionalParams: Record<string, string | number> = {};\n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const queryParams = UrlHelpers.buildQueryParams({ ...unusedParameters, ...parameterValues }, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n actualRoute += (actualRoute.includes('?') ? '&' : '?') + queryString;\n }\n\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n const headers = {\n ...(this._httpHeadersCallback?.() || {}),\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 const response = await fetch(url, {\n method: 'GET',\n headers\n });\n\n try {\n const result = await response.json();\n return new QueryResult(result, this.modelType, this.enumerable);\n } catch {\n return noSuccess;\n }\n }\n\n private validateArguments(args?: TParameters): boolean {\n return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args as object);\n }\n\n private buildRoute(args?: TParameters): string {\n const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n return actualRoute;\n }\n\n private buildQueryArguments(): any {\n const queryArguments: any = {};\n\n if (this.paging && this.paging.pageSize > 0) {\n queryArguments.pageSize = this.paging.pageSize;\n queryArguments.page = this.paging.page;\n }\n\n if (this.sorting.hasSorting) {\n queryArguments.sortBy = this.sorting.field;\n queryArguments.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n return queryArguments;\n }\n\n private addPagingAndSortingToRoute(route: string): string {\n const additionalParams: Record<string, string | number> = {};\n \n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n const queryParams = UrlHelpers.buildQueryParams({}, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n route += '?' + queryString;\n }\n \n return route;\n }\n\n private deserializeResult(result: any): void {\n if (this.enumerable) {\n if (Array.isArray(result.data)) {\n result.data = JsonSerializer.deserializeArrayFromInstance(this.modelType, result.data);\n } else {\n result.data = [];\n }\n } else {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":["Sorting","Paging","Globals","NullObservableQueryConnection","UrlHelpers","ObservableQueryConnection","ObservableQuerySubscription","QueryResult","joinPaths","SortDirection","ParametersHelper","ValidateRequestArguments","JsonSerializer"],"mappings":";;;;;;;;;;;;;;;;MA4BsB,kBAAkB,CAAA;AAmBf,IAAA,SAAA;AAAiC,IAAA,UAAA;AAlB9C,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,WAAW;AACX,IAAA,oBAAoB;AAM5B,IAAA,OAAO;AACP,IAAA,MAAM;IAON,WAAA,CAAqB,SAAsB,EAAW,UAAmB,EAAA;QAApD,IAAA,CAAA,SAAS,GAAT,SAAS;QAAwB,IAAA,CAAA,UAAU,GAAV,UAAU;AAC5D,QAAA,IAAI,CAAC,OAAO,GAAGA,eAAO,CAAC,IAAI;AAC3B,QAAA,IAAI,CAAC,MAAM,GAAGC,aAAM,CAAC,QAAQ;QAC7B,IAAI,CAAC,aAAa,GAAGC,eAAO,CAAC,YAAY,IAAI,EAAE;AAC/C,QAAA,IAAI,CAAC,YAAY,GAAG,EAAE;AACtB,QAAA,IAAI,CAAC,OAAO,GAAG,EAAE;QACjB,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;IAKA,OAAO,GAAA;AACH,QAAA,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE;IAClC;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AAChC,QA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AG,KAAK;QAC3G;QAEA,MAAM,WAAW,GAAGL,qBAAU,CAAC,gBAAgB,CAAC,EAAE,EAAE,gBAAgB,CAAC;AACrE,QAAA,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,EAAE;QAC1C,IAAI,WAAW,EAAE;AACb,YAAA,KAAK,IAAI,GAAG,GAAG,WAAW;QAC9B;AAEA,QAAA,OAAO,KAAK;IAChB;AAEQ,IAAA,iBAAiB,CAAC,MAAW,EAAA;AACjC,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;AAC5B,gBAAA,MAAM,CAAC,IAAI,GAAGQ,2BAAc,CAAC,4BAA4B,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;YAC1F;iBAAO;AACH,gBAAA,MAAM,CAAC,IAAI,GAAG,EAAE;YACpB;QACJ;aAAO;AACH,YAAA,MAAM,CAAC,IAAI,GAAGA,2BAAc,CAAC,uBAAuB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;QACrF;IACJ;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"ObservableQueryFor.js","sources":["../../../queries/ObservableQueryFor.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 { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';\nimport { ObservableQueryConnection } from './ObservableQueryConnection';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\nimport { Constructor } from '@cratis/fundamentals';\nimport { JsonSerializer } from '@cratis/fundamentals';\nimport { QueryResult } from './QueryResult';\nimport { Sorting } from './Sorting';\nimport { Paging } from './Paging';\nimport { SortDirection } from './SortDirection';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class ObservableQueryFor<TDataType, TParameters = object> implements IObservableQueryFor<TDataType, TParameters> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _connection?: IObservableQueryConnection<TDataType>;\n private _httpHeadersCallback: GetHttpHeaders;\n\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n sorting: Sorting;\n paging: Paging;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryFor<,>}} class.\n * @param modelType Type of model, if an enumerable, this is the instance type.\n * @param enumerable Whether or not it is an enumerable.\n */\n constructor(readonly modelType: Constructor, readonly enumerable: boolean) {\n this.sorting = Sorting.none;\n this.paging = Paging.noPaging;\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = '';\n this._origin = '';\n this._httpHeadersCallback = () => ({});\n }\n\n /**\n * Disposes the query.\n */\n dispose() {\n this._connection?.disconnect();\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 subscribe(callback: OnNextResult<QueryResult<TDataType>>, args?: TParameters): ObservableQuerySubscription<TDataType> {\n if (this._connection) {\n this._connection.disconnect();\n }\n\n if (!this.validateArguments(args)) {\n this._connection = new NullObservableQueryConnection(this.defaultValue);\n } else {\n const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n this._connection = new ObservableQueryConnection<TDataType>(url, this._microservice);\n }\n\n // Build query arguments including unused args parameters, parameter descriptor values, and paging/sorting\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...unusedParameters,\n ...parameterValues,\n ...this.buildQueryArguments()\n };\n\n const subscriber = new ObservableQuerySubscription(this._connection);\n this._connection.connect(data => {\n const result: any = data;\n try {\n this.deserializeResult(result);\n callback(result);\n } catch (ex) {\n console.log(ex);\n }\n }, connectionQueryArguments);\n return subscriber;\n }\n\n /** @inheritdoc */\n async perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n if (!this.validateArguments(args)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n const { route, unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n let actualRoute = joinPaths(this._apiBasePath, route);\n \n const additionalParams: Record<string, string | number> = {};\n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const queryParams = UrlHelpers.buildQueryParams({ ...unusedParameters, ...parameterValues }, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n actualRoute += (actualRoute.includes('?') ? '&' : '?') + queryString;\n }\n\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n const headers = {\n ...(this._httpHeadersCallback?.() || {}),\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 const response = await fetch(url, {\n method: 'GET',\n headers\n });\n\n try {\n const result = await response.json();\n return new QueryResult(result, this.modelType, this.enumerable);\n } catch {\n return noSuccess;\n }\n }\n\n private validateArguments(args?: TParameters): boolean {\n return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args as object);\n }\n\n private buildRoute(args?: TParameters): string {\n const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n return actualRoute;\n }\n\n private buildQueryArguments(): any {\n const queryArguments: any = {};\n\n if (this.paging && this.paging.pageSize > 0) {\n queryArguments.pageSize = this.paging.pageSize;\n queryArguments.page = this.paging.page;\n }\n\n if (this.sorting.hasSorting) {\n queryArguments.sortBy = this.sorting.field;\n queryArguments.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n return queryArguments;\n }\n\n private addPagingAndSortingToRoute(route: string): string {\n const additionalParams: Record<string, string | number> = {};\n \n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n const queryParams = UrlHelpers.buildQueryParams({}, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n route += '?' + queryString;\n }\n \n return route;\n }\n\n private deserializeResult(result: any): void {\n if (this.enumerable) {\n if (Array.isArray(result.data)) {\n result.data = JsonSerializer.deserializeArrayFromInstance(this.modelType, result.data);\n } else {\n result.data = [];\n }\n } else {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":["Sorting","Paging","Globals","NullObservableQueryConnection","UrlHelpers","joinPaths","ObservableQueryConnection","ParametersHelper","ObservableQuerySubscription","QueryResult","SortDirection","ValidateRequestArguments","JsonSerializer"],"mappings":";;;;;;;;;;;;;;;;MA4BsB,kBAAkB,CAAA;AAmBf,IAAA,SAAA;AAAiC,IAAA,UAAA;AAlB9C,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,WAAW;AACX,IAAA,oBAAoB;AAM5B,IAAA,OAAO;AACP,IAAA,MAAM;IAON,WAAA,CAAqB,SAAsB,EAAW,UAAmB,EAAA;QAApD,IAAA,CAAA,SAAS,GAAT,SAAS;QAAwB,IAAA,CAAA,UAAU,GAAV,UAAU;AAC5D,QAAA,IAAI,CAAC,OAAO,GAAGA,eAAO,CAAC,IAAI;AAC3B,QAAA,IAAI,CAAC,MAAM,GAAGC,aAAM,CAAC,QAAQ;QAC7B,IAAI,CAAC,aAAa,GAAGC,eAAO,CAAC,YAAY,IAAI,EAAE;AAC/C,QAAA,IAAI,CAAC,YAAY,GAAG,EAAE;AACtB,QAAA,IAAI,CAAC,OAAO,GAAG,EAAE;QACjB,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;IAKA,OAAO,GAAA;AACH,QAAA,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE;IAClC;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AAChC,QAAA,IAAI,CAAC,aAAa,GAAG,YAAY;IACrC;AAGA,IAAA,cAAc,CAAC,WAAmB,EAAA;AAC9B,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;IACnC;AAGA,IAAA,SAAS,CAAC,MAAc,EAAA;AACpB,QAAA,IAAI,CAAC,OAAO,GAAG,MAAM;IACzB;AAGA,IAAA,sBAAsB,CAAC,QAAwB,EAAA;AAC3C,QAAA,IAAI,CAAC,oBAAoB,GAAG,QAAQ;IACxC;IAGA,SAAS,C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S,KAAKA,2BAAa,CAAC,UAAU,IAAI,MAAM,GAAG,KAAK;QAC3G;QAEA,MAAM,WAAW,GAAGN,qBAAU,CAAC,gBAAgB,CAAC,EAAE,EAAE,gBAAgB,CAAC;AACrE,QAAA,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,EAAE;QAC1C,IAAI,WAAW,EAAE;AACb,YAAA,KAAK,IAAI,GAAG,GAAG,WAAW;QAC9B;AAEA,QAAA,OAAO,KAAK;IAChB;AAEQ,IAAA,iBAAiB,CAAC,MAAW,EAAA;AACjC,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;AAC5B,gBAAA,MAAM,CAAC,IAAI,GAAGQ,2BAAc,CAAC,4BAA4B,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;YAC1F;iBAAO;AACH,gBAAA,MAAM,CAAC,IAAI,GAAG,EAAE;YACpB;QACJ;aAAO;AACH,YAAA,MAAM,CAAC,IAAI,GAAGA,2BAAc,CAAC,uBAAuB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;QACrF;IACJ;AACH;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.ValidationResultSeverity = void 0;
|
|
4
|
+
(function (ValidationResultSeverity) {
|
|
5
|
+
ValidationResultSeverity[ValidationResultSeverity["Unknown"] = 0] = "Unknown";
|
|
6
|
+
ValidationResultSeverity[ValidationResultSeverity["Information"] = 1] = "Information";
|
|
7
|
+
ValidationResultSeverity[ValidationResultSeverity["Warning"] = 2] = "Warning";
|
|
8
|
+
ValidationResultSeverity[ValidationResultSeverity["Error"] = 3] = "Error";
|
|
9
|
+
})(exports.ValidationResultSeverity || (exports.ValidationResultSeverity = {}));
|
|
10
|
+
//# sourceMappingURL=ValidationResultSeverity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationResultSeverity.js","sources":["../../../validation/ValidationResultSeverity.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Holds the values for severity of a validation result.\n */\nexport enum ValidationResultSeverity {\n\n /**\n * The validation result is unknown.\n */\n Unknown = 0,\n\n /**\n * The validation result is a warning.\n */\n Information = 1,\n\n /**\n * The validation result is a warning.\n */\n Warning = 2,\n\n /**\n * The validation result is an error.\n */\n Error = 3\n}\n"],"names":["ValidationResultSeverity"],"mappings":";;AAMYA;AAAZ,CAAA,UAAY,wBAAwB,EAAA;AAKhC,IAAA,wBAAA,CAAA,wBAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAW;AAKX,IAAA,wBAAA,CAAA,wBAAA,CAAA,aAAA,CAAA,GAAA,CAAA,CAAA,GAAA,aAAe;AAKf,IAAA,wBAAA,CAAA,wBAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAW;AAKX,IAAA,wBAAA,CAAA,wBAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAS;AACb,CAAC,EArBWA,gCAAwB,KAAxBA,gCAAwB,GAAA,EAAA,CAAA,CAAA;;"}
|
|
@@ -27,6 +27,7 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
|
|
|
27
27
|
execute(): Promise<CommandResult<TCommandResponse>>;
|
|
28
28
|
validate(): Promise<CommandResult<TCommandResponse>>;
|
|
29
29
|
private buildPayload;
|
|
30
|
+
private validateRequiredProperties;
|
|
30
31
|
private buildHeaders;
|
|
31
32
|
private performRequest;
|
|
32
33
|
clear(): 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,YAAY,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C;IAC3C,QAAQ,KAAK,UAAU,IAAI,MAAM,EAAE,CAAC;IAEpC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAkB;gBAOf,aAAa,EAAE,WAAW,YAAS,EAAW,yBAAyB,EAAE,OAAO;IAQrG,eAAe,CAAC,YAAY,EAAE,MAAM;IAKpC,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKzC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKhD,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAoBnD,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAK1D,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,0BAA0B;IAgBlC,OAAO,CAAC,YAAY;YAeN,cAAc;IA6B5B,KAAK,IAAI,IAAI;IASb,gBAAgB,CAAC,MAAM,EAAE,eAAe;IAWxC,iCAAiC;IAUjC,aAAa,IAAI,IAAI;IAOrB,IAAI,UAAU,YAEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM;IAehC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;IAO5D,OAAO,CAAC,gBAAgB;CAG3B"}
|
|
@@ -3,6 +3,8 @@ import { JsonSerializer } from '@cratis/fundamentals';
|
|
|
3
3
|
import { Globals } from '../Globals.js';
|
|
4
4
|
import { joinPaths } from '../joinPaths.js';
|
|
5
5
|
import { UrlHelpers } from '../UrlHelpers.js';
|
|
6
|
+
import { ValidationResult } from '../validation/ValidationResult.js';
|
|
7
|
+
import { ValidationResultSeverity } from '../validation/ValidationResultSeverity.js';
|
|
6
8
|
|
|
7
9
|
class Command {
|
|
8
10
|
_responseType;
|
|
@@ -35,6 +37,10 @@ class Command {
|
|
|
35
37
|
this._httpHeadersCallback = callback;
|
|
36
38
|
}
|
|
37
39
|
async execute() {
|
|
40
|
+
const validationErrors = this.validateRequiredProperties();
|
|
41
|
+
if (validationErrors.length > 0) {
|
|
42
|
+
return CommandResult.validationFailed(validationErrors);
|
|
43
|
+
}
|
|
38
44
|
let actualRoute = this.route;
|
|
39
45
|
if (this.requestParameters && this.requestParameters.length > 0) {
|
|
40
46
|
const payload = this.buildPayload();
|
|
@@ -56,6 +62,16 @@ class Command {
|
|
|
56
62
|
});
|
|
57
63
|
return payload;
|
|
58
64
|
}
|
|
65
|
+
validateRequiredProperties() {
|
|
66
|
+
const validationErrors = [];
|
|
67
|
+
this.properties.forEach(property => {
|
|
68
|
+
const value = this[property];
|
|
69
|
+
if (value === undefined || value === null || value === '') {
|
|
70
|
+
validationErrors.push(new ValidationResult(ValidationResultSeverity.Error, `${property} is required`, [property], null));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return validationErrors;
|
|
74
|
+
}
|
|
59
75
|
buildHeaders() {
|
|
60
76
|
const customHeaders = this._httpHeadersCallback?.() ?? {};
|
|
61
77
|
const headers = {
|