@cratis/arc 25.7.1 → 25.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/Command.ts +23 -17
- package/commands/CommandExecutionState.ts +63 -0
- package/commands/for_Command/when_executing/and_execution_rejects.ts +27 -0
- package/commands/for_Command/when_executing/with_overlapping_executions.ts +62 -0
- package/commands/for_Command/when_validating/with_pending_validation.ts +23 -0
- package/commands/index.ts +2 -0
- package/dist/cjs/commands/Command.d.ts.map +1 -1
- package/dist/cjs/commands/Command.js +26 -20
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/cjs/commands/CommandExecutionState.d.ts +8 -0
- package/dist/cjs/commands/CommandExecutionState.d.ts.map +1 -0
- package/dist/cjs/commands/CommandExecutionState.js +56 -0
- package/dist/cjs/commands/CommandExecutionState.js.map +1 -0
- package/dist/cjs/commands/index.d.ts +2 -0
- package/dist/cjs/commands/index.d.ts.map +1 -1
- package/dist/cjs/commands/index.js +3 -0
- package/dist/cjs/commands/index.js.map +1 -1
- package/dist/esm/commands/Command.d.ts.map +1 -1
- package/dist/esm/commands/Command.js +26 -20
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/CommandExecutionState.d.ts +8 -0
- package/dist/esm/commands/CommandExecutionState.d.ts.map +1 -0
- package/dist/esm/commands/CommandExecutionState.js +52 -0
- package/dist/esm/commands/CommandExecutionState.js.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/and_execution_rejects.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/and_execution_rejects.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/and_execution_rejects.js +22 -0
- package/dist/esm/commands/for_Command/when_executing/and_execution_rejects.js.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_overlapping_executions.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/with_overlapping_executions.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_overlapping_executions.js +53 -0
- package/dist/esm/commands/for_Command/when_executing/with_overlapping_executions.js.map +1 -0
- package/dist/esm/commands/for_Command/when_validating/with_pending_validation.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_validating/with_pending_validation.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_validating/with_pending_validation.js +17 -0
- package/dist/esm/commands/for_Command/when_validating/with_pending_validation.js.map +1 -0
- package/dist/esm/commands/index.d.ts +2 -0
- package/dist/esm/commands/index.d.ts.map +1 -1
- package/dist/esm/commands/index.js +1 -0
- package/dist/esm/commands/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CommandResult } from './CommandResult.js';
|
|
2
|
+
import { beginCommandExecution } from './CommandExecutionState.js';
|
|
2
3
|
import { JsonSerializer } from '@cratis/fundamentals';
|
|
3
4
|
import { Globals } from '../Globals.js';
|
|
4
5
|
import { joinPaths } from '../joinPaths.js';
|
|
@@ -56,27 +57,32 @@ import { ValidationResultReasonDetail } from '../validation/ValidationResultReas
|
|
|
56
57
|
this._httpHeadersCallback = callback;
|
|
57
58
|
}
|
|
58
59
|
/** @inheritdoc */ async execute(allowedSeverity, ignoreWarnings) {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
const finishExecution = beginCommandExecution(this);
|
|
61
|
+
try {
|
|
62
|
+
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
63
|
+
const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);
|
|
64
|
+
if (filteredClientErrors.length > 0) {
|
|
65
|
+
return CommandResult.validationFailed(filteredClientErrors);
|
|
66
|
+
}
|
|
67
|
+
const validationErrors = this.validateRequiredProperties();
|
|
68
|
+
const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);
|
|
69
|
+
if (filteredRequiredErrors.length > 0) {
|
|
70
|
+
return CommandResult.validationFailed(filteredRequiredErrors);
|
|
71
|
+
}
|
|
72
|
+
const actualRoute = this.resolveRoute();
|
|
73
|
+
const submittedValues = this.captureCurrentValues();
|
|
74
|
+
const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', {
|
|
75
|
+
allowedSeverity,
|
|
76
|
+
ignoreWarnings
|
|
77
|
+
});
|
|
78
|
+
if (result.isSuccess) {
|
|
79
|
+
this._initialValues = submittedValues;
|
|
80
|
+
this.updateHasChanges();
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
} finally{
|
|
84
|
+
finishExecution();
|
|
78
85
|
}
|
|
79
|
-
return result;
|
|
80
86
|
}
|
|
81
87
|
/** @inheritdoc */ async validate() {
|
|
82
88
|
const clientValidationErrors = this.validation?.validate(this) || [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Command.js","sources":["../../../commands/Command.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ICommand, PropertyChanged } from './ICommand.js';\nimport { CommandResult } from \"./CommandResult.js\";\nimport { CommandValidator } from './CommandValidator.js';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals.js';\nimport { joinPaths } from '../joinPaths.js';\nimport { UrlHelpers } from '../UrlHelpers.js';\nimport { GetHttpHeaders } from '../GetHttpHeaders.js';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor.js';\nimport { SliceLocation } from '../reflection/SliceLocation.js';\nimport { ValidationResult } from '../validation/ValidationResult.js';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity.js';\nimport { ValidationResultReason } from '../validation/ValidationResultReason.js';\nimport { ValidationResultReasonDetail } from '../validation/ValidationResultReasonDetail.js';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n * Missing required properties produce a {@link ValidationResultReason.Rule} result with\n * {@link ValidationResultReasonDetail.Required}, without contacting the server.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n /**\n * Gets the {@link SliceLocation} of the command. Generated proxies override it with the location resolved from the backend namespace.\n */\n static readonly sliceLocation: SliceLocation = SliceLocation.empty;\n\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n /** Inclusive minimum blocking severity declared by a model-bound command proxy. */\n readonly blockOnValidationSeverity?: ValidationResultSeverity;\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n async execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n const actualRoute = this.resolveRoute();\n\n const submittedValues = this.captureCurrentValues();\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', { allowedSeverity, ignoreWarnings });\n if (result.isSuccess) {\n this._initialValues = submittedValues;\n this.updateHasChanges();\n }\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n const actualRoute = `${this.resolveRoute()}/validate`;\n const result = await this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n if (result.isSuccess && clientValidationErrors.length > 0) {\n return Object.assign(result, { validationResults: [...result.validationResults, ...clientValidationErrors] });\n }\n return result;\n }\n\n /** @inheritdoc */\n validateClientSide(): CommandResult<TCommandResponse> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n const advisoryResults = [...clientValidationErrors, ...validationErrors];\n if (advisoryResults.length === 0) {\n return CommandResult.empty as CommandResult<TCommandResponse>;\n }\n\n return new CommandResult({\n ...CommandResult.empty,\n correlationId: CommandResult.empty.correlationId.toString(),\n validationResults: advisoryResults,\n response: null\n }, Object, false) as CommandResult<TCommandResponse>;\n }\n\n private resolveRoute(): string {\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n return UrlHelpers.replaceRouteParameters(this.route, payload).route;\n }\n return this.route;\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null) {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null,\n ValidationResultReason.Rule,\n ValidationResultReasonDetail.Required\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\n if (this.blockOnValidationSeverity !== undefined) {\n const effectiveAllowed = Math.min(allowedSeverity ?? ValidationResultSeverity.Error, this.blockOnValidationSeverity - 1);\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Unknown || result.severity > effectiveAllowed);\n }\n if (ignoreWarnings === true) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n if (allowedSeverity === undefined) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n return validationResults.filter(result => result.severity > allowedSeverity);\n }\n\n private buildHeaders(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n if (allowedSeverity !== undefined) {\n headers['X-Allowed-Severity'] = allowedSeverity.toString();\n }\n\n if (ignoreWarnings === true) {\n headers['X-Ignore-Warnings'] = 'true';\n }\n\n return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string,\n options: { allowedSeverity?: ValidationResultSeverity; ignoreWarnings?: boolean } = {}\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders(options.allowedSeverity, options.ignoreWarnings);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this._initialValues = this.captureCurrentValues();\n this.updateHasChanges();\n }\n\n private captureCurrentValues(): object {\n const values = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (property in this) {\n values[property] = this[property];\n }\n });\n return values;\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n if (this._callbacks.some(_ => _.callback.deref() === callback && _.thisArg.deref() === thisArg)) {\n return;\n }\n\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Command","sliceLocation","SliceLocation","empty","_microservice","_apiBasePath","_origin","_httpHeadersCallback","validation","roles","blockOnValidationSeverity","_initialValues","_hasChanges","_callbacks","_responseType","Object","_isResponseTypeEnumerable","Globals","microservice","apiBasePath","origin","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","execute","allowedSeverity","ignoreWarnings","clientValidationErrors","validate","filteredClientErrors","filterValidationResultsBySeverity","length","CommandResult","validationFailed","validationErrors","validateRequiredProperties","filteredRequiredErrors","actualRoute","resolveRoute","submittedValues","captureCurrentValues","result","performRequest","isSuccess","updateHasChanges","assign","validationResults","validateClientSide","advisoryResults","correlationId","toString","response","requestParameters","payload","buildPayload","UrlHelpers","replaceRouteParameters","route","propertyDescriptors","forEach","propertyDescriptor","property","name","isOptional","includes","value","undefined","push","ValidationResult","ValidationResultSeverity","Error","ValidationResultReason","Rule","ValidationResultReasonDetail","Required","effectiveAllowed","Math","min","filter","severity","Unknown","buildHeaders","customHeaders","headers","microserviceHttpHeader","notFoundMessage","errorMessage","options","joinPaths","url","createUrlFrom","fetch","method","body","JsonSerializer","serialize","status","failed","json","ex","clear","setInitialValues","values","prototype","hasOwnProperty","call","setInitialValuesFromCurrentValues","revertChanges","hasChanges","propertyChanged","callbackContainer","deref","thisArg","_","onPropertyChanged","some","WeakRef"],"mappings":";;;;;;;;;;;AAAA;AACA;AAsBA;;;;AAIC,IACM,MAAeA,OAAAA,CAAAA;;;AAClB;;AAEC,QACD,OAAgBC,aAAAA,GAA+BC,aAAAA,CAAcC,KAAK;IAE1DC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;4DAGR,UAASC;AACT,2DACSC,KAAAA,GAAkB,EAAE;wFAE7B,yBAASC;AAIDC,IAAAA,cAAAA,GAAyB,EAAC;AAC1BC,IAAAA,WAAAA,GAAc,KAAA;AACdC,IAAAA,UAAAA,GAAyB,EAAE;AAEnC;;;;AAIC,QACD,YAAY,aAASC,GAA6BC,MAAM,EAAWC,yBAAkC,CAAE;aAAlFF,aAAAA,GAAAA,aAAAA;aAA8CE,yBAAAA,GAAAA,yBAAAA;AAC/D,QAAA,IAAI,CAACZ,aAAa,GAAGa,OAAAA,CAAQC,YAAY,IAAI,EAA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,OAAO,CAACD,KAAK,EAAA;AAC/C,YAAA,IAAIxF,YAAYyF,OAAAA,EAAS;gBACrBzF,QAAAA,CAASkF,IAAI,CAACO,OAAAA,EAASnD,QAAAA,CAAAA;YAC3B,CAAA,MAAO;AACH,gBAAA,IAAI,CAAClD,UAAU,GAAG,IAAI,CAACA,UAAU,CAACmE,MAAM,CAACmC,CAAAA,CAAAA,GAAKA,CAAAA,CAAE1F,QAAQ,KAAKuF,kBAAkBvF,QAAQ,CAAA;AAC3F,YAAA;AACJ,QAAA,CAAA,CAAA;AACJ,IAAA;AAEA,uBACA2F,iBAAAA,CAAkB3F,QAAyB,EAAEyF,OAAe,EAAE;AAC1D,QAAA,IAAI,IAAI,CAACrG,UAAU,CAACwG,IAAI,CAACF,CAAAA,CAAAA,GAAKA,CAAAA,CAAE1F,QAAQ,CAACwF,KAAK,OAAOxF,QAAAA,IAAY0F,CAAAA,CAAED,OAAO,CAACD,KAAK,OAAOC,OAAAA,CAAAA,EAAU;AAC7F,YAAA;AACJ,QAAA;AAEA,QAAA,IAAI,CAACrG,UAAU,CAACwD,IAAI,CAAC;AACjB5C,YAAAA,QAAAA,EAAU,IAAI6F,OAAAA,CAAQ7F,QAAAA,CAAAA;AACtByF,YAAAA,OAAAA,EAAS,IAAII,OAAAA,CAAQJ,OAAAA;AACzB,SAAA,CAAA;AACJ,IAAA;IAEQpE,gBAAAA,GAAmB;QACvB,IAAI,CAAClC,WAAW,GAAG,IAAI,CAACgD,mBAAmB,CAACyD,IAAI,CAACvD,CAAAA,kBAAAA,GAAAA;YAC7C,MAAMC,QAAAA,GAAWD,mBAAmBE,IAAI;YACxC,OAAO,IAAI,CAACD,QAAAA,CAAS,KAAK,IAAI,CAACpD,cAAc,CAACoD,QAAAA,CAAS;AAC3D,QAAA,CAAA,CAAA;AACJ,IAAA;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"Command.js","sources":["../../../commands/Command.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ICommand, PropertyChanged } from './ICommand.js';\nimport { CommandResult } from \"./CommandResult.js\";\nimport { CommandValidator } from './CommandValidator.js';\nimport { beginCommandExecution } from './CommandExecutionState.js';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals.js';\nimport { joinPaths } from '../joinPaths.js';\nimport { UrlHelpers } from '../UrlHelpers.js';\nimport { GetHttpHeaders } from '../GetHttpHeaders.js';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor.js';\nimport { SliceLocation } from '../reflection/SliceLocation.js';\nimport { ValidationResult } from '../validation/ValidationResult.js';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity.js';\nimport { ValidationResultReason } from '../validation/ValidationResultReason.js';\nimport { ValidationResultReasonDetail } from '../validation/ValidationResultReasonDetail.js';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n * Missing required properties produce a {@link ValidationResultReason.Rule} result with\n * {@link ValidationResultReasonDetail.Required}, without contacting the server.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n /**\n * Gets the {@link SliceLocation} of the command. Generated proxies override it with the location resolved from the backend namespace.\n */\n static readonly sliceLocation: SliceLocation = SliceLocation.empty;\n\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n /** Inclusive minimum blocking severity declared by a model-bound command proxy. */\n readonly blockOnValidationSeverity?: ValidationResultSeverity;\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n async execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>> {\n const finishExecution = beginCommandExecution(this);\n try {\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 const actualRoute = this.resolveRoute();\n\n const submittedValues = this.captureCurrentValues();\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', { allowedSeverity, ignoreWarnings });\n if (result.isSuccess) {\n this._initialValues = submittedValues;\n this.updateHasChanges();\n }\n return result;\n } finally {\n finishExecution();\n }\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n const actualRoute = `${this.resolveRoute()}/validate`;\n const result = await this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n if (result.isSuccess && clientValidationErrors.length > 0) {\n return Object.assign(result, { validationResults: [...result.validationResults, ...clientValidationErrors] });\n }\n return result;\n }\n\n /** @inheritdoc */\n validateClientSide(): CommandResult<TCommandResponse> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n const advisoryResults = [...clientValidationErrors, ...validationErrors];\n if (advisoryResults.length === 0) {\n return CommandResult.empty as CommandResult<TCommandResponse>;\n }\n\n return new CommandResult({\n ...CommandResult.empty,\n correlationId: CommandResult.empty.correlationId.toString(),\n validationResults: advisoryResults,\n response: null\n }, Object, false) as CommandResult<TCommandResponse>;\n }\n\n private resolveRoute(): string {\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n return UrlHelpers.replaceRouteParameters(this.route, payload).route;\n }\n return this.route;\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null) {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null,\n ValidationResultReason.Rule,\n ValidationResultReasonDetail.Required\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\n if (this.blockOnValidationSeverity !== undefined) {\n const effectiveAllowed = Math.min(allowedSeverity ?? ValidationResultSeverity.Error, this.blockOnValidationSeverity - 1);\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Unknown || result.severity > effectiveAllowed);\n }\n if (ignoreWarnings === true) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n if (allowedSeverity === undefined) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n return validationResults.filter(result => result.severity > allowedSeverity);\n }\n\n private buildHeaders(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n if (allowedSeverity !== undefined) {\n headers['X-Allowed-Severity'] = allowedSeverity.toString();\n }\n\n if (ignoreWarnings === true) {\n headers['X-Ignore-Warnings'] = 'true';\n }\n\n return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string,\n options: { allowedSeverity?: ValidationResultSeverity; ignoreWarnings?: boolean } = {}\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders(options.allowedSeverity, options.ignoreWarnings);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this._initialValues = this.captureCurrentValues();\n this.updateHasChanges();\n }\n\n private captureCurrentValues(): object {\n const values = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (property in this) {\n values[property] = this[property];\n }\n });\n return values;\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n if (this._callbacks.some(_ => _.callback.deref() === callback && _.thisArg.deref() === thisArg)) {\n return;\n }\n\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Command","sliceLocation","SliceLocation","empty","_microservice","_apiBasePath","_origin","_httpHeadersCallback","validation","roles","blockOnValidationSeverity","_initialValues","_hasChanges","_callbacks","_responseType","Object","_isResponseTypeEnumerable","Globals","microservice","apiBasePath","origin","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","execute","allowedSeverity","ignoreWarnings","finishExecution","beginCommandExecution","clientValidationErrors","validate","filteredClientErrors","filterValidationResultsBySeverity","length","CommandResult","validationFailed","validationErrors","validateRequiredProperties","filteredRequiredErrors","actualRoute","resolveRoute","submittedValues","captureCurrentValues","result","performRequest","isSuccess","updateHasChanges","assign","validationResults","validateClientSide","advisoryResults","correlationId","toString","response","requestParameters","payload","buildPayload","UrlHelpers","replaceRouteParameters","route","propertyDescriptors","forEach","propertyDescriptor","property","name","isOptional","includes","value","undefined","push","ValidationResult","ValidationResultSeverity","Error","ValidationResultReason","Rule","ValidationResultReasonDetail","Required","effectiveAllowed","Math","min","filter","severity","Unknown","buildHeaders","customHeaders","headers","microserviceHttpHeader","notFoundMessage","errorMessage","options","joinPaths","url","createUrlFrom","fetch","method","body","JsonSerializer","serialize","status","failed","json","ex","clear","setInitialValues","values","prototype","hasOwnProperty","call","setInitialValuesFromCurrentValues","revertChanges","hasChanges","propertyChanged","callbackContainer","deref","thisArg","_","onPropertyChanged","some","WeakRef"],"mappings":";;;;;;;;;;;;AAAA;AACA;A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,OAAO,CAACD,KAAK,OAAOC,OAAAA,CAAAA,EAAU;AAC7F,YAAA;AACJ,QAAA;AAEA,QAAA,IAAI,CAACvG,UAAU,CAAC0D,IAAI,CAAC;AACjB9C,YAAAA,QAAAA,EAAU,IAAI+F,OAAAA,CAAQ/F,QAAAA,CAAAA;AACtB2F,YAAAA,OAAAA,EAAS,IAAII,OAAAA,CAAQJ,OAAAA;AACzB,SAAA,CAAA;AACJ,IAAA;IAEQpE,gBAAAA,GAAmB;QACvB,IAAI,CAACpC,WAAW,GAAG,IAAI,CAACkD,mBAAmB,CAACyD,IAAI,CAACvD,CAAAA,kBAAAA,GAAAA;YAC7C,MAAMC,QAAAA,GAAWD,mBAAmBE,IAAI;YACxC,OAAO,IAAI,CAACD,QAAAA,CAAS,KAAK,IAAI,CAACtD,cAAc,CAACsD,QAAAA,CAAS;AAC3D,QAAA,CAAA,CAAA;AACJ,IAAA;AACJ;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Command } from './Command.js';
|
|
2
|
+
export interface CommandExecutionState {
|
|
3
|
+
readonly isExecuting: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function getCommandExecutionState(command: Command<unknown, unknown>): CommandExecutionState;
|
|
6
|
+
export declare function subscribeToCommandExecutionState(command: Command<unknown, unknown>, onChange: () => void): () => void;
|
|
7
|
+
export declare function beginCommandExecution(command: Command<unknown, unknown>): () => void;
|
|
8
|
+
//# sourceMappingURL=CommandExecutionState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandExecutionState.d.ts","sourceRoot":"","sources":["../../../commands/CommandExecutionState.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,WAAW,qBAAqB;IAElC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CACjC;AAgBD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,qBAAqB,CAElG;AAQD,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAKrH;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,MAAM,IAAI,CAWpF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
const executions = new WeakMap();
|
|
4
|
+
const idle = Object.freeze({
|
|
5
|
+
isExecuting: false
|
|
6
|
+
});
|
|
7
|
+
const executing = Object.freeze({
|
|
8
|
+
isExecuting: true
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Gets the current execution state of a command. Validation without execution does not affect this state.
|
|
12
|
+
* @param command The command instance to read.
|
|
13
|
+
* @returns A readonly snapshot that keeps the same identity while the execution state is unchanged.
|
|
14
|
+
*/ function getCommandExecutionState(command) {
|
|
15
|
+
return (executions.get(command)?.count ?? 0) > 0 ? executing : idle;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Subscribes to execution state changes when the first execution starts or the last one settles.
|
|
19
|
+
* @param command The command instance to observe.
|
|
20
|
+
* @param onChange The callback to invoke when the state changes.
|
|
21
|
+
* @returns A function that removes this subscription.
|
|
22
|
+
*/ function subscribeToCommandExecutionState(command, onChange) {
|
|
23
|
+
const { changes } = getOrCreateExecution(command);
|
|
24
|
+
const listener = ()=>onChange();
|
|
25
|
+
changes.addEventListener('change', listener);
|
|
26
|
+
return ()=>changes.removeEventListener('change', listener);
|
|
27
|
+
}
|
|
28
|
+
function beginCommandExecution(command) {
|
|
29
|
+
const execution = getOrCreateExecution(command);
|
|
30
|
+
if (++execution.count === 1) {
|
|
31
|
+
execution.changes.dispatchEvent(new Event('change'));
|
|
32
|
+
}
|
|
33
|
+
return ()=>{
|
|
34
|
+
if (--execution.count === 0) {
|
|
35
|
+
execution.changes.dispatchEvent(new Event('change'));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function getOrCreateExecution(command) {
|
|
40
|
+
let execution = executions.get(command);
|
|
41
|
+
if (!execution) {
|
|
42
|
+
execution = {
|
|
43
|
+
count: 0,
|
|
44
|
+
changes: new EventTarget()
|
|
45
|
+
};
|
|
46
|
+
executions.set(command, execution);
|
|
47
|
+
}
|
|
48
|
+
return execution;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { beginCommandExecution, getCommandExecutionState, subscribeToCommandExecutionState };
|
|
52
|
+
//# sourceMappingURL=CommandExecutionState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandExecutionState.js","sources":["../../../commands/CommandExecutionState.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 type { Command } from './Command.js';\n\n/** The execution state of a command instance. */\nexport interface CommandExecutionState {\n /** Whether any executions of this command instance are still in flight. */\n readonly isExecuting: boolean;\n}\n\ntype Execution = {\n count: number;\n changes: EventTarget;\n};\n\nconst executions = new WeakMap<Command<unknown, unknown>, Execution>();\nconst idle: CommandExecutionState = Object.freeze({ isExecuting: false });\nconst executing: CommandExecutionState = Object.freeze({ isExecuting: true });\n\n/**\n * Gets the current execution state of a command. Validation without execution does not affect this state.\n * @param command The command instance to read.\n * @returns A readonly snapshot that keeps the same identity while the execution state is unchanged.\n */\nexport function getCommandExecutionState(command: Command<unknown, unknown>): CommandExecutionState {\n return (executions.get(command)?.count ?? 0) > 0 ? executing : idle;\n}\n\n/**\n * Subscribes to execution state changes when the first execution starts or the last one settles.\n * @param command The command instance to observe.\n * @param onChange The callback to invoke when the state changes.\n * @returns A function that removes this subscription.\n */\nexport function subscribeToCommandExecutionState(command: Command<unknown, unknown>, onChange: () => void): () => void {\n const { changes } = getOrCreateExecution(command);\n const listener = () => onChange();\n changes.addEventListener('change', listener);\n return () => changes.removeEventListener('change', listener);\n}\n\nexport function beginCommandExecution(command: Command<unknown, unknown>): () => void {\n const execution = getOrCreateExecution(command);\n if (++execution.count === 1) {\n execution.changes.dispatchEvent(new Event('change'));\n }\n\n return () => {\n if (--execution.count === 0) {\n execution.changes.dispatchEvent(new Event('change'));\n }\n };\n}\n\nfunction getOrCreateExecution(command: Command<unknown, unknown>): Execution {\n let execution = executions.get(command);\n if (!execution) {\n execution = { count: 0, changes: new EventTarget() };\n executions.set(command, execution);\n }\n return execution;\n}\n"],"names":["executions","WeakMap","idle","Object","freeze","isExecuting","executing","getCommandExecutionState","command","get","count","subscribeToCommandExecutionState","onChange","changes","getOrCreateExecution","listener","addEventListener","removeEventListener","beginCommandExecution","execution","dispatchEvent","Event","EventTarget","set"],"mappings":"AAAA;AACA;AAeA,MAAMA,aAAa,IAAIC,OAAAA,EAAAA;AACvB,MAAMC,IAAAA,GAA8BC,MAAAA,CAAOC,MAAM,CAAC;IAAEC,WAAAA,EAAa;AAAM,CAAA,CAAA;AACvE,MAAMC,SAAAA,GAAmCH,MAAAA,CAAOC,MAAM,CAAC;IAAEC,WAAAA,EAAa;AAAK,CAAA,CAAA;AAE3E;;;;IAKO,SAASE,wBAAAA,CAAyBC,OAAkC,EAAA;IACvE,OAAQR,CAAAA,UAAAA,CAAWS,GAAG,CAACD,UAAUE,KAAAA,IAAS,CAAA,IAAK,CAAA,GAAIJ,SAAAA,GAAYJ,IAAAA;AACnE;AAEA;;;;;AAKC,IACM,SAASS,gCAAAA,CAAiCH,OAAkC,EAAEI,QAAoB,EAAA;AACrG,IAAA,MAAM,EAAEC,OAAO,EAAE,GAAGC,oBAAAA,CAAqBN,OAAAA,CAAAA;AACzC,IAAA,MAAMO,WAAW,IAAMH,QAAAA,EAAAA;IACvBC,OAAAA,CAAQG,gBAAgB,CAAC,QAAA,EAAUD,QAAAA,CAAAA;AACnC,IAAA,OAAO,IAAMF,OAAAA,CAAQI,mBAAmB,CAAC,QAAA,EAAUF,QAAAA,CAAAA;AACvD;AAEO,SAASG,sBAAsBV,OAAkC,EAAA;AACpE,IAAA,MAAMW,YAAYL,oBAAAA,CAAqBN,OAAAA,CAAAA;AACvC,IAAA,IAAI,EAAEW,SAAAA,CAAUT,KAAK,KAAK,CAAA,EAAG;AACzBS,QAAAA,SAAAA,CAAUN,OAAO,CAACO,aAAa,CAAC,IAAIC,KAAAA,CAAM,QAAA,CAAA,CAAA;AAC9C,IAAA;IAEA,OAAO,IAAA;AACH,QAAA,IAAI,EAAEF,SAAAA,CAAUT,KAAK,KAAK,CAAA,EAAG;AACzBS,YAAAA,SAAAA,CAAUN,OAAO,CAACO,aAAa,CAAC,IAAIC,KAAAA,CAAM,QAAA,CAAA,CAAA;AAC9C,QAAA;AACJ,IAAA,CAAA;AACJ;AAEA,SAASP,qBAAqBN,OAAkC,EAAA;IAC5D,IAAIW,SAAAA,GAAYnB,UAAAA,CAAWS,GAAG,CAACD,OAAAA,CAAAA;AAC/B,IAAA,IAAI,CAACW,SAAAA,EAAW;QACZA,SAAAA,GAAY;YAAET,KAAAA,EAAO,CAAA;AAAGG,YAAAA,OAAAA,EAAS,IAAIS,WAAAA;AAAc,SAAA;QACnDtB,UAAAA,CAAWuB,GAAG,CAACf,OAAAA,EAASW,SAAAA,CAAAA;AAC5B,IAAA;IACA,OAAOA,SAAAA;AACX;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"and_execution_rejects.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/and_execution_rejects.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { given } from '../../../given.js';
|
|
2
|
+
import { getCommandExecutionState } from '../../index.js';
|
|
3
|
+
import { a_command } from '../given/a_command.js';
|
|
4
|
+
describe('when executing a command and execution rejects', given(a_command, context => {
|
|
5
|
+
const error = new Error('Could not build request headers');
|
|
6
|
+
let rejection;
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
rejection = undefined;
|
|
9
|
+
context.fetchHelper.stubFetch();
|
|
10
|
+
context.command.setHttpHeadersCallback(() => { throw error; });
|
|
11
|
+
try {
|
|
12
|
+
await context.command.execute();
|
|
13
|
+
}
|
|
14
|
+
catch (caught) {
|
|
15
|
+
rejection = caught;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
afterEach(() => context.fetchStub.restore());
|
|
19
|
+
it('should reject with the original error', () => expect(rejection).to.equal(error));
|
|
20
|
+
it('should be idle after rejection', () => getCommandExecutionState(context.command).isExecuting.should.be.false);
|
|
21
|
+
}));
|
|
22
|
+
//# sourceMappingURL=and_execution_rejects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"and_execution_rejects.js","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/and_execution_rejects.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,QAAQ,CAAC,gDAAgD,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE;IAClF,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAC3D,IAAI,SAAkB,CAAC;IAEvB,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,SAAS,GAAG,SAAS,CAAC;QACtB,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;QAChC,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,GAAG,EAAE,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,IAAI,CAAC;YACD,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACpC,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YACd,SAAS,GAAG,MAAM,CAAC;QACvB,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;IAE7C,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IACrF,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE,CAAC,wBAAwB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AACtH,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_overlapping_executions.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_overlapping_executions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { given } from '../../../given.js';
|
|
2
|
+
import { CommandResult, getCommandExecutionState, subscribeToCommandExecutionState } from '../../index.js';
|
|
3
|
+
import { a_command } from '../given/a_command.js';
|
|
4
|
+
import { SomeCommand } from '../SomeCommand.js';
|
|
5
|
+
describe('when executing a command with overlapping executions', given(a_command, context => {
|
|
6
|
+
let beforeExecution;
|
|
7
|
+
let whileOneIsPending;
|
|
8
|
+
let whileBothArePending;
|
|
9
|
+
let otherCommandIsExecuting;
|
|
10
|
+
let afterOneFails;
|
|
11
|
+
let afterBothSettle;
|
|
12
|
+
let notifications;
|
|
13
|
+
let earlyNotifications;
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
notifications = [];
|
|
16
|
+
earlyNotifications = [];
|
|
17
|
+
const { command } = context;
|
|
18
|
+
const fetchStub = context.fetchHelper.stubFetch();
|
|
19
|
+
const readState = () => getCommandExecutionState(command).isExecuting;
|
|
20
|
+
const unsubscribe = subscribeToCommandExecutionState(command, () => notifications.push(readState()));
|
|
21
|
+
const unsubscribeEarly = subscribeToCommandExecutionState(command, () => earlyNotifications.push(readState()));
|
|
22
|
+
const firstRequest = Promise.withResolvers();
|
|
23
|
+
const secondRequest = Promise.withResolvers();
|
|
24
|
+
fetchStub.onFirstCall().returns(firstRequest.promise);
|
|
25
|
+
fetchStub.onSecondCall().returns(secondRequest.promise);
|
|
26
|
+
beforeExecution = readState();
|
|
27
|
+
const first = command.execute();
|
|
28
|
+
whileOneIsPending = readState();
|
|
29
|
+
unsubscribeEarly();
|
|
30
|
+
const second = command.execute();
|
|
31
|
+
whileBothArePending = readState();
|
|
32
|
+
otherCommandIsExecuting = getCommandExecutionState(new SomeCommand()).isExecuting;
|
|
33
|
+
firstRequest.reject(new Error('Network error'));
|
|
34
|
+
await first;
|
|
35
|
+
afterOneFails = readState();
|
|
36
|
+
secondRequest.resolve(Response.json({ ...CommandResult.empty, correlationId: CommandResult.empty.correlationId.toString() }));
|
|
37
|
+
await second;
|
|
38
|
+
afterBothSettle = readState();
|
|
39
|
+
unsubscribe();
|
|
40
|
+
});
|
|
41
|
+
afterEach(() => context.fetchStub.restore());
|
|
42
|
+
it('should be idle initially', () => beforeExecution.should.be.false);
|
|
43
|
+
it('should be executing while one or both executions are pending', () => {
|
|
44
|
+
whileOneIsPending.should.be.true;
|
|
45
|
+
whileBothArePending.should.be.true;
|
|
46
|
+
});
|
|
47
|
+
it('should not report an execution for another instance of the same command', () => otherCommandIsExecuting.should.be.false);
|
|
48
|
+
it('should stay executing when one of the pending executions fails', () => afterOneFails.should.be.true);
|
|
49
|
+
it('should be idle after the last execution settles', () => afterBothSettle.should.be.false);
|
|
50
|
+
it('should notify subscribers only when the execution state changes', () => notifications.should.deep.equal([true, false]));
|
|
51
|
+
it('should stop notifying an unsubscribed listener', () => earlyNotifications.should.deep.equal([true]));
|
|
52
|
+
}));
|
|
53
|
+
//# sourceMappingURL=with_overlapping_executions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_overlapping_executions.js","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_overlapping_executions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,gCAAgC,EAAE,MAAM,gBAAgB,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,QAAQ,CAAC,sDAAsD,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE;IACxF,IAAI,eAAwB,CAAC;IAC7B,IAAI,iBAA0B,CAAC;IAC/B,IAAI,mBAA4B,CAAC;IACjC,IAAI,uBAAgC,CAAC;IACrC,IAAI,aAAsB,CAAC;IAC3B,IAAI,eAAwB,CAAC;IAC7B,IAAI,aAAwB,CAAC;IAC7B,IAAI,kBAA6B,CAAC;IAElC,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,aAAa,GAAG,EAAE,CAAC;QACnB,kBAAkB,GAAG,EAAE,CAAC;QACxB,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAC5B,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;QAClD,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC;QACtE,MAAM,WAAW,GAAG,gCAAgC,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QACrG,MAAM,gBAAgB,GAAG,gCAAgC,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAC/G,MAAM,YAAY,G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iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;QACjC,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,yEAAyE,EAAE,GAAG,EAAE,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC7H,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACzG,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC7F,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5H,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC7G,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_pending_validation.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating/with_pending_validation.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { given } from '../../../given.js';
|
|
2
|
+
import { CommandResult, getCommandExecutionState } from '../../index.js';
|
|
3
|
+
import { a_command } from '../given/a_command.js';
|
|
4
|
+
describe('when validating a command while validation is pending', given(a_command, context => {
|
|
5
|
+
let whileValidationIsPending;
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
const request = Promise.withResolvers();
|
|
8
|
+
context.fetchHelper.stubFetch().returns(request.promise);
|
|
9
|
+
const validation = context.command.validate();
|
|
10
|
+
whileValidationIsPending = getCommandExecutionState(context.command).isExecuting;
|
|
11
|
+
request.resolve(Response.json({ ...CommandResult.empty, correlationId: CommandResult.empty.correlationId.toString() }));
|
|
12
|
+
await validation;
|
|
13
|
+
});
|
|
14
|
+
afterEach(() => context.fetchStub.restore());
|
|
15
|
+
it('should not report an execution in progress', () => whileValidationIsPending.should.be.false);
|
|
16
|
+
}));
|
|
17
|
+
//# sourceMappingURL=with_pending_validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_pending_validation.js","sourceRoot":"","sources":["../../../../../commands/for_Command/when_validating/with_pending_validation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,QAAQ,CAAC,uDAAuD,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE;IACzF,IAAI,wBAAiC,CAAC;IAEtC,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,EAAY,CAAC;QAClD,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACzD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC9C,wBAAwB,GAAG,wBAAwB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC;QACjF,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,aAAa,CAAC,KAAK,EAAE,aAAa,EAAE,aAAa,CAAC,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;QACxH,MAAM,UAAU,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;IAE7C,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE,CAAC,wBAAwB,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AACrG,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -4,5 +4,7 @@ export * from './ICommandResult.js';
|
|
|
4
4
|
export * from './CommandResult.js';
|
|
5
5
|
export * from './CommandResults.js';
|
|
6
6
|
export * from './CommandValidator.js';
|
|
7
|
+
export { getCommandExecutionState, subscribeToCommandExecutionState } from './CommandExecutionState.js';
|
|
8
|
+
export type { CommandExecutionState } from './CommandExecutionState.js';
|
|
7
9
|
import '../validation/index.js';
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../commands/index.ts"],"names":[],"mappings":"AAGA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,OAAO,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../commands/index.ts"],"names":[],"mappings":"AAGA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,gCAAgC,EAAE,MAAM,4BAA4B,CAAC;AACxG,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,wBAAwB,CAAC"}
|
|
@@ -2,6 +2,7 @@ export { Command } from './Command.js';
|
|
|
2
2
|
export { CommandResult } from './CommandResult.js';
|
|
3
3
|
export { CommandResults } from './CommandResults.js';
|
|
4
4
|
export { CommandValidator } from './CommandValidator.js';
|
|
5
|
+
export { getCommandExecutionState, subscribeToCommandExecutionState } from './CommandExecutionState.js';
|
|
5
6
|
import '../validation/RuleBuilderExtensions.js';
|
|
6
7
|
|
|
7
8
|
// Copyright (c) Cratis. All rights reserved.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../commands/index.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\nexport * from './ICommand.js';\nexport * from './Command.js';\nexport * from './ICommandResult.js';\nexport * from './CommandResult.js';\nexport * from './CommandResults.js';\nexport * from './CommandValidator.js';\nimport '../validation/index.js';"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../commands/index.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\nexport * from './ICommand.js';\nexport * from './Command.js';\nexport * from './ICommandResult.js';\nexport * from './CommandResult.js';\nexport * from './CommandResults.js';\nexport * from './CommandValidator.js';\nexport { getCommandExecutionState, subscribeToCommandExecutionState } from './CommandExecutionState.js';\nexport type { CommandExecutionState } from './CommandExecutionState.js';\nimport '../validation/index.js';"],"names":[],"mappings":";;;;;;;AAAA;AACA"}
|