@cratis/arc 23.8.0 → 23.8.2
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 +4 -0
- package/commands/for_Command/when_registering_the_same_property_changed_callback_twice.ts +47 -0
- package/dist/cjs/commands/Command.d.ts.map +1 -1
- package/dist/cjs/commands/Command.js +3 -0
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.js +6 -5
- package/dist/cjs/queries/QueryInstanceCache.js.map +1 -1
- package/dist/esm/commands/Command.d.ts.map +1 -1
- package/dist/esm/commands/Command.js +3 -0
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/for_Command/when_registering_the_same_property_changed_callback_twice.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_registering_the_same_property_changed_callback_twice.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_registering_the_same_property_changed_callback_twice.js +36 -0
- package/dist/esm/commands/for_Command/when_registering_the_same_property_changed_callback_twice.js.map +1 -0
- package/dist/esm/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/esm/queries/QueryInstanceCache.js +6 -5
- package/dist/esm/queries/QueryInstanceCache.js.map +1 -1
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.js +1 -1
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.js.map +1 -1
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_retained_entries.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_retained_entries.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_retained_entries.js +44 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_retained_entries.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/queries/QueryInstanceCache.ts +6 -6
- package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.ts +1 -1
- package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_retained_entries.ts +52 -0
package/commands/Command.ts
CHANGED
|
@@ -328,6 +328,10 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
|
|
|
328
328
|
|
|
329
329
|
/** @inheritdoc */
|
|
330
330
|
onPropertyChanged(callback: PropertyChanged, thisArg: object) {
|
|
331
|
+
if (this._callbacks.some(_ => _.callback.deref() === callback && _.thisArg.deref() === thisArg)) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
|
|
331
335
|
this._callbacks.push({
|
|
332
336
|
callback: new WeakRef(callback),
|
|
333
337
|
thisArg: new WeakRef(thisArg)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import sinon from 'sinon';
|
|
5
|
+
import { SomeCommand } from './SomeCommand.js';
|
|
6
|
+
|
|
7
|
+
describe('when registering the same property changed callback twice', () => {
|
|
8
|
+
it('should notify the callback once per change', () => {
|
|
9
|
+
const command = new SomeCommand();
|
|
10
|
+
const callback = sinon.spy();
|
|
11
|
+
command.onPropertyChanged(callback, command);
|
|
12
|
+
command.onPropertyChanged(callback, command);
|
|
13
|
+
|
|
14
|
+
command.propertyChanged('someProperty');
|
|
15
|
+
|
|
16
|
+
callback.calledOnceWithExactly('someProperty').should.be.true;
|
|
17
|
+
command.propertyChanged('someProperty');
|
|
18
|
+
callback.callCount.should.equal(2);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should retain registrations with different receivers', () => {
|
|
22
|
+
const command = new SomeCommand();
|
|
23
|
+
const callback = sinon.spy();
|
|
24
|
+
const otherReceiver = {};
|
|
25
|
+
command.onPropertyChanged(callback, command);
|
|
26
|
+
command.onPropertyChanged(callback, otherReceiver);
|
|
27
|
+
|
|
28
|
+
command.propertyChanged('someProperty');
|
|
29
|
+
|
|
30
|
+
callback.calledTwice.should.be.true;
|
|
31
|
+
callback.calledOn(command).should.be.true;
|
|
32
|
+
callback.calledOn(otherReceiver).should.be.true;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should retain different callbacks for the same receiver', () => {
|
|
36
|
+
const command = new SomeCommand();
|
|
37
|
+
const first = sinon.spy();
|
|
38
|
+
const second = sinon.spy();
|
|
39
|
+
command.onPropertyChanged(first, command);
|
|
40
|
+
command.onPropertyChanged(second, command);
|
|
41
|
+
|
|
42
|
+
command.propertyChanged('someProperty');
|
|
43
|
+
|
|
44
|
+
first.calledOnce.should.be.true;
|
|
45
|
+
second.calledOnce.should.be.true;
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Command.d.ts","sourceRoot":"","sources":["../../../commands/Command.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAInE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAcrF,8BAAsB,OAAO,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,YAAW,QAAQ,CAAC,eAAe,EAAE,gBAAgB,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AAO,CAAC,YAAY;YAuBN,cAAc;IA8B5B,KAAK,IAAI,IAAI,CAOZ;IAGD,gBAAgB,CAAC,MAAM,EAAE,eAAe,QASvC;IAGD,iCAAiC,SAGhC;IAED,OAAO,CAAC,oBAAoB;IAY5B,aAAa,IAAI,IAAI,CAKpB;IAGD,IAAI,UAAU,YAEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM,QAY/B;IAGD,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,QAS3D;IAED,OAAO,CAAC,gBAAgB;CAM3B"}
|
|
@@ -266,6 +266,9 @@ var ValidationResultReasonDetail = require('../validation/ValidationResultReason
|
|
|
266
266
|
});
|
|
267
267
|
}
|
|
268
268
|
/** @inheritdoc */ onPropertyChanged(callback, thisArg) {
|
|
269
|
+
if (this._callbacks.some((_)=>_.callback.deref() === callback && _.thisArg.deref() === thisArg)) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
269
272
|
this._callbacks.push({
|
|
270
273
|
callback: new WeakRef(callback),
|
|
271
274
|
thisArg: new WeakRef(thisArg)
|
|
@@ -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 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","WeakRef","some"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AAsBA;;;;AAIC,IACM,MAAeA,OAAAA,CAAAA;;;AAClB;;AAEC,QACD,OAAgBC,aAAAA,GAA+BC,2BAAAA,CAAcC,KAAK;IAE1DC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;4DAGR,UAASC;AACT,2DACSC,KAAAA,GAAkB,EAAE;wFAE7B,yBAASC;AAIDC,IAAAA,cAAAA,GAAyB,EAAC;AAC1BC,IAAAA,WAAAA,GAAc,KAAA;AACdC,IAAAA,UAAAA,GAAyB,EAAE;AAEnC;;;;AAIC,QACD,YAAY,aAASC,GAA6BC,MAAM,EAAWC,yBAAkC,CAAE;aAAlFF,aAAAA,GAAAA,aAAAA;aAA8CE,yBAAAA,GAAAA,yBAAAA;AAC/D,QAAA,IAAI,CAACZ,aAAa,GAAGa,eAAAA,CAAQC,YAAY,IAAI,EAAA;AAC7C,QAAA,IAAI,CAACb,YAAY,GAAGY,eAAAA,CAAQE,WAAW,IAAI,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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,CAACrG,UAAU,CAACwD,IAAI,CAAC;AACjB5C,YAAAA,QAAAA,EAAU,IAAI4F,OAAAA,CAAQ5F,QAAAA,CAAAA;AACtByF,YAAAA,OAAAA,EAAS,IAAIG,OAAAA,CAAQH,OAAAA;AACzB,SAAA,CAAA;AACJ,IAAA;IAEQpE,gBAAAA,GAAmB;QACvB,IAAI,CAAClC,WAAW,GAAG,IAAI,CAACgD,mBAAmB,CAAC0D,IAAI,CAACxD,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 { 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,2BAAAA,CAAcC,KAAK;IAE1DC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;4DAGR,UAASC;AACT,2DACSC,KAAAA,GAAkB,EAAE;wFAE7B,yBAASC;AAIDC,IAAAA,cAAAA,GAAyB,EAAC;AAC1BC,IAAAA,WAAAA,GAAc,KAAA;AACdC,IAAAA,UAAAA,GAAyB,EAAE;AAEnC;;;;AAIC,QACD,YAAY,aAASC,GAA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AAG,EAAE,aAAa,EAClB,QAAQ,EAAE,kBAAkB,CAAC,SAAS,CAAC,GACxC,IAAI,CAMN;IAQD,cAAc,CAAC,SAAS,EACpB,GAAG,EAAE,aAAa,EAClB,QAAQ,EAAE,kBAAkB,CAAC,SAAS,CAAC,GACxC,IAAI,CAMN;IAQD,WAAW,CAAC,GAAG,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAO1D;IAOD,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAExC;IAUD,OAAO,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAuBhC;IAOD,GAAG,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAE/B;IAYD,wBAAwB,IAAI,IAAI,CAI/B;IAED,OAAO,CAAC,aAAa;IAWrB,OAAO,IAAI,IAAI,CAQd;IAWD,YAAY,IAAI,IAAI,CASnB;IAQD,oBAAoB,IAAI,IAAI,CAK3B;IAMD,sBAAsB,IAAI,gBAAgB,CAwCzC;CACJ"}
|
|
@@ -217,7 +217,7 @@ var deepEqual = require('../deepEqual.js');
|
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
219
|
* Tears down all active subscriptions and marks every entry as not subscribed,
|
|
220
|
-
* but preserves entries, subscriber counts, and
|
|
220
|
+
* but preserves entries, subscriber counts, listeners, and pending eviction timers. This allows
|
|
221
221
|
* hooks whose effects re-run afterward to detect that the entry is no longer
|
|
222
222
|
* subscribed and re-establish a fresh connection.
|
|
223
223
|
*
|
|
@@ -230,10 +230,6 @@ var deepEqual = require('../deepEqual.js');
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
teardownEntry(entry) {
|
|
233
|
-
if (entry.pendingCleanup !== undefined) {
|
|
234
|
-
clearTimeout(entry.pendingCleanup);
|
|
235
|
-
entry.pendingCleanup = undefined;
|
|
236
|
-
}
|
|
237
233
|
entry.subscribed = false;
|
|
238
234
|
entry.teardown?.();
|
|
239
235
|
entry.teardown = undefined;
|
|
@@ -244,6 +240,11 @@ var deepEqual = require('../deepEqual.js');
|
|
|
244
240
|
* unmounts permanently so that all query connections are closed synchronously.
|
|
245
241
|
*/ dispose() {
|
|
246
242
|
this.teardownAllSubscriptions();
|
|
243
|
+
for (const entry of this._entries.values()){
|
|
244
|
+
if (entry.pendingCleanup !== undefined) {
|
|
245
|
+
clearTimeout(entry.pendingCleanup);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
247
248
|
this._entries.clear();
|
|
248
249
|
}
|
|
249
250
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryInstanceCache.js","sources":["../../../queries/QueryInstanceCache.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 { QueryResultWithState } from './QueryResultWithState.js';\nimport type {\n CacheDiagnostics,\n CacheEntryDiagnostics,\n} from './ObservableQueryDiagnosticsSnapshot.js';\nimport { reconcileQueryData } from './reconcileQueryData.js';\nimport { deepEqual } from '../deepEqual.js';\n\n/**\n * Represents a key that uniquely identifies a query instance in the cache, based on the query type name and its serialized arguments.\n */\nexport type QueryCacheKey = string;\n\n/**\n * Callback invoked when the cached result for an entry changes.\n */\nexport type QueryCacheListener<TDataType> = (\n result: QueryResultWithState<TDataType>,\n) => void;\n\n/**\n * Represents a single entry in the {@link QueryInstanceCache}.\n * @template TDataType The type of data returned by the query.\n */\nexport interface QueryCacheEntry<TDataType> {\n /**\n * The cached query instance.\n */\n readonly instance: unknown;\n\n /**\n * The last result received from the query, if any.\n */\n lastResult?: QueryResultWithState<TDataType>;\n\n /**\n * The number of active subscribers holding a reference to this entry.\n */\n subscriberCount: number;\n\n /**\n * Set of listener callbacks that are notified when {@link lastResult} changes.\n */\n readonly listeners: Set<QueryCacheListener<TDataType>>;\n\n /**\n * Cleanup function returned by the first subscriber that starts the query connection.\n * Called when the last subscriber releases the entry.\n */\n teardown?: () => void;\n\n /**\n * Whether an active subscription has been established for this entry.\n */\n subscribed: boolean;\n\n /**\n * Timer handle for deferred cleanup. Allows React StrictMode re-mounts (in any build\n * environment) to cancel the pending teardown so the connection is reused instead of\n * torn down and recreated.\n */\n pendingCleanup?: ReturnType<typeof setTimeout>;\n}\n\n/**\n * Provides a cache for query instances, keyed by query type and serialized arguments.\n *\n * Two callers requesting the same query type with identical arguments receive the same\n * cached instance and immediately see the last known result — without an additional\n * round trip to the server. When the last subscriber releases its reference the entry\n * is evicted.\n */\nexport class QueryInstanceCache {\n private readonly _entries = new Map<QueryCacheKey, QueryCacheEntry<unknown>>();\n private _pendingDispose?: ReturnType<typeof setTimeout>;\n\n /**\n * Initializes a new instance of {@link QueryInstanceCache}.\n * @param retentionMs How long in milliseconds to keep a cache entry alive after the last\n * subscriber releases it before evicting the subscription and cached data. A non-zero\n * value lets users navigate away and back without losing cached data. Defaults to\n * 30 000 ms. Pass 0 for immediate eviction.\n */\n constructor(private readonly _retentionMs: number = 30_000) {}\n\n /**\n * Builds the cache key for a query.\n * @param queryTypeName The stable type name for the query. Use the instance's `queryName`\n * (a hardcoded fully-qualified string in generated proxies) rather than {@link Function.name},\n * which is unstable under minification.\n * @param args Optional arguments supplied to the query.\n * @returns A stable string key.\n */\n buildKey(queryTypeName: string, args?: object): QueryCacheKey {\n if (!args || Object.keys(args).length === 0) {\n return `${queryTypeName}::`;\n }\n\n const sorted = Object.keys(args)\n .sort()\n .reduce<Record<string, unknown>>((accumulator, key) => {\n accumulator[key] = (args as Record<string, unknown>)[key];\n return accumulator;\n }, {});\n\n return `${queryTypeName}::${JSON.stringify(sorted)}`;\n }\n\n /**\n * Returns a cached instance for the given key, or creates a new one using the provided factory.\n * The subscriber count of the entry is incremented.\n * @template TInstance The type of the query instance.\n * @param key The cache key produced by {@link buildKey}.\n * @param factory A zero-argument factory that creates a fresh query instance when one is not yet cached.\n * @returns The cached (or newly created) instance and whether it was newly created.\n */\n getOrCreate<TInstance>(\n key: QueryCacheKey,\n factory: () => TInstance,\n ): { instance: TInstance; isNew: boolean } {\n if (!this._entries.has(key)) {\n const entry: QueryCacheEntry<unknown> = {\n instance: factory(),\n lastResult: undefined,\n subscriberCount: 0,\n listeners: new Set(),\n subscribed: false,\n };\n\n this._entries.set(key, entry);\n return { instance: entry.instance as TInstance, isNew: true };\n }\n\n const entry = this._entries.get(key)!;\n return { instance: entry.instance as TInstance, isNew: false };\n }\n\n /**\n * Increments the active subscriber count for the given key.\n * If a deferred cleanup was pending (from a recent {@link release}),\n * it is cancelled so the existing subscription is reused.\n * Call from `useEffect` setup to pair with {@link release} in the cleanup.\n * @param key The cache key produced by {@link buildKey}.\n */\n acquire(key: QueryCacheKey): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n if (entry.pendingCleanup !== undefined) {\n clearTimeout(entry.pendingCleanup);\n entry.pendingCleanup = undefined;\n }\n\n entry.subscriberCount++;\n }\n }\n\n /**\n * Returns the last cached result for the given key, or `undefined` if no result has been stored yet.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @returns The last {@link QueryResultWithState}, or `undefined`.\n */\n getLastResult<TDataType>(\n key: QueryCacheKey,\n ): QueryResultWithState<TDataType> | undefined {\n return this._entries.get(key)?.lastResult as\n | QueryResultWithState<TDataType>\n | undefined;\n }\n\n /**\n * Stores the most recent result for the given key and notifies all registered listeners.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param result The result to store.\n */\n setLastResult<TDataType>(\n key: QueryCacheKey,\n result: QueryResultWithState<TDataType>,\n ): void {\n const entry = this._entries.get(key);\n\n if (!entry) {\n return;\n }\n\n const previousResult = entry.lastResult as\n | QueryResultWithState<TDataType>\n | undefined;\n\n // Reconcile the incoming payload against the one already held so items that did not actually\n // change keep their previous references. A full snapshot — which is what the server re-sends\n // whenever a subscription is re-established — otherwise arrives as all-new references and\n // makes every consumer treat every item as changed.\n const reconciled =\n previousResult === undefined\n ? result\n : this.withReconciledData(previousResult, result);\n\n entry.lastResult = reconciled as QueryResultWithState<unknown>;\n\n // Reconciliation returns the previous data reference when nothing changed, so identity is\n // enough to detect it. Data and result metadata affect what the user sees; changeSet is\n // ephemeral and does not independently require a notification.\n if (\n previousResult !== undefined &&\n previousResult.data === reconciled.data &&\n this.hasEquivalentMetadata(previousResult, reconciled)\n ) {\n return;\n }\n\n for (const listener of entry.listeners) {\n (listener as QueryCacheListener<TDataType>)(reconciled);\n }\n }\n\n /**\n * Returns the incoming result with its data reconciled against the previous result, or the\n * incoming result unchanged when reconciliation found nothing to carry over.\n * @template TDataType The type of data returned by the query.\n * @param previous The previously held result.\n * @param next The freshly received result.\n * @returns A result whose data preserves references for everything that did not change.\n */\n private withReconciledData<TDataType>(\n previous: QueryResultWithState<TDataType>,\n next: QueryResultWithState<TDataType>,\n ): QueryResultWithState<TDataType> {\n const reconciledData = reconcileQueryData(previous.data, next.data);\n\n if (reconciledData === next.data) {\n return next;\n }\n\n return new QueryResultWithState<TDataType>(\n reconciledData,\n next.paging,\n next.isSuccess,\n next.isAuthorized,\n next.isValid,\n next.validationResults,\n next.hasExceptions,\n next.exceptionMessages,\n next.exceptionStackTrace,\n next.isPerforming,\n next.changeSet,\n next.isReady,\n next.authorizationFailureReason,\n next.isRetryable,\n );\n }\n\n private hasEquivalentMetadata<TDataType>(result: QueryResultWithState<TDataType>, previous: QueryResultWithState<TDataType>): boolean {\n return result.isPerforming === previous.isPerforming\n && result.isSuccess === previous.isSuccess\n && result.isReady === previous.isReady\n && result.isAuthorized === previous.isAuthorized\n && result.authorizationFailureReason === previous.authorizationFailureReason\n && result.isRetryable === previous.isRetryable\n && result.isValid === previous.isValid\n && result.hasExceptions === previous.hasExceptions\n && result.exceptionStackTrace === previous.exceptionStackTrace\n && deepEqual(result.paging, previous.paging)\n && deepEqual(result.exceptionMessages, previous.exceptionMessages)\n && deepEqual(result.validationResults, previous.validationResults);\n }\n\n /**\n * Registers a listener that is invoked whenever the cached result for the given key changes.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param listener The callback to register.\n */\n addListener<TDataType>(\n key: QueryCacheKey,\n listener: QueryCacheListener<TDataType>,\n ): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.listeners.add(listener as QueryCacheListener<unknown>);\n }\n }\n\n /**\n * Removes a previously registered listener.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param listener The callback to remove.\n */\n removeListener<TDataType>(\n key: QueryCacheKey,\n listener: QueryCacheListener<TDataType>,\n ): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.listeners.delete(listener as QueryCacheListener<unknown>);\n }\n }\n\n /**\n * Stores a teardown function for the given key and marks the entry as subscribed.\n * Called automatically when the last subscriber releases the entry.\n * @param key The cache key produced by {@link buildKey}.\n * @param teardown Cleanup function that disconnects the underlying query subscription.\n */\n setTeardown(key: QueryCacheKey, teardown: () => void): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.teardown = teardown;\n entry.subscribed = true;\n }\n }\n\n /**\n * Returns whether an active subscription exists for the given key.\n * @param key The cache key to check.\n * @returns `true` if a subscription has been established; `false` otherwise.\n */\n isSubscribed(key: QueryCacheKey): boolean {\n return this._entries.get(key)?.subscribed ?? false;\n }\n\n /**\n * Decrements the subscriber count for the given key. When the count reaches zero, both teardown\n * and eviction are deferred by one microtask so that React StrictMode re-mounts — in any build\n * environment — can re-acquire the entry and cancel the cleanup before the timeout fires. This\n * prevents an unnecessary disconnect/reconnect cycle during the synthetic unmount/remount that\n * StrictMode performs.\n * @param key The cache key produced by {@link buildKey}.\n */\n release(key: QueryCacheKey): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.subscriberCount--;\n\n if (entry.subscriberCount <= 0) {\n // Defer both teardown and eviction. React StrictMode re-mounts can cancel by\n // calling acquire() before the timeout fires. A non-zero _retentionMs keeps the\n // entry alive so users navigating back quickly see cached data immediately.\n entry.pendingCleanup = setTimeout(() => {\n const current = this._entries.get(key);\n\n if (current && current.subscriberCount <= 0) {\n current.subscribed = false;\n current.teardown?.();\n current.teardown = undefined;\n current.pendingCleanup = undefined;\n this._entries.delete(key);\n }\n }, this._retentionMs);\n }\n }\n }\n\n /**\n * Returns whether an entry exists for the given key.\n * @param key The cache key to check.\n * @returns `true` if an entry exists; `false` otherwise.\n */\n has(key: QueryCacheKey): boolean {\n return this._entries.has(key);\n }\n\n /**\n * Tears down all active subscriptions and marks every entry as not subscribed,\n * but preserves entries, subscriber counts, and listeners. This allows\n * hooks whose effects re-run afterward to detect that the entry is no longer\n * subscribed and re-establish a fresh connection.\n *\n * Use this when the underlying transport must be replaced (e.g. after an\n * authentication change that requires new WebSocket connections with updated\n * credentials).\n */\n teardownAllSubscriptions(): void {\n for (const [, entry] of this._entries) {\n this.teardownEntry(entry);\n }\n }\n\n private teardownEntry(entry: QueryCacheEntry<unknown>): void {\n if (entry.pendingCleanup !== undefined) {\n clearTimeout(entry.pendingCleanup);\n entry.pendingCleanup = undefined;\n }\n\n entry.subscribed = false;\n entry.teardown?.();\n entry.teardown = undefined;\n }\n\n /**\n * Immediately tears down all subscriptions, cancels any pending deferred cleanups,\n * and evicts all entries. Call when the owning component (e.g. the {@link Arc} provider)\n * unmounts permanently so that all query connections are closed synchronously.\n */\n dispose(): void {\n this.teardownAllSubscriptions();\n this._entries.clear();\n }\n\n /**\n * Schedules a deferred {@link dispose} using {@code setTimeout(0)}.\n *\n * This allows React StrictMode re-mounts to call {@link cancelPendingDispose}\n * before the dispose fires, avoiding the destruction of cache entries that child\n * effects are about to re-acquire.\n *\n * If a deferred dispose is already pending, it is replaced.\n */\n deferDispose(): void {\n if (this._pendingDispose !== undefined) {\n clearTimeout(this._pendingDispose);\n }\n\n this._pendingDispose = setTimeout(() => {\n this._pendingDispose = undefined;\n this.dispose();\n }, 0);\n }\n\n /**\n * Cancels a pending deferred dispose scheduled by {@link deferDispose}.\n *\n * Call from the {@code useEffect} setup phase so that a StrictMode re-mount\n * prevents the synthetic unmount's deferred dispose from firing.\n */\n cancelPendingDispose(): void {\n if (this._pendingDispose !== undefined) {\n clearTimeout(this._pendingDispose);\n this._pendingDispose = undefined;\n }\n }\n\n /**\n * Returns a diagnostics snapshot of the current cache state.\n * @returns A {@link CacheDiagnostics} describing all entries.\n */\n getDiagnosticsSnapshot(): CacheDiagnostics {\n const entries: CacheEntryDiagnostics[] = [];\n let totalBytes = 0;\n let unhealthyCount = 0;\n\n for (const [key, entry] of this._entries) {\n const colonIndex = key.indexOf('::');\n const queryName = colonIndex >= 0 ? key.substring(0, colonIndex) : key;\n\n let estimatedBytes = 0;\n try {\n if (entry.lastResult !== undefined) {\n estimatedBytes = JSON.stringify(entry.lastResult).length;\n }\n } catch {\n // Ignore serialization errors\n }\n\n if (entry.subscriberCount > 0 && !entry.subscribed) {\n unhealthyCount++;\n }\n\n totalBytes += estimatedBytes;\n entries.push({\n key,\n queryName,\n subscriberCount: entry.subscriberCount,\n listenerCount: entry.listeners.size,\n subscribed: entry.subscribed,\n hasResult: entry.lastResult !== undefined,\n estimatedBytes,\n });\n }\n\n return {\n healthy: unhealthyCount === 0,\n entryCount: this._entries.size,\n estimatedBytes: totalBytes,\n entries,\n };\n }\n}\n"],"names":["QueryInstanceCache","_entries","Map","_pendingDispose","_retentionMs","buildKey","queryTypeName","args","Object","keys","length","sorted","sort","reduce","accumulator","key","JSON","stringify","getOrCreate","factory","has","entry","instance","lastResult","undefined","subscriberCount","listeners","Set","subscribed","set","isNew","get","acquire","pendingCleanup","clearTimeout","getLastResult","setLastResult","result","previousResult","reconciled","withReconciledData","data","hasEquivalentMetadata","listener","previous","next","reconciledData","reconcileQueryData","QueryResultWithState","paging","isSuccess","isAuthorized","isValid","validationResults","hasExceptions","exceptionMessages","exceptionStackTrace","isPerforming","changeSet","isReady","authorizationFailureReason","isRetryable","deepEqual","addListener","add","removeListener","delete","setTeardown","teardown","isSubscribed","release","setTimeout","current","teardownAllSubscriptions","teardownEntry","dispose","clear","deferDispose","cancelPendingDispose","getDiagnosticsSnapshot","entries","totalBytes","unhealthyCount","colonIndex","indexOf","queryName","substring","estimatedBytes","push","listenerCount","size","hasResult","healthy","entryCount"],"mappings":";;;;;;AAAA;AACA;AAkEA;;;;;;;AAOC,IACM,MAAMA,kBAAAA,CAAAA;;AACQC,IAAAA,QAAAA,GAAW,IAAIC,GAAAA,EAAAA;IACxBC,eAAAA;AAER;;;;;;AAMC,QACD,WAAA,CAA6BC,YAAAA,GAAuB,MAAM,CAAE;aAA/BA,YAAAA,GAAAA,YAAAA;AAAgC,IAAA;AAE7D;;;;;;;AAOC,QACDC,QAAAA,CAASC,aAAqB,EAAEC,IAAa,EAAiB;QAC1D,IAAI,CAACA,QAAQC,MAAAA,CAAOC,IAAI,CAACF,IAAAA,CAAAA,CAAMG,MAAM,KAAK,CAAA,EAAG;YACzC,OAAO,CAAA,EAAGJ,aAAAA,CAAc,EAAE,CAAC;AAC/B,QAAA;QAEA,MAAMK,MAAAA,GAASH,MAAAA,CAAOC,IAAI,CAACF,IAAAA,CAAAA,CACtBK,IAAI,EAAA,CACJC,MAAM,CAA0B,CAACC,WAAAA,EAAaC,GAAAA,GAAAA;AAC3CD,YAAAA,WAAW,CAACC,GAAAA,CAAI,GAAG,IAAiC,CAACA,GAAAA,CAAI;YACzD,OAAOD,WAAAA;AACX,QAAA,CAAA,EAAG,EAAC,CAAA;AAER,QAAA,OAAO,GAAGR,aAAAA,CAAc,EAAE,EAAEU,IAAAA,CAAKC,SAAS,CAACN,MAAAA,CAAAA,CAAAA,CAAS;AACxD,IAAA;AAEA;;;;;;;AAOC,QACDO,WAAAA,CACIH,GAAkB,EAClBI,OAAwB,EACe;AACvC,QAAA,IAAI,CAAC,IAAI,CAAClB,QAAQ,CAACmB,GAAG,CAACL,GAAAA,CAAAA,EAAM;AACzB,YAAA,MAAMM,KAAAA,GAAkC;gBACpCC,QAAAA,EAAUH,OAAAA,EAAAA;gBACVI,UAAAA,EAAYC,SAAAA;gBACZC,eAAAA,EAAiB,CAAA;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A,CAAMK,SAAS,CAACgE,IAAI;AACnC9D,gBAAAA,UAAAA,EAAYP,MAAMO,UAAU;gBAC5B+D,SAAAA,EAAWtE,KAAAA,CAAME,UAAU,KAAKC,SAAAA;AAChC+D,gBAAAA;AACJ,aAAA,CAAA;AACJ,QAAA;QAEA,OAAO;AACHK,YAAAA,OAAAA,EAASV,cAAAA,KAAmB,CAAA;AAC5BW,YAAAA,UAAAA,EAAY,IAAI,CAAC5F,QAAQ,CAACyF,IAAI;YAC9BH,cAAAA,EAAgBN,UAAAA;AAChBD,YAAAA;AACJ,SAAA;AACJ,IAAA;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"QueryInstanceCache.js","sources":["../../../queries/QueryInstanceCache.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 { QueryResultWithState } from './QueryResultWithState.js';\nimport type {\n CacheDiagnostics,\n CacheEntryDiagnostics,\n} from './ObservableQueryDiagnosticsSnapshot.js';\nimport { reconcileQueryData } from './reconcileQueryData.js';\nimport { deepEqual } from '../deepEqual.js';\n\n/**\n * Represents a key that uniquely identifies a query instance in the cache, based on the query type name and its serialized arguments.\n */\nexport type QueryCacheKey = string;\n\n/**\n * Callback invoked when the cached result for an entry changes.\n */\nexport type QueryCacheListener<TDataType> = (\n result: QueryResultWithState<TDataType>,\n) => void;\n\n/**\n * Represents a single entry in the {@link QueryInstanceCache}.\n * @template TDataType The type of data returned by the query.\n */\nexport interface QueryCacheEntry<TDataType> {\n /**\n * The cached query instance.\n */\n readonly instance: unknown;\n\n /**\n * The last result received from the query, if any.\n */\n lastResult?: QueryResultWithState<TDataType>;\n\n /**\n * The number of active subscribers holding a reference to this entry.\n */\n subscriberCount: number;\n\n /**\n * Set of listener callbacks that are notified when {@link lastResult} changes.\n */\n readonly listeners: Set<QueryCacheListener<TDataType>>;\n\n /**\n * Cleanup function returned by the first subscriber that starts the query connection.\n * Called when the last subscriber releases the entry.\n */\n teardown?: () => void;\n\n /**\n * Whether an active subscription has been established for this entry.\n */\n subscribed: boolean;\n\n /**\n * Timer handle for deferred cleanup. Allows React StrictMode re-mounts (in any build\n * environment) to cancel the pending teardown so the connection is reused instead of\n * torn down and recreated.\n */\n pendingCleanup?: ReturnType<typeof setTimeout>;\n}\n\n/**\n * Provides a cache for query instances, keyed by query type and serialized arguments.\n *\n * Two callers requesting the same query type with identical arguments receive the same\n * cached instance and immediately see the last known result — without an additional\n * round trip to the server. When the last subscriber releases its reference the entry\n * is evicted.\n */\nexport class QueryInstanceCache {\n private readonly _entries = new Map<QueryCacheKey, QueryCacheEntry<unknown>>();\n private _pendingDispose?: ReturnType<typeof setTimeout>;\n\n /**\n * Initializes a new instance of {@link QueryInstanceCache}.\n * @param retentionMs How long in milliseconds to keep a cache entry alive after the last\n * subscriber releases it before evicting the subscription and cached data. A non-zero\n * value lets users navigate away and back without losing cached data. Defaults to\n * 30 000 ms. Pass 0 for immediate eviction.\n */\n constructor(private readonly _retentionMs: number = 30_000) {}\n\n /**\n * Builds the cache key for a query.\n * @param queryTypeName The stable type name for the query. Use the instance's `queryName`\n * (a hardcoded fully-qualified string in generated proxies) rather than {@link Function.name},\n * which is unstable under minification.\n * @param args Optional arguments supplied to the query.\n * @returns A stable string key.\n */\n buildKey(queryTypeName: string, args?: object): QueryCacheKey {\n if (!args || Object.keys(args).length === 0) {\n return `${queryTypeName}::`;\n }\n\n const sorted = Object.keys(args)\n .sort()\n .reduce<Record<string, unknown>>((accumulator, key) => {\n accumulator[key] = (args as Record<string, unknown>)[key];\n return accumulator;\n }, {});\n\n return `${queryTypeName}::${JSON.stringify(sorted)}`;\n }\n\n /**\n * Returns a cached instance for the given key, or creates a new one using the provided factory.\n * The subscriber count of the entry is incremented.\n * @template TInstance The type of the query instance.\n * @param key The cache key produced by {@link buildKey}.\n * @param factory A zero-argument factory that creates a fresh query instance when one is not yet cached.\n * @returns The cached (or newly created) instance and whether it was newly created.\n */\n getOrCreate<TInstance>(\n key: QueryCacheKey,\n factory: () => TInstance,\n ): { instance: TInstance; isNew: boolean } {\n if (!this._entries.has(key)) {\n const entry: QueryCacheEntry<unknown> = {\n instance: factory(),\n lastResult: undefined,\n subscriberCount: 0,\n listeners: new Set(),\n subscribed: false,\n };\n\n this._entries.set(key, entry);\n return { instance: entry.instance as TInstance, isNew: true };\n }\n\n const entry = this._entries.get(key)!;\n return { instance: entry.instance as TInstance, isNew: false };\n }\n\n /**\n * Increments the active subscriber count for the given key.\n * If a deferred cleanup was pending (from a recent {@link release}),\n * it is cancelled so the existing subscription is reused.\n * Call from `useEffect` setup to pair with {@link release} in the cleanup.\n * @param key The cache key produced by {@link buildKey}.\n */\n acquire(key: QueryCacheKey): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n if (entry.pendingCleanup !== undefined) {\n clearTimeout(entry.pendingCleanup);\n entry.pendingCleanup = undefined;\n }\n\n entry.subscriberCount++;\n }\n }\n\n /**\n * Returns the last cached result for the given key, or `undefined` if no result has been stored yet.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @returns The last {@link QueryResultWithState}, or `undefined`.\n */\n getLastResult<TDataType>(\n key: QueryCacheKey,\n ): QueryResultWithState<TDataType> | undefined {\n return this._entries.get(key)?.lastResult as\n | QueryResultWithState<TDataType>\n | undefined;\n }\n\n /**\n * Stores the most recent result for the given key and notifies all registered listeners.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param result The result to store.\n */\n setLastResult<TDataType>(\n key: QueryCacheKey,\n result: QueryResultWithState<TDataType>,\n ): void {\n const entry = this._entries.get(key);\n\n if (!entry) {\n return;\n }\n\n const previousResult = entry.lastResult as\n | QueryResultWithState<TDataType>\n | undefined;\n\n // Reconcile the incoming payload against the one already held so items that did not actually\n // change keep their previous references. A full snapshot — which is what the server re-sends\n // whenever a subscription is re-established — otherwise arrives as all-new references and\n // makes every consumer treat every item as changed.\n const reconciled =\n previousResult === undefined\n ? result\n : this.withReconciledData(previousResult, result);\n\n entry.lastResult = reconciled as QueryResultWithState<unknown>;\n\n // Reconciliation returns the previous data reference when nothing changed, so identity is\n // enough to detect it. Data and result metadata affect what the user sees; changeSet is\n // ephemeral and does not independently require a notification.\n if (\n previousResult !== undefined &&\n previousResult.data === reconciled.data &&\n this.hasEquivalentMetadata(previousResult, reconciled)\n ) {\n return;\n }\n\n for (const listener of entry.listeners) {\n (listener as QueryCacheListener<TDataType>)(reconciled);\n }\n }\n\n /**\n * Returns the incoming result with its data reconciled against the previous result, or the\n * incoming result unchanged when reconciliation found nothing to carry over.\n * @template TDataType The type of data returned by the query.\n * @param previous The previously held result.\n * @param next The freshly received result.\n * @returns A result whose data preserves references for everything that did not change.\n */\n private withReconciledData<TDataType>(\n previous: QueryResultWithState<TDataType>,\n next: QueryResultWithState<TDataType>,\n ): QueryResultWithState<TDataType> {\n const reconciledData = reconcileQueryData(previous.data, next.data);\n\n if (reconciledData === next.data) {\n return next;\n }\n\n return new QueryResultWithState<TDataType>(\n reconciledData,\n next.paging,\n next.isSuccess,\n next.isAuthorized,\n next.isValid,\n next.validationResults,\n next.hasExceptions,\n next.exceptionMessages,\n next.exceptionStackTrace,\n next.isPerforming,\n next.changeSet,\n next.isReady,\n next.authorizationFailureReason,\n next.isRetryable,\n );\n }\n\n private hasEquivalentMetadata<TDataType>(result: QueryResultWithState<TDataType>, previous: QueryResultWithState<TDataType>): boolean {\n return result.isPerforming === previous.isPerforming\n && result.isSuccess === previous.isSuccess\n && result.isReady === previous.isReady\n && result.isAuthorized === previous.isAuthorized\n && result.authorizationFailureReason === previous.authorizationFailureReason\n && result.isRetryable === previous.isRetryable\n && result.isValid === previous.isValid\n && result.hasExceptions === previous.hasExceptions\n && result.exceptionStackTrace === previous.exceptionStackTrace\n && deepEqual(result.paging, previous.paging)\n && deepEqual(result.exceptionMessages, previous.exceptionMessages)\n && deepEqual(result.validationResults, previous.validationResults);\n }\n\n /**\n * Registers a listener that is invoked whenever the cached result for the given key changes.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param listener The callback to register.\n */\n addListener<TDataType>(\n key: QueryCacheKey,\n listener: QueryCacheListener<TDataType>,\n ): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.listeners.add(listener as QueryCacheListener<unknown>);\n }\n }\n\n /**\n * Removes a previously registered listener.\n * @template TDataType The type of data returned by the query.\n * @param key The cache key produced by {@link buildKey}.\n * @param listener The callback to remove.\n */\n removeListener<TDataType>(\n key: QueryCacheKey,\n listener: QueryCacheListener<TDataType>,\n ): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.listeners.delete(listener as QueryCacheListener<unknown>);\n }\n }\n\n /**\n * Stores a teardown function for the given key and marks the entry as subscribed.\n * Called automatically when the last subscriber releases the entry.\n * @param key The cache key produced by {@link buildKey}.\n * @param teardown Cleanup function that disconnects the underlying query subscription.\n */\n setTeardown(key: QueryCacheKey, teardown: () => void): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.teardown = teardown;\n entry.subscribed = true;\n }\n }\n\n /**\n * Returns whether an active subscription exists for the given key.\n * @param key The cache key to check.\n * @returns `true` if a subscription has been established; `false` otherwise.\n */\n isSubscribed(key: QueryCacheKey): boolean {\n return this._entries.get(key)?.subscribed ?? false;\n }\n\n /**\n * Decrements the subscriber count for the given key. When the count reaches zero, both teardown\n * and eviction are deferred by one microtask so that React StrictMode re-mounts — in any build\n * environment — can re-acquire the entry and cancel the cleanup before the timeout fires. This\n * prevents an unnecessary disconnect/reconnect cycle during the synthetic unmount/remount that\n * StrictMode performs.\n * @param key The cache key produced by {@link buildKey}.\n */\n release(key: QueryCacheKey): void {\n const entry = this._entries.get(key);\n\n if (entry) {\n entry.subscriberCount--;\n\n if (entry.subscriberCount <= 0) {\n // Defer both teardown and eviction. React StrictMode re-mounts can cancel by\n // calling acquire() before the timeout fires. A non-zero _retentionMs keeps the\n // entry alive so users navigating back quickly see cached data immediately.\n entry.pendingCleanup = setTimeout(() => {\n const current = this._entries.get(key);\n\n if (current && current.subscriberCount <= 0) {\n current.subscribed = false;\n current.teardown?.();\n current.teardown = undefined;\n current.pendingCleanup = undefined;\n this._entries.delete(key);\n }\n }, this._retentionMs);\n }\n }\n }\n\n /**\n * Returns whether an entry exists for the given key.\n * @param key The cache key to check.\n * @returns `true` if an entry exists; `false` otherwise.\n */\n has(key: QueryCacheKey): boolean {\n return this._entries.has(key);\n }\n\n /**\n * Tears down all active subscriptions and marks every entry as not subscribed,\n * but preserves entries, subscriber counts, listeners, and pending eviction timers. This allows\n * hooks whose effects re-run afterward to detect that the entry is no longer\n * subscribed and re-establish a fresh connection.\n *\n * Use this when the underlying transport must be replaced (e.g. after an\n * authentication change that requires new WebSocket connections with updated\n * credentials).\n */\n teardownAllSubscriptions(): void {\n for (const [, entry] of this._entries) {\n this.teardownEntry(entry);\n }\n }\n\n private teardownEntry(entry: QueryCacheEntry<unknown>): void {\n entry.subscribed = false;\n entry.teardown?.();\n entry.teardown = undefined;\n }\n\n /**\n * Immediately tears down all subscriptions, cancels any pending deferred cleanups,\n * and evicts all entries. Call when the owning component (e.g. the {@link Arc} provider)\n * unmounts permanently so that all query connections are closed synchronously.\n */\n dispose(): void {\n this.teardownAllSubscriptions();\n for (const entry of this._entries.values()) {\n if (entry.pendingCleanup !== undefined) {\n clearTimeout(entry.pendingCleanup);\n }\n }\n this._entries.clear();\n }\n\n /**\n * Schedules a deferred {@link dispose} using {@code setTimeout(0)}.\n *\n * This allows React StrictMode re-mounts to call {@link cancelPendingDispose}\n * before the dispose fires, avoiding the destruction of cache entries that child\n * effects are about to re-acquire.\n *\n * If a deferred dispose is already pending, it is replaced.\n */\n deferDispose(): void {\n if (this._pendingDispose !== undefined) {\n clearTimeout(this._pendingDispose);\n }\n\n this._pendingDispose = setTimeout(() => {\n this._pendingDispose = undefined;\n this.dispose();\n }, 0);\n }\n\n /**\n * Cancels a pending deferred dispose scheduled by {@link deferDispose}.\n *\n * Call from the {@code useEffect} setup phase so that a StrictMode re-mount\n * prevents the synthetic unmount's deferred dispose from firing.\n */\n cancelPendingDispose(): void {\n if (this._pendingDispose !== undefined) {\n clearTimeout(this._pendingDispose);\n this._pendingDispose = undefined;\n }\n }\n\n /**\n * Returns a diagnostics snapshot of the current cache state.\n * @returns A {@link CacheDiagnostics} describing all entries.\n */\n getDiagnosticsSnapshot(): CacheDiagnostics {\n const entries: CacheEntryDiagnostics[] = [];\n let totalBytes = 0;\n let unhealthyCount = 0;\n\n for (const [key, entry] of this._entries) {\n const colonIndex = key.indexOf('::');\n const queryName = colonIndex >= 0 ? key.substring(0, colonIndex) : key;\n\n let estimatedBytes = 0;\n try {\n if (entry.lastResult !== undefined) {\n estimatedBytes = JSON.stringify(entry.lastResult).length;\n }\n } catch {\n // Ignore serialization errors\n }\n\n if (entry.subscriberCount > 0 && !entry.subscribed) {\n unhealthyCount++;\n }\n\n totalBytes += estimatedBytes;\n entries.push({\n key,\n queryName,\n subscriberCount: entry.subscriberCount,\n listenerCount: entry.listeners.size,\n subscribed: entry.subscribed,\n hasResult: entry.lastResult !== undefined,\n estimatedBytes,\n });\n }\n\n return {\n healthy: unhealthyCount === 0,\n entryCount: this._entries.size,\n estimatedBytes: totalBytes,\n entries,\n };\n }\n}\n"],"names":["QueryInstanceCache","_entries","Map","_pendingDispose","_retentionMs","buildKey","queryTypeName","args","Object","keys","length","sorted","sort","reduce","accumulator","key","JSON","stringify","getOrCreate","factory","has","entry","instance","lastResult","undefined","subscriberCount","listeners","Set","subscribed","set","isNew","get","acquire","pendingCleanup","clearTimeout","getLastResult","setLastResult","result","previousResult","reconciled","withReconciledData","data","hasEquivalentMetadata","listener","previous","next","reconciledData","reconcileQueryData","QueryResultWithState","paging","isSuccess","isAuthorized","isValid","validationResults","hasExceptions","exceptionMessages","exceptionStackTrace","isPerforming","changeSet","isReady","authorizationFailureReason","isRetryable","deepEqual","addListener","add","removeListener","delete","setTeardown","teardown","isSubscribed","release","setTimeout","current","teardownAllSubscriptions","teardownEntry","dispose","values","clear","deferDispose","cancelPendingDispose","getDiagnosticsSnapshot","entries","totalBytes","unhealthyCount","colonIndex","indexOf","queryName","substring","estimatedBytes","push","listenerCount","size","hasResult","healthy","entryCount"],"mappings":";;;;;;AAAA;AACA;AAkEA;;;;;;;AAOC,IACM,MAAMA,kBAAAA,CAAAA;;AACQC,IAAAA,QAAAA,GAAW,IAAIC,GAAAA,EAAAA;IACxBC,eAAAA;AAER;;;;;;AAMC,QACD,WAAA,CAA6BC,YAAAA,GAAuB,MAAM,CAAE;aAA/BA,YAAAA,GAAAA,YAAAA;AAAgC,IAAA;AAE7D;;;;;;;AAOC,QACDC,QAAAA,CAASC,aAAqB,EAAEC,IAAa,EAAiB;QAC1D,IAAI,CAACA,QAAQC,MAAAA,CAAOC,IAAI,CAACF,IAAAA,CAAAA,CAAMG,MAAM,KAAK,CAAA,EAAG;YACzC,OAAO,CAAA,EAAGJ,aAAAA,CAAc,EAAE,CAAC;AAC/B,QAAA;QAEA,MAAMK,MAAAA,GAASH,MAAAA,CAAOC,IAAI,CAACF,IAAAA,CAAAA,CACtBK,IAAI,EAAA,CACJC,MAAM,CAA0B,CAACC,WAAAA,EAAaC,GAAAA,GAAAA;AAC3CD,YAAAA,WAAW,CAACC,GAAAA,CAAI,GAAG,IAAiC,CAACA,GAAAA,CAAI;YACzD,OAAOD,WAAAA;AACX,QAAA,CAAA,EAAG,EAAC,CAAA;AAER,QAAA,OAAO,GAAGR,aAAAA,CAAc,EAAE,EAAEU,IAAAA,CAAKC,SAAS,CAACN,MAAAA,CAAAA,CAAAA,CAAS;AACxD,IAAA;AAEA;;;;;;;AAOC,QACDO,WAAAA,CACIH,GAAkB,EAClBI,OAAwB,EACe;AACvC,QAAA,IAAI,CAAC,IAAI,CAAClB,QAAQ,CAACmB,GAAG,CAACL,GAAAA,CAAAA,EAAM;AACzB,YAAA,MAAMM,KAAAA,GAAkC;gBACpCC,QAAAA,EAAUH,OAAAA,EAAAA;gBACVI,UAA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GD,iCAAiC,SAGhC;IAED,OAAO,CAAC,oBAAoB;IAY5B,aAAa,IAAI,IAAI,CAKpB;IAGD,IAAI,UAAU,YAEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM,QAY/B;IAGD,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,QAS3D;IAED,OAAO,CAAC,gBAAgB;CAM3B"}
|
|
@@ -264,6 +264,9 @@ import { ValidationResultReasonDetail } from '../validation/ValidationResultReas
|
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
266
|
/** @inheritdoc */ onPropertyChanged(callback, thisArg) {
|
|
267
|
+
if (this._callbacks.some((_)=>_.callback.deref() === callback && _.thisArg.deref() === thisArg)) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
267
270
|
this._callbacks.push({
|
|
268
271
|
callback: new WeakRef(callback),
|
|
269
272
|
thisArg: new WeakRef(thisArg)
|
|
@@ -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 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","WeakRef","some"],"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,EAAA;AAC7C,QAAA,IAAI,CAACb,YAAY,GAAGY,OAAAA,CAAQE,WAAW,IAAI,EAAA;AAC3C,QAAA,IAAI,CAACb,OAAO,GAAGW,OAAAA,CAAQG,MAAM,IAAI,EAAA;AACjC,QAAA,IAAI,CAACb,oBAAoB,GAA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AU,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,CAACrG,UAAU,CAACwD,IAAI,CAAC;AACjB5C,YAAAA,QAAAA,EAAU,IAAI4F,OAAAA,CAAQ5F,QAAAA,CAAAA;AACtByF,YAAAA,OAAAA,EAAS,IAAIG,OAAAA,CAAQH,OAAAA;AACzB,SAAA,CAAA;AACJ,IAAA;IAEQpE,gBAAAA,GAAmB;QACvB,IAAI,CAAClC,WAAW,GAAG,IAAI,CAACgD,mBAAmB,CAAC0D,IAAI,CAACxD,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 { 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,OA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_callback_twice.d.ts","sourceRoot":"","sources":["../../../../commands/for_Command/when_registering_the_same_property_changed_callback_twice.ts"],"names":[],"mappings":""}
|
package/dist/esm/commands/for_Command/when_registering_the_same_property_changed_callback_twice.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import sinon from 'sinon';
|
|
2
|
+
import { SomeCommand } from './SomeCommand.js';
|
|
3
|
+
describe('when registering the same property changed callback twice', () => {
|
|
4
|
+
it('should notify the callback once per change', () => {
|
|
5
|
+
const command = new SomeCommand();
|
|
6
|
+
const callback = sinon.spy();
|
|
7
|
+
command.onPropertyChanged(callback, command);
|
|
8
|
+
command.onPropertyChanged(callback, command);
|
|
9
|
+
command.propertyChanged('someProperty');
|
|
10
|
+
callback.calledOnceWithExactly('someProperty').should.be.true;
|
|
11
|
+
command.propertyChanged('someProperty');
|
|
12
|
+
callback.callCount.should.equal(2);
|
|
13
|
+
});
|
|
14
|
+
it('should retain registrations with different receivers', () => {
|
|
15
|
+
const command = new SomeCommand();
|
|
16
|
+
const callback = sinon.spy();
|
|
17
|
+
const otherReceiver = {};
|
|
18
|
+
command.onPropertyChanged(callback, command);
|
|
19
|
+
command.onPropertyChanged(callback, otherReceiver);
|
|
20
|
+
command.propertyChanged('someProperty');
|
|
21
|
+
callback.calledTwice.should.be.true;
|
|
22
|
+
callback.calledOn(command).should.be.true;
|
|
23
|
+
callback.calledOn(otherReceiver).should.be.true;
|
|
24
|
+
});
|
|
25
|
+
it('should retain different callbacks for the same receiver', () => {
|
|
26
|
+
const command = new SomeCommand();
|
|
27
|
+
const first = sinon.spy();
|
|
28
|
+
const second = sinon.spy();
|
|
29
|
+
command.onPropertyChanged(first, command);
|
|
30
|
+
command.onPropertyChanged(second, command);
|
|
31
|
+
command.propertyChanged('someProperty');
|
|
32
|
+
first.calledOnce.should.be.true;
|
|
33
|
+
second.calledOnce.should.be.true;
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=when_registering_the_same_property_changed_callback_twice.js.map
|