@cratis/arc 19.9.7 → 19.10.5
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 +1 -0
- package/commands/ICommand.ts +5 -0
- package/commands/for_Command/when_executing/with_allowed_severity_warning.ts +0 -1
- 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 +1 -0
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/cjs/commands/ICommand.d.ts +1 -0
- package/dist/cjs/commands/ICommand.d.ts.map +1 -1
- package/dist/cjs/queries/IObservableQueryFor.d.ts +1 -0
- package/dist/cjs/queries/IObservableQueryFor.d.ts.map +1 -1
- package/dist/cjs/queries/IQueryFor.d.ts +1 -0
- package/dist/cjs/queries/IQueryFor.d.ts.map +1 -1
- package/dist/cjs/queries/ObservableQueryFor.d.ts +1 -0
- package/dist/cjs/queries/ObservableQueryFor.d.ts.map +1 -1
- package/dist/cjs/queries/ObservableQueryFor.js +1 -0
- package/dist/cjs/queries/ObservableQueryFor.js.map +1 -1
- package/dist/cjs/queries/QueryFor.d.ts +1 -0
- package/dist/cjs/queries/QueryFor.d.ts.map +1 -1
- package/dist/cjs/queries/QueryFor.js +1 -0
- package/dist/cjs/queries/QueryFor.js.map +1 -1
- package/dist/cjs/queries/for_ObservableQueryFor/given/TestQueries.d.ts +11 -0
- package/dist/cjs/queries/for_ObservableQueryFor/given/TestQueries.d.ts.map +1 -1
- package/dist/cjs/queries/for_ObservableQueryFor/given/an_observable_query_for.d.ts +2 -1
- package/dist/cjs/queries/for_ObservableQueryFor/given/an_observable_query_for.d.ts.map +1 -1
- package/dist/cjs/queries/for_ObservableQueryFor/when_performing/with_partially_missing_required_arguments.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryFor/when_performing/with_partially_missing_required_arguments.d.ts.map +1 -0
- package/dist/cjs/queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.d.ts +2 -0
- package/dist/cjs/queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryFor/given/TestQueries.d.ts +11 -0
- package/dist/cjs/queries/for_QueryFor/given/TestQueries.d.ts.map +1 -1
- package/dist/cjs/queries/for_QueryFor/given/a_query_for.d.ts +2 -1
- package/dist/cjs/queries/for_QueryFor/given/a_query_for.d.ts.map +1 -1
- package/dist/cjs/queries/for_QueryFor/when_performing/with_partially_missing_required_arguments.d.ts +2 -0
- package/dist/cjs/queries/for_QueryFor/when_performing/with_partially_missing_required_arguments.d.ts.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 +1 -0
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/ICommand.d.ts +1 -0
- package/dist/esm/commands/ICommand.d.ts.map +1 -1
- package/dist/esm/commands/for_Command/when_executing/with_allowed_severity_warning.js.map +1 -1
- package/dist/esm/queries/IObservableQueryFor.d.ts +1 -0
- package/dist/esm/queries/IObservableQueryFor.d.ts.map +1 -1
- package/dist/esm/queries/IQueryFor.d.ts +1 -0
- package/dist/esm/queries/IQueryFor.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryFor.d.ts +1 -0
- package/dist/esm/queries/ObservableQueryFor.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryFor.js +1 -0
- package/dist/esm/queries/ObservableQueryFor.js.map +1 -1
- package/dist/esm/queries/QueryFor.d.ts +1 -0
- package/dist/esm/queries/QueryFor.d.ts.map +1 -1
- package/dist/esm/queries/QueryFor.js +1 -0
- package/dist/esm/queries/QueryFor.js.map +1 -1
- package/dist/esm/queries/for_ObservableQueryFor/given/TestQueries.d.ts +11 -0
- package/dist/esm/queries/for_ObservableQueryFor/given/TestQueries.d.ts.map +1 -1
- package/dist/esm/queries/for_ObservableQueryFor/given/TestQueries.js +14 -0
- package/dist/esm/queries/for_ObservableQueryFor/given/TestQueries.js.map +1 -1
- package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_for.d.ts +2 -1
- package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_for.d.ts.map +1 -1
- package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_for.js +3 -1
- package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_for.js.map +1 -1
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_partially_missing_required_arguments.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_partially_missing_required_arguments.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_partially_missing_required_arguments.js +35 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_partially_missing_required_arguments.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.js +41 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.js.map +1 -0
- package/dist/esm/queries/for_QueryFor/given/TestQueries.d.ts +11 -0
- package/dist/esm/queries/for_QueryFor/given/TestQueries.d.ts.map +1 -1
- package/dist/esm/queries/for_QueryFor/given/TestQueries.js +14 -0
- package/dist/esm/queries/for_QueryFor/given/TestQueries.js.map +1 -1
- package/dist/esm/queries/for_QueryFor/given/a_query_for.d.ts +2 -1
- package/dist/esm/queries/for_QueryFor/given/a_query_for.d.ts.map +1 -1
- package/dist/esm/queries/for_QueryFor/given/a_query_for.js +3 -1
- package/dist/esm/queries/for_QueryFor/given/a_query_for.js.map +1 -1
- package/dist/esm/queries/for_QueryFor/when_performing/with_partially_missing_required_arguments.d.ts +2 -0
- package/dist/esm/queries/for_QueryFor/when_performing/with_partially_missing_required_arguments.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryFor/when_performing/with_partially_missing_required_arguments.js +35 -0
- package/dist/esm/queries/for_QueryFor/when_performing/with_partially_missing_required_arguments.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/queries/IObservableQueryFor.ts +5 -0
- package/queries/IQueryFor.ts +5 -0
- package/queries/ObservableQueryFor.ts +1 -0
- package/queries/QueryFor.ts +1 -0
- package/queries/for_ObservableQueryFor/given/TestQueries.ts +22 -0
- package/queries/for_ObservableQueryFor/given/an_observable_query_for.ts +9 -1
- package/queries/for_ObservableQueryFor/when_performing/with_partially_missing_required_arguments.ts +45 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.ts +52 -0
- package/queries/for_QueryFor/given/TestQueries.ts +22 -0
- package/queries/for_QueryFor/given/a_query_for.ts +9 -1
- package/queries/for_QueryFor/when_performing/with_partially_missing_required_arguments.ts +45 -0
package/commands/Command.ts
CHANGED
|
@@ -30,6 +30,7 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
30
30
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
31
31
|
readonly validation?: CommandValidator<any>;
|
|
32
32
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
33
|
+
readonly roles: string[] = [];
|
|
33
34
|
abstract readonly propertyDescriptors: PropertyDescriptor[];
|
|
34
35
|
abstract get requestParameters(): string[];
|
|
35
36
|
|
package/commands/ICommand.ts
CHANGED
|
@@ -20,6 +20,11 @@ export interface ICommand<TCommandContent = object, TCommandResponse = object> e
|
|
|
20
20
|
*/
|
|
21
21
|
readonly route: string;
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Gets the roles required to execute the command. An empty array means no specific roles are required.
|
|
25
|
+
*/
|
|
26
|
+
readonly roles: string[];
|
|
27
|
+
|
|
23
28
|
/**
|
|
24
29
|
* Gets the property descriptors for the command.
|
|
25
30
|
*/
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { given } from '../../../given';
|
|
5
5
|
import { a_command } from '../given/a_command';
|
|
6
6
|
import { ValidationResultSeverity } from '../../../validation/ValidationResultSeverity';
|
|
7
|
-
import { CommandResult } from '../../CommandResult';
|
|
8
7
|
|
|
9
8
|
describe("when executing with allowed severity warning", given(class extends a_command {
|
|
10
9
|
constructor() {
|
|
@@ -14,6 +14,7 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
|
|
|
14
14
|
private _httpHeadersCallback;
|
|
15
15
|
abstract readonly route: string;
|
|
16
16
|
readonly validation?: CommandValidator<any>;
|
|
17
|
+
readonly roles: string[];
|
|
17
18
|
abstract readonly propertyDescriptors: PropertyDescriptor[];
|
|
18
19
|
abstract get requestParameters(): string[];
|
|
19
20
|
private _initialValues;
|
|
@@ -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,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAInE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAUlF,8BAAsB,OAAO,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,YAAW,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Command.d.ts","sourceRoot":"","sources":["../../../commands/Command.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,eAAe,EA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AE,MAAM,GAAG,IAAI;IAK/B,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKhD,OAAO,CAAC,eAAe,CAAC,EAAE,wBAAwB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IA2BvH,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAuB1D,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,0BAA0B;IAkBlC,OAAO,CAAC,iCAAiC;IAUzC,OAAO,CAAC,YAAY;YAuBN,cAAc;IA+B5B,KAAK,IAAI,IAAI;IAUb,gBAAgB,CAAC,MAAM,EAAE,eAAe;IAYxC,iCAAiC;IAWjC,aAAa,IAAI,IAAI;IAQrB,IAAI,UAAU,YAEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM;IAehC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;IAO5D,OAAO,CAAC,gBAAgB;CAM3B"}
|
|
@@ -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';\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 /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\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 if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\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 actualRoute = `${actualRoute}/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.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 || value === '') {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\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":["Globals","CommandResult","UrlHelpers","ValidationResult","ValidationResultSeverity","joinPaths","JsonSerializer"],"mappings":";;;;;;;;;;MAuBsB,OAAO,CAAA;AAqBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AApB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAKX,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EAAA;QAAhF,IAA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AEvB,QAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,iBAAiB,IAAG;YACxC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,QAAQ,CAAC,KAAK,EAAE;YACnD,MAAM,OAAO,GAAG,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,mBAAmB,CAAC,IAAI,CAAC,kBAAkB,IAAG;AAClE,YAAA,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI;YACxC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC;AAC3D,QAAA,CAAC,CAAC;IACN;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 /* 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 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 if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\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 actualRoute = `${actualRoute}/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.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 || value === '') {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\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":["Globals","CommandResult","UrlHelpers","ValidationResult","ValidationResultSeverity","joinPaths","JsonSerializer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,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC;AAC3D,QAAA,CAAC,CAAC;IACN;AACH;;;;"}
|
|
@@ -5,6 +5,7 @@ import { ValidationResultSeverity } from '../validation/ValidationResultSeverity
|
|
|
5
5
|
export type PropertyChanged = (property: string) => void;
|
|
6
6
|
export interface ICommand<TCommandContent = object, TCommandResponse = object> extends ICanBeConfigured {
|
|
7
7
|
readonly route: string;
|
|
8
|
+
readonly roles: string[];
|
|
8
9
|
readonly propertyDescriptors: PropertyDescriptor[];
|
|
9
10
|
execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>>;
|
|
10
11
|
validate(): Promise<CommandResult<TCommandResponse>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ICommand.d.ts","sourceRoot":"","sources":["../../../commands/ICommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAKlF,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAKzD,MAAM,WAAW,QAAQ,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,SAAQ,gBAAgB;IAInG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAKvB,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAQnD,OAAO,CAAC,eAAe,CAAC,EAAE,wBAAwB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;IASxH,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,C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AAM,EAAE,eAAe,GAAG,IAAI,CAAC;IAKhD,iCAAiC,IAAI,IAAI,CAAC;IAK1C,aAAa,IAAI,IAAI,CAAC;IAKtB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAM7B,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAOxC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACvE"}
|
|
@@ -7,6 +7,7 @@ export interface IObservableQueryFor<TDataType, TArguments = object> extends IQu
|
|
|
7
7
|
readonly route: string;
|
|
8
8
|
readonly requiredRequestParameters: string[];
|
|
9
9
|
readonly defaultValue: TDataType;
|
|
10
|
+
readonly roles: string[];
|
|
10
11
|
subscribe(callback: OnNextResult<QueryResult<TDataType>>, args?: TArguments): ObservableQuerySubscription<TDataType>;
|
|
11
12
|
perform(args?: TArguments): Promise<QueryResult<TDataType>>;
|
|
12
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IObservableQueryFor.d.ts","sourceRoot":"","sources":["../../../queries/IObservableQueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAKhE,MAAM,MAAM,YAAY,CAAC,SAAS,IAAI,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;AAOhE,MAAM,WAAW,mBAAmB,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAAE,SAAQ,MAAM,EAAE,eAAe;IAChG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,yBAAyB,EAAE,MAAM,EAAE,CAAC;IAC7C,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"IObservableQueryFor.d.ts","sourceRoot":"","sources":["../../../queries/IObservableQueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAKhE,MAAM,MAAM,YAAY,CAAC,SAAS,IAAI,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;AAOhE,MAAM,WAAW,mBAAmB,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAAE,SAAQ,MAAM,EAAE,eAAe;IAChG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,yBAAyB,EAAE,MAAM,EAAE,CAAC;IAC7C,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC;IAKjC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAQzB,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,2BAA2B,CAAC,SAAS,CAAC,CAAC;IAOrH,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;CAC/D"}
|
|
@@ -5,6 +5,7 @@ export interface IQueryFor<TDataType, TArguments = object> extends IQuery, IHave
|
|
|
5
5
|
readonly route: string;
|
|
6
6
|
readonly requiredRequestParameters: string[];
|
|
7
7
|
readonly defaultValue: TDataType;
|
|
8
|
+
readonly roles: string[];
|
|
8
9
|
get parameters(): TArguments | undefined;
|
|
9
10
|
set parameters(value: TArguments);
|
|
10
11
|
perform(args?: TArguments): Promise<QueryResult<TDataType>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IQueryFor.d.ts","sourceRoot":"","sources":["../../../queries/IQueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAOhE,MAAM,WAAW,SAAS,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAAE,SAAQ,MAAM,EAAE,eAAe;IACtF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,yBAAyB,EAAE,MAAM,EAAE,CAAC;IAC7C,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC;IAKjC,IAAI,UAAU,IAAI,UAAU,GAAG,SAAS,CAAC;IAKzC,IAAI,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE;IASlC,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;CAC/D"}
|
|
1
|
+
{"version":3,"file":"IQueryFor.d.ts","sourceRoot":"","sources":["../../../queries/IQueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAOhE,MAAM,WAAW,SAAS,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAAE,SAAQ,MAAM,EAAE,eAAe;IACtF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,yBAAyB,EAAE,MAAM,EAAE,CAAC;IAC7C,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC;IAKjC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAKzB,IAAI,UAAU,IAAI,UAAU,GAAG,SAAS,CAAC;IAKzC,IAAI,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE;IASlC,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;CAC/D"}
|
|
@@ -16,6 +16,7 @@ export declare abstract class ObservableQueryFor<TDataType, TParameters = object
|
|
|
16
16
|
private _httpHeadersCallback;
|
|
17
17
|
abstract readonly route: string;
|
|
18
18
|
abstract readonly defaultValue: TDataType;
|
|
19
|
+
readonly roles: string[];
|
|
19
20
|
abstract readonly parameterDescriptors: ParameterDescriptor[];
|
|
20
21
|
abstract get requiredRequestParameters(): string[];
|
|
21
22
|
sorting: Sorting;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryFor.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAI5E,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AASxE,8BAAsB,kBAAkB,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,CAAE,YAAW,mBAAmB,CAAC,SAAS,EAAE,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"ObservableQueryFor.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAA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AS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKtD,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,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;IAMzB,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,iBAAiB;CAW5B"}
|
|
@@ -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 = Globals.apiBasePath ?? '';\n this._origin = Globals.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 const parameterValues = ParametersHelper.collectParameterValues(this);\n const combinedArgs = { ...(args as object || {}), ...parameterValues };\n return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs as object);\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 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,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AAS,KAAKD,2BAAa,CAAC,UAAU,IAAI,MAAM,GAAG,KAAK;QACzG;AAEA,QAAA,OAAO,cAAc;IACzB;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,GAAGE,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 readonly roles: string[] = [];\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 = Globals.apiBasePath ?? '';\n this._origin = Globals.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 const parameterValues = ParametersHelper.collectParameterValues(this);\n const combinedArgs = { ...(args as object || {}), ...parameterValues };\n return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs as object);\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 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;AAoBf,IAAA,SAAA;AAAiC,IAAA,UAAA;AAnB9C,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,WAAW;AACX,IAAA,oBAAoB;IAInB,KAAK,GAAa,EAAE;AAG7B,IAAA,OAAO;AACP,IAAA,MAAM;IAON,WAAA,CAAqB,SAAsB,EAAW,UAAmB,EAAA;QAApD,IAAA,CAAA,SAAS,GAAT,SAAS;QAAwB,IAAA,CAAA,UAAU,GAA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A,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YACzB,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;YAC1C,cAAc,CAAC,aAAa,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,KAAKD,2BAAa,CAAC,UAAU,IAAI,MAAM,GAAG,KAAK;QACzG;AAEA,QAAA,OAAO,cAAc;IACzB;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,GAAGE,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;;;;"}
|
|
@@ -15,6 +15,7 @@ export declare abstract class QueryFor<TDataType, TParameters = object> implemen
|
|
|
15
15
|
private _httpHeadersCallback;
|
|
16
16
|
abstract readonly route: string;
|
|
17
17
|
readonly validation?: QueryValidator<any>;
|
|
18
|
+
readonly roles: string[];
|
|
18
19
|
abstract readonly parameterDescriptors: ParameterDescriptor[];
|
|
19
20
|
abstract get requiredRequestParameters(): string[];
|
|
20
21
|
abstract defaultValue: TDataType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryFor.d.ts","sourceRoot":"","sources":["../../../queries/QueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,E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K,EAAE,MAAM,CAAC;IAEhC,QAAQ,CAAC,UAAU,CAAC,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IAE1C,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAM;IAC9B,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAAC;IAC9D,QAAQ,KAAK,yBAAyB,IAAI,MAAM,EAAE,CAAC;IACnD,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC;IACjC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,WAAW,GAAG,SAAS,CAAC;gBAOf,SAAS,EAAE,WAAW,EAAW,UAAU,EAAE,OAAO;IAUzE,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,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;CA4FrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryFor.js","sources":["../../../queries/QueryFor.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 { IQueryFor } from './IQueryFor';\nimport { QueryResult } from \"./QueryResult\";\nimport { QueryValidator } from './QueryValidator';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { Constructor } from '@cratis/fundamentals';\nimport { Paging } from './Paging';\nimport { Globals } from '../Globals';\nimport { Sorting } from './Sorting';\nimport { SortDirection } from './SortDirection';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class QueryFor<TDataType, TParameters = object> implements IQueryFor<TDataType, TParameters> {\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?: QueryValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n abstract defaultValue: TDataType;\n abortController?: AbortController;\n sorting: Sorting;\n paging: Paging;\n parameters: TParameters | undefined;\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 = 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 perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n args = args || this.parameters;\n\n const clientValidationErrors = this.validation?.validate(args as object || {}) || [];\n if (clientValidationErrors.length > 0) {\n return new QueryResult({\n data: this.defaultValue as object,\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: clientValidationErrors.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, this.modelType, this.enumerable) as QueryResult<TDataType>;\n }\n\n if (!ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args as object)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n if (this.abortController) {\n this.abortController.abort();\n }\n\n this.abortController = new AbortController();\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 {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }\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 signal: this.abortController.signal\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 }\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GAAGA,qBAAU,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;AAElF,QAAA,MAAM,OAAO,GAAG;AACZ,YAAA,GAAI,IAAI,CAAC,oBAAoB,IAAI,EAAE,GACnC;AACI,gBAAA,QAAQ,EAAE,kBAAkB;AAC5B,gBAAA,cAAc,EAAE;AACnB;SACJ;QAED,IAAI,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,CAAC,EAAE;YAChC,OAAO,CAACH,eAAO,CAAC,sBAAsB,CAAC,GAAG,IAAI,CAAC,aAAa;QAChE;AAEA,QAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;AAC9B,YAAA,MAAM,EAAE,KAAK;YACb,OAAO;AACP,YAAA,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC;AAChC,SAAA,CAAC;AAEF,QAAA,IAAI;AACA,YAAA,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE;AACpC,YAAA,OAAO,IAAIC,uBAAW,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC;QACnE;AAAE,QAAA,MAAM;AACJ,YAAA,OAAO,SAAS;QACpB;IACJ;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"QueryFor.js","sources":["../../../queries/QueryFor.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 { IQueryFor } from './IQueryFor';\nimport { QueryResult } from \"./QueryResult\";\nimport { QueryValidator } from './QueryValidator';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { Constructor } from '@cratis/fundamentals';\nimport { Paging } from './Paging';\nimport { Globals } from '../Globals';\nimport { Sorting } from './Sorting';\nimport { SortDirection } from './SortDirection';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class QueryFor<TDataType, TParameters = object> implements IQueryFor<TDataType, TParameters> {\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?: QueryValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n abstract defaultValue: TDataType;\n abortController?: AbortController;\n sorting: Sorting;\n paging: Paging;\n parameters: TParameters | undefined;\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 = 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 perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n args = args || this.parameters;\n\n const clientValidationErrors = this.validation?.validate(args as object || {}) || [];\n if (clientValidationErrors.length > 0) {\n return new QueryResult({\n data: this.defaultValue as object,\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: clientValidationErrors.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, this.modelType, this.enumerable) as QueryResult<TDataType>;\n }\n\n if (!ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args as object)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n if (this.abortController) {\n this.abortController.abort();\n }\n\n this.abortController = new AbortController();\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 {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }\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 signal: this.abortController.signal\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"],"names":["Sorting","Paging","Globals","QueryResult","ValidateRequestArguments","UrlHelpers","joinPaths","SortDirection","ParametersHelper"],"mappings":";;;;;;;;;;;;MAsBsB,QAAQ,CAAA;AAuBL,IAAA,SAAA;AAAiC,IAAA,UAAA;AAtB9C,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAEV,KAAK,GAAa,EAAE;AAI7B,IAAA,eAAe;AACf,IAAA,OAAO;AACP,IAAA,MAAM;AACN,IAAA,UAAU;IAOV,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;QAC/C,IAAI,CAAC,YAAY,GAAGA,eAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAGA,eAAO,CAAC,MAAM,IAAI,EAAE;QACnC,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;IAGA,MAAM,OAAO,CAAC,IAAkB,EA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AAI,WAAW;QACxE;AAEA,QAAA,MAAM,GAAG,GAAGA,qBAAU,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;AAElF,QAAA,MAAM,OAAO,GAAG;AACZ,YAAA,GAAI,IAAI,CAAC,oBAAoB,IAAI,EAAE,GACnC;AACI,gBAAA,QAAQ,EAAE,kBAAkB;AAC5B,gBAAA,cAAc,EAAE;AACnB;SACJ;QAED,IAAI,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,CAAC,EAAE;YAChC,OAAO,CAACH,eAAO,CAAC,sBAAsB,CAAC,GAAG,IAAI,CAAC,aAAa;QAChE;AAEA,QAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;AAC9B,YAAA,MAAM,EAAE,KAAK;YACb,OAAO;AACP,YAAA,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC;AAChC,SAAA,CAAC;AAEF,QAAA,IAAI;AACA,YAAA,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE;AACpC,YAAA,OAAO,IAAIC,uBAAW,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC;QACnE;AAAE,QAAA,MAAM;AACJ,YAAA,OAAO,SAAS;QACpB;IACJ;AACH;;;;"}
|
|
@@ -39,4 +39,15 @@ export declare class TestObservableQueryWithRouteAndQueryArgs extends Observable
|
|
|
39
39
|
get requiredRequestParameters(): string[];
|
|
40
40
|
constructor();
|
|
41
41
|
}
|
|
42
|
+
export interface TestObservableQueryWithMultipleRequiredParametersArguments {
|
|
43
|
+
userId: string;
|
|
44
|
+
category: string;
|
|
45
|
+
}
|
|
46
|
+
export declare class TestObservableQueryWithMultipleRequiredParameters extends ObservableQueryFor<string, TestObservableQueryWithMultipleRequiredParametersArguments> {
|
|
47
|
+
readonly route = "/api/filter/{userId}/{category}";
|
|
48
|
+
readonly defaultValue = "";
|
|
49
|
+
readonly parameterDescriptors: ParameterDescriptor[];
|
|
50
|
+
get requiredRequestParameters(): string[];
|
|
51
|
+
constructor();
|
|
52
|
+
}
|
|
42
53
|
//# sourceMappingURL=TestQueries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestQueries.d.ts","sourceRoot":"","sources":["../../../../../queries/for_ObservableQueryFor/given/TestQueries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAE9E,qBAAa,mBAAoB,SAAQ,kBAAkB,CAAC,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;IAC/E,QAAQ,CAAC,KAAK,oBAAoB;IAClC,QAAQ,CAAC,YAAY,MAAM;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAElD;IAEF,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;;CAKJ;AAED,qBAAa,mBAAoB,SAAQ,kBAAkB,CAAC,MAAM,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;IACvF,QAAQ,CAAC,KAAK,2BAA2B;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAM;IACrC,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAElD;IAEF,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;;CAKJ;AAED,qBAAa,gDAAiD,SAAQ,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC;IACpG,QAAQ,CAAC,KAAK,iBAAiB;IAC/B,QAAQ,CAAC,YAAY,MAAM;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAGlD;IAEF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,IAAI,yBAAyB,IAAI,MAAM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IACpG,QAAQ,CAAC,KAAK,iBAAiB;IAC/B,QAAQ,CAAC,YAAY,MAAM;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAGlD;IAEF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;;CAKJ;AAED,MAAM,WAAW,wCAAwC;IACrD,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,wCAAyC,SAAQ,kBAAkB,CAAC,MAAM,EAAE,wCAAwC,CAAC;IAC9H,QAAQ,CAAC,KAAK,qBAAqB;IACnC,QAAQ,CAAC,YAAY,MAAM;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAIlD;IAEF,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;;CAKJ;AAED,MAAM,WAAW,0DAA0D;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,iDAAkD,SAAQ,kBAAkB,CAAC,MAAM,EAAE,0DAA0D,CAAC;IACzJ,QAAQ,CAAC,KAAK,qCAAqC;IACnD,QAAQ,CAAC,YAAY,MAAM;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAGlD;IAEF,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;;CAKJ"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { TestObservableQuery, TestEnumerableQuery, TestObservableQueryWithParameterDescriptorValues, TestObservableQueryWithRouteAndQueryArgs } from './TestQueries';
|
|
1
|
+
import { TestObservableQuery, TestEnumerableQuery, TestObservableQueryWithParameterDescriptorValues, TestObservableQueryWithRouteAndQueryArgs, TestObservableQueryWithMultipleRequiredParameters } from './TestQueries';
|
|
2
2
|
export declare class an_observable_query_for {
|
|
3
3
|
query: TestObservableQuery;
|
|
4
4
|
enumerableQuery: TestEnumerableQuery;
|
|
5
5
|
queryWithParameterDescriptorValues: TestObservableQueryWithParameterDescriptorValues;
|
|
6
6
|
queryWithRouteAndQueryArgs: TestObservableQueryWithRouteAndQueryArgs;
|
|
7
|
+
queryWithMultipleRequiredParameters: TestObservableQueryWithMultipleRequiredParameters;
|
|
7
8
|
constructor();
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=an_observable_query_for.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"an_observable_query_for.d.ts","sourceRoot":"","sources":["../../../../../queries/for_ObservableQueryFor/given/an_observable_query_for.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"an_observable_query_for.d.ts","sourceRoot":"","sources":["../../../../../queries/for_ObservableQueryFor/given/an_observable_query_for.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,mBAAmB,EACnB,mBAAmB,EACnB,gDAAgD,EAChD,wCAAwC,EACxC,iDAAiD,EACpD,MAAM,eAAe,CAAC;AAEvB,qBAAa,uBAAuB;IAChC,KAAK,EAAE,mBAAmB,CAAC;IAC3B,eAAe,EAAE,mBAAmB,CAAC;IACrC,kCAAkC,EAAE,gDAAgD,CAAC;IACrF,0BAA0B,EAAE,wCAAwC,CAAC;IACrE,mCAAmC,EAAE,iDAAiD,CAAC;;CAS1F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_partially_missing_required_arguments.d.ts","sourceRoot":"","sources":["../../../../../queries/for_ObservableQueryFor/when_performing/with_partially_missing_required_arguments.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_partially_missing_required_arguments.d.ts","sourceRoot":"","sources":["../../../../../queries/for_ObservableQueryFor/when_subscribing/with_partially_missing_required_arguments.ts"],"names":[],"mappings":""}
|
|
@@ -34,4 +34,15 @@ export declare class TestQueryForWithParameterDescriptorValues extends QueryFor<
|
|
|
34
34
|
get requiredRequestParameters(): string[];
|
|
35
35
|
constructor();
|
|
36
36
|
}
|
|
37
|
+
export interface TestQueryForWithMultipleRequiredParametersArguments {
|
|
38
|
+
userId: string;
|
|
39
|
+
category: string;
|
|
40
|
+
}
|
|
41
|
+
export declare class TestQueryForWithMultipleRequiredParameters extends QueryFor<string, TestQueryForWithMultipleRequiredParametersArguments> {
|
|
42
|
+
readonly route = "/api/filter/{userId}/{category}";
|
|
43
|
+
readonly defaultValue = "";
|
|
44
|
+
readonly parameterDescriptors: ParameterDescriptor[];
|
|
45
|
+
get requiredRequestParameters(): string[];
|
|
46
|
+
constructor();
|
|
47
|
+
}
|
|
37
48
|
//# sourceMappingURL=TestQueries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestQueries.d.ts","sourceRoot":"","sources":["../../../../../queries/for_QueryFor/given/TestQueries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAE9E,qBAAa,YAAa,SAAQ,QAAQ,CAAC,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;IAC9D,QAAQ,CAAC,KAAK,oBAAoB;IAClC,QAAQ,CAAC,YAAY,MAAM;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAElD;IAEF,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;;CAKJ;AAED,qBAAa,sBAAuB,SAAQ,QAAQ,CAAC,MAAM,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;IAChF,QAAQ,CAAC,KAAK,2BAA2B;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,CAAM;IACrC,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAElD;IAEF,IAAI,yBA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E,MAAM,EAAE,CAAM;IACrC,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAElD;IAEF,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;;CAKJ;AAED,qBAAa,iCAAkC,SAAQ,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAC3E,QAAQ,CAAC,KAAK,cAAc;IAC5B,QAAQ,CAAC,YAAY,MAAM;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAAM;IAE1D,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;;CAKJ;AAED,qBAAa,yCAA0C,SAAQ,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACnF,QAAQ,CAAC,KAAK,iBAAiB;IAC/B,QAAQ,CAAC,YAAY,MAAM;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAGlD;IAEF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;;CAKJ;AAED,MAAM,WAAW,mDAAmD;IAChE,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,0CAA2C,SAAQ,QAAQ,CAAC,MAAM,EAAE,mDAAmD,CAAC;IACjI,QAAQ,CAAC,KAAK,qCAAqC;IACnD,QAAQ,CAAC,YAAY,MAAM;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAGlD;IAEF,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;;CAKJ"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { TestQueryFor, TestEnumerableQueryFor, TestQueryForWithoutRequiredParams, TestQueryForWithParameterDescriptorValues } from './TestQueries';
|
|
1
|
+
import { TestQueryFor, TestEnumerableQueryFor, TestQueryForWithoutRequiredParams, TestQueryForWithParameterDescriptorValues, TestQueryForWithMultipleRequiredParameters } from './TestQueries';
|
|
2
2
|
export declare class a_query_for {
|
|
3
3
|
query: TestQueryFor;
|
|
4
4
|
enumerableQuery: TestEnumerableQueryFor;
|
|
5
5
|
queryWithoutParams: TestQueryForWithoutRequiredParams;
|
|
6
6
|
queryWithParameterDescriptorValues: TestQueryForWithParameterDescriptorValues;
|
|
7
|
+
queryWithMultipleRequiredParameters: TestQueryForWithMultipleRequiredParameters;
|
|
7
8
|
constructor();
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=a_query_for.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a_query_for.d.ts","sourceRoot":"","sources":["../../../../../queries/for_QueryFor/given/a_query_for.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"a_query_for.d.ts","sourceRoot":"","sources":["../../../../../queries/for_QueryFor/given/a_query_for.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,YAAY,EACZ,sBAAsB,EACtB,iCAAiC,EACjC,yCAAyC,EACzC,0CAA0C,EAC7C,MAAM,eAAe,CAAC;AAEvB,qBAAa,WAAW;IACpB,KAAK,EAAE,YAAY,CAAC;IACpB,eAAe,EAAE,sBAAsB,CAAC;IACxC,kBAAkB,EAAE,iCAAiC,CAAC;IACtD,kCAAkC,EAAE,yCAAyC,CAAC;IAC9E,mCAAmC,EAAE,0CAA0C,CAAC;;CASnF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_partially_missing_required_arguments.d.ts","sourceRoot":"","sources":["../../../../../queries/for_QueryFor/when_performing/with_partially_missing_required_arguments.ts"],"names":[],"mappings":""}
|
|
@@ -14,6 +14,7 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
|
|
|
14
14
|
private _httpHeadersCallback;
|
|
15
15
|
abstract readonly route: string;
|
|
16
16
|
readonly validation?: CommandValidator<any>;
|
|
17
|
+
readonly roles: string[];
|
|
17
18
|
abstract readonly propertyDescriptors: PropertyDescriptor[];
|
|
18
19
|
abstract get requestParameters(): string[];
|
|
19
20
|
private _initialValues;
|
|
@@ -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,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAInE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAUlF,8BAAsB,OAAO,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,YAAW,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;
|
|
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,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAInE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAUlF,8BAAsB,OAAO,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,YAAW,QAAQ,CAAC,eAAe,EAAE,gBAAgB,C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