@nmshd/consumption 2.0.0-alpha.28 → 2.0.0-alpha.30

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.
@@ -17,11 +17,11 @@ const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
17
17
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
18
18
  const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
19
19
  exports.buildInformation = {
20
- version: "2.0.0-alpha.28",
21
- build: "48",
22
- date: "2022-07-07T13:12:39+00:00",
23
- commit: "81c8304697f68fe9ed157cebc415dd1fb2f7b941",
24
- dependencies: {"@js-soft/docdb-querytranslator":"^1.0.1","ts-simple-nameof":"^1.3.1"},
20
+ version: "2.0.0-alpha.30",
21
+ build: "50",
22
+ date: "2022-07-20T08:46:05+00:00",
23
+ commit: "c75ea75c8ea2648264f637a5d484f7937cd383f6",
24
+ dependencies: {"@js-soft/docdb-querytranslator":"^1.1.0","ts-simple-nameof":"^1.3.1"},
25
25
  libraries: {
26
26
  transport: transport_1.buildInformation,
27
27
  crypto: crypto_1.buildInformation,
@@ -1197,61 +1197,54 @@ exports.DecideRequestParametersValidator = void 0;
1197
1197
  const ts_utils_1 = __webpack_require__(/*! @js-soft/ts-utils */ "./node_modules/@js-soft/ts-utils/dist/index.js");
1198
1198
  const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
1199
1199
  const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
1200
+ const ValidationResult_1 = __webpack_require__(/*! ../itemProcessors/ValidationResult */ "./dist/modules/requests/itemProcessors/ValidationResult.js");
1200
1201
  const DecideRequestItemGroupParameters_1 = __webpack_require__(/*! ./decide/DecideRequestItemGroupParameters */ "./dist/modules/requests/incoming/decide/DecideRequestItemGroupParameters.js");
1201
1202
  const DecideRequestItemParameters_1 = __webpack_require__(/*! ./decide/DecideRequestItemParameters */ "./dist/modules/requests/incoming/decide/DecideRequestItemParameters.js");
1202
1203
  class DecideRequestParametersValidator {
1203
1204
  validate(params, request) {
1204
1205
  if (!request.id.equals(transport_1.CoreId.from(params.requestId))) {
1205
- return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidRequestId", "The id of the request does not match the id of the response"));
1206
+ return ValidationResult_1.ValidationResult.error(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidRequestId", "The id of the Request does not match the id of the Response"));
1206
1207
  }
1207
1208
  if (params.items.length !== request.content.items.length) {
1208
- return ts_utils_1.Result.fail(this.invalidNumberOfItemsError("Number of items in Request and Response do not match"));
1209
- }
1210
- for (let i = 0; i < params.items.length; i++) {
1211
- const validationResult = this.checkItemOrGroup(request.content.items[i], params.items[i], i.toString(), params.accept);
1212
- if (validationResult.isError)
1213
- return validationResult;
1209
+ return ValidationResult_1.ValidationResult.error(this.invalidNumberOfItemsError("Number of items in Request and Response do not match"));
1214
1210
  }
1215
- return ts_utils_1.Result.ok(undefined);
1211
+ const validationResults = request.content.items.map((requestItem, index) => this.checkItemOrGroup(requestItem, params.items[index], params.accept));
1212
+ return ValidationResult_1.ValidationResult.fromItems(validationResults);
1216
1213
  }
1217
- checkItemOrGroup(requestItem, responseItem, index, isParentAccepted) {
1214
+ checkItemOrGroup(requestItem, responseItem, isParentAccepted) {
1218
1215
  if (requestItem instanceof content_1.RequestItem) {
1219
- return this.checkItem(requestItem, responseItem, index, isParentAccepted);
1216
+ return this.checkItem(requestItem, responseItem, isParentAccepted);
1220
1217
  }
1221
- return this.checkItemGroup(requestItem, responseItem, index, isParentAccepted);
1218
+ return this.checkItemGroup(requestItem, responseItem, isParentAccepted);
1222
1219
  }
1223
- checkItem(requestItem, response, index, isParentAccepted) {
1220
+ checkItem(requestItem, response, isParentAccepted) {
1224
1221
  if ((0, DecideRequestItemGroupParameters_1.isDecideRequestItemGroupParametersJSON)(response)) {
1225
- return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItem with index '${index}' was answered as a RequestItemGroup.`));
1222
+ return ValidationResult_1.ValidationResult.error(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", "The RequestItem was answered as a RequestItemGroup."));
1226
1223
  }
1227
1224
  if (!isParentAccepted && response.accept) {
1228
- return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItem with index '${index}' was accepted, but the parent was not accepted.`));
1225
+ return ValidationResult_1.ValidationResult.error(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", "The RequestItem was accepted, but the parent was not accepted."));
1229
1226
  }
1230
1227
  if (isParentAccepted && requestItem.mustBeAccepted && !response.accept) {
1231
- return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItem with index '${index}', which is flagged as 'mustBeAccepted', was not accepted.`));
1228
+ return ValidationResult_1.ValidationResult.error(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", "The RequestItem is flagged as 'mustBeAccepted', but it was not accepted."));
1232
1229
  }
1233
- return ts_utils_1.Result.ok(undefined);
1230
+ return ValidationResult_1.ValidationResult.success();
1234
1231
  }
1235
- checkItemGroup(requestItemGroup, responseItemGroup, index, isParentAccepted) {
1232
+ checkItemGroup(requestItemGroup, responseItemGroup, isParentAccepted) {
1236
1233
  if ((0, DecideRequestItemParameters_1.isDecideRequestItemParametersJSON)(responseItemGroup)) {
1237
- return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItemGroup with index '${index}' was answered as a RequestItem.`));
1234
+ return ValidationResult_1.ValidationResult.error(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", "The RequestItemGroup was answered as a RequestItem."));
1238
1235
  }
1239
1236
  if (responseItemGroup.items.length !== requestItemGroup.items.length) {
1240
- return ts_utils_1.Result.fail(this.invalidNumberOfItemsError("Number of items in RequestItemGroup and ResponseItemGroup do not match"));
1237
+ return ValidationResult_1.ValidationResult.error(this.invalidNumberOfItemsError("Number of items in RequestItemGroup and ResponseItemGroup do not match"));
1241
1238
  }
1242
1239
  const isGroupAccepted = responseItemGroup.items.some((value) => value.accept);
1243
1240
  if (!isParentAccepted && isGroupAccepted) {
1244
- return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItemGroup with index '${index}' was accepted, but the parent was not accepted.`));
1241
+ return ValidationResult_1.ValidationResult.error(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", "The RequestItemGroup was accepted, but the parent was not accepted."));
1245
1242
  }
1246
1243
  if (isParentAccepted && requestItemGroup.mustBeAccepted && !isGroupAccepted) {
1247
- return ts_utils_1.Result.fail(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", `The RequestItemGroup with index '${index}', which is flagged as 'mustBeAccepted', was not accepted. Please accept all 'mustBeAccepted' items in this group.`));
1244
+ return ValidationResult_1.ValidationResult.error(new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidResponseItemForRequestItem", "The RequestItemGroup is flagged as 'mustBeAccepted', but it was not accepted. Please accept all 'mustBeAccepted' items in this group."));
1248
1245
  }
1249
- for (let i = 0; i < responseItemGroup.items.length; i++) {
1250
- const validationResult = this.checkItem(requestItemGroup.items[i], responseItemGroup.items[i], `${index}.${i}`, isGroupAccepted);
1251
- if (validationResult.isError)
1252
- return validationResult;
1253
- }
1254
- return ts_utils_1.Result.ok(undefined);
1246
+ const validationResults = requestItemGroup.items.map((requestItem, index) => this.checkItem(requestItem, responseItemGroup.items[index], isGroupAccepted));
1247
+ return ValidationResult_1.ValidationResult.fromItems(validationResults);
1255
1248
  }
1256
1249
  invalidNumberOfItemsError(message) {
1257
1250
  return new ts_utils_1.ApplicationError("error.requests.decide.validation.invalidNumberOfItems", message);
@@ -1380,11 +1373,10 @@ class IncomingRequestsController extends consumption_1.ConsumptionBaseController
1380
1373
  // syntactic validation
1381
1374
  InternalDecideRequestParameters_1.InternalDecideRequestParameters.from(params);
1382
1375
  const request = await this.getOrThrow(params.requestId);
1383
- const validationResult = this.decideRequestParamsValidator.validate(params, request);
1384
- if (!validationResult.isSuccess) {
1385
- throw new Error(validationResult.error.message);
1386
- }
1387
1376
  this.assertRequestStatus(request, LocalRequestStatus_1.LocalRequestStatus.DecisionRequired, LocalRequestStatus_1.LocalRequestStatus.ManualDecisionRequired);
1377
+ const validationResult = this.decideRequestParamsValidator.validate(params, request);
1378
+ if (validationResult.isError())
1379
+ return validationResult;
1388
1380
  const itemResults = await this.canDecideItems(params.items, request.content.items, request);
1389
1381
  return ValidationResult_1.ValidationResult.fromItems(itemResults);
1390
1382
  }
@@ -2325,10 +2317,10 @@ const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transpor
2325
2317
  const ts_simple_nameof_1 = __webpack_require__(/*! ts-simple-nameof */ "./node_modules/ts-simple-nameof/index.js");
2326
2318
  let AcceptReadAttributeRequestItemParameters = AcceptReadAttributeRequestItemParameters_1 = class AcceptReadAttributeRequestItemParameters extends ts_serval_1.Serializable {
2327
2319
  isWithExistingAttribute() {
2328
- return this.attributeId !== undefined;
2320
+ return this.existingAttributeId !== undefined;
2329
2321
  }
2330
2322
  isWithNewAttribute() {
2331
- return this.newAttributeValue !== undefined;
2323
+ return this.newAttribute !== undefined;
2332
2324
  }
2333
2325
  static from(value) {
2334
2326
  return this.fromAny(value);
@@ -2336,11 +2328,11 @@ let AcceptReadAttributeRequestItemParameters = AcceptReadAttributeRequestItemPar
2336
2328
  static postFrom(value) {
2337
2329
  if (!(value instanceof AcceptReadAttributeRequestItemParameters_1))
2338
2330
  throw new Error("this should never happen");
2339
- if (value.attributeId && value.newAttributeValue) {
2340
- throw new ts_serval_1.ValidationError(AcceptReadAttributeRequestItemParameters_1.name, (0, ts_simple_nameof_1.nameof)((x) => x.newAttributeValue), `You cannot specify both ${(0, ts_simple_nameof_1.nameof)((x) => x.newAttributeValue)} and ${(0, ts_simple_nameof_1.nameof)((x) => x.attributeId)}.`);
2331
+ if (value.existingAttributeId && value.newAttribute) {
2332
+ throw new ts_serval_1.ValidationError(AcceptReadAttributeRequestItemParameters_1.name, (0, ts_simple_nameof_1.nameof)((x) => x.newAttribute), `You cannot specify both ${(0, ts_simple_nameof_1.nameof)((x) => x.newAttribute)} and ${(0, ts_simple_nameof_1.nameof)((x) => x.existingAttributeId)}.`);
2341
2333
  }
2342
- if (!value.attributeId && !value.newAttributeValue) {
2343
- throw new ts_serval_1.ValidationError(AcceptReadAttributeRequestItemParameters_1.name, (0, ts_simple_nameof_1.nameof)((x) => x.newAttributeValue), `You have to specify either ${(0, ts_simple_nameof_1.nameof)((x) => x.newAttributeValue)} or ${(0, ts_simple_nameof_1.nameof)((x) => x.attributeId)}.`);
2334
+ if (!value.existingAttributeId && !value.newAttribute) {
2335
+ throw new ts_serval_1.ValidationError(AcceptReadAttributeRequestItemParameters_1.name, (0, ts_simple_nameof_1.nameof)((x) => x.newAttribute), `You have to specify either ${(0, ts_simple_nameof_1.nameof)((x) => x.newAttribute)} or ${(0, ts_simple_nameof_1.nameof)((x) => x.existingAttributeId)}.`);
2344
2336
  }
2345
2337
  return value;
2346
2338
  }
@@ -2349,12 +2341,12 @@ __decorate([
2349
2341
  (0, ts_serval_1.serialize)(),
2350
2342
  (0, ts_serval_1.validate)({ nullable: true }),
2351
2343
  __metadata("design:type", transport_1.CoreId)
2352
- ], AcceptReadAttributeRequestItemParameters.prototype, "attributeId", void 0);
2344
+ ], AcceptReadAttributeRequestItemParameters.prototype, "existingAttributeId", void 0);
2353
2345
  __decorate([
2354
2346
  (0, ts_serval_1.serialize)({ unionTypes: [content_1.IdentityAttribute, content_1.RelationshipAttribute] }),
2355
2347
  (0, ts_serval_1.validate)({ nullable: true }),
2356
2348
  __metadata("design:type", Object)
2357
- ], AcceptReadAttributeRequestItemParameters.prototype, "newAttributeValue", void 0);
2349
+ ], AcceptReadAttributeRequestItemParameters.prototype, "newAttribute", void 0);
2358
2350
  AcceptReadAttributeRequestItemParameters = AcceptReadAttributeRequestItemParameters_1 = __decorate([
2359
2351
  (0, ts_serval_1.type)("AcceptReadAttributeRequestItemParameters")
2360
2352
  ], AcceptReadAttributeRequestItemParameters);
@@ -2395,7 +2387,7 @@ class ReadAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.Ge
2395
2387
  async canAccept(_requestItem, params, requestInfo) {
2396
2388
  const parsedParams = AcceptReadAttributeRequestItemParameters_1.AcceptReadAttributeRequestItemParameters.from(params);
2397
2389
  if (parsedParams.isWithExistingAttribute()) {
2398
- const foundAttribute = await this.consumptionController.attributes.getLocalAttribute(parsedParams.attributeId);
2390
+ const foundAttribute = await this.consumptionController.attributes.getLocalAttribute(parsedParams.existingAttributeId);
2399
2391
  if (!foundAttribute) {
2400
2392
  return ValidationResult_1.ValidationResult.error(transport_1.TransportErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, requestInfo.id.toString()));
2401
2393
  }
@@ -2409,10 +2401,10 @@ class ReadAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.Ge
2409
2401
  const parsedParams = AcceptReadAttributeRequestItemParameters_1.AcceptReadAttributeRequestItemParameters.from(params);
2410
2402
  let sharedLocalAttribute;
2411
2403
  if (parsedParams.isWithExistingAttribute()) {
2412
- sharedLocalAttribute = await this.copyExistingAttribute(parsedParams.attributeId, requestInfo);
2404
+ sharedLocalAttribute = await this.copyExistingAttribute(parsedParams.existingAttributeId, requestInfo);
2413
2405
  }
2414
2406
  else {
2415
- sharedLocalAttribute = await this.createNewAttribute(parsedParams.newAttributeValue, requestInfo);
2407
+ sharedLocalAttribute = await this.createNewAttribute(parsedParams.newAttribute, requestInfo);
2416
2408
  }
2417
2409
  return content_1.ReadAttributeAcceptResponseItem.from({
2418
2410
  result: content_1.ResponseItemResult.Accepted,
@@ -2560,12 +2552,12 @@ class ShareAttributeRequestItemProcessor extends GenericRequestItemProcessor_1.G
2560
2552
  if (attribute.content instanceof content_1.IdentityAttribute) {
2561
2553
  return ((await this.consumptionController.attributes.getLocalAttributes({
2562
2554
  "shareInfo.sourceAttribute": attribute.shareInfo.sourceAttribute.toString(),
2563
- "shareInfo.peer": shareWith.toString() // eslint-disable-line @typescript-eslint/naming-convention
2555
+ "shareInfo.peer": shareWith.toString()
2564
2556
  })).length > 0);
2565
2557
  }
2566
2558
  return ((await this.consumptionController.attributes.getLocalAttributes({
2567
2559
  "shareInfo.sourceAttribute": attribute.id.toString(),
2568
- "shareInfo.peer": shareWith.toString() // eslint-disable-line @typescript-eslint/naming-convention
2560
+ "shareInfo.peer": shareWith.toString()
2569
2561
  })).length > 0);
2570
2562
  }
2571
2563
  async shareAttribute(attribute, shareWith) {
@@ -3529,7 +3521,7 @@ class QueryTranslator {
3529
3521
  valRegex;
3530
3522
  arrRegex;
3531
3523
  constructor(options = {}) {
3532
- this.ops = options.ops ?? ["!", "^", "$", "~", ">", "<", "$in"];
3524
+ this.ops = options.ops ?? ["!", "^", "$", "~", ">", "<", "$containsAny", "$containsNone"];
3533
3525
  this.alias = options.alias ?? {};
3534
3526
  this.blacklist = options.blacklist ?? {};
3535
3527
  this.whitelist = options.whitelist ?? {};
@@ -3560,7 +3552,7 @@ class QueryTranslator {
3560
3552
  switch (op) {
3561
3553
  case "!":
3562
3554
  if (array) {
3563
- ret.field = "$nin";
3555
+ ret.field = "$containsNone";
3564
3556
  }
3565
3557
  else if (org === "") {
3566
3558
  ret.field = "$exists";
@@ -3598,7 +3590,7 @@ class QueryTranslator {
3598
3590
  ret.op = op = "";
3599
3591
  ret.value = this.parseStringVal(org);
3600
3592
  if (array) {
3601
- ret.field = "$in";
3593
+ ret.field = "$containsAny";
3602
3594
  }
3603
3595
  else if (org === "") {
3604
3596
  ret.field = "$exists";
@@ -3665,14 +3657,14 @@ class QueryTranslator {
3665
3657
  }
3666
3658
  // Handle array key
3667
3659
  if (Array.isArray(val)) {
3668
- if (this.ops.includes("$in") && val.length > 0) {
3660
+ if (this.ops.includes("$containsAny") && val.length > 0) {
3669
3661
  res[key] = {};
3670
3662
  for (const item of val) {
3671
3663
  if (this.ops.includes(item[0])) {
3672
3664
  const parsed = this.parseString(item, true);
3673
3665
  switch (parsed.field) {
3674
- case "$in":
3675
- case "$nin":
3666
+ case "$containsAny":
3667
+ case "$containsNone":
3676
3668
  res[key][parsed.field] = res[key][parsed.field] || [];
3677
3669
  res[key][parsed.field].push(parsed.value);
3678
3670
  break;
@@ -3685,8 +3677,8 @@ class QueryTranslator {
3685
3677
  }
3686
3678
  }
3687
3679
  else {
3688
- res[key].$in = res[key].$in || [];
3689
- res[key].$in.push(this.parseStringVal(item));
3680
+ res[key].$containsAny = res[key].$containsAny || [];
3681
+ res[key].$containsAny.push(this.parseStringVal(item));
3690
3682
  }
3691
3683
  }
3692
3684
  }
@@ -3831,10 +3823,11 @@ const EventBus_1 = __webpack_require__(/*! ../EventBus */ "./node_modules/@js-so
3831
3823
  const SubscriptionTargetInfo_1 = __webpack_require__(/*! ../SubscriptionTargetInfo */ "./node_modules/@js-soft/ts-utils/dist/eventBus/SubscriptionTargetInfo.js");
3832
3824
  class EventEmitter2EventBus {
3833
3825
  emitter;
3834
- wrappers = new Map();
3826
+ listeners = new Map();
3835
3827
  nextId = 0;
3836
- constructor() {
3837
- this.emitter = new eventemitter2_1.EventEmitter2({ wildcard: true, maxListeners: 50, verboseMemoryLeak: true });
3828
+ invocationPromises = [];
3829
+ constructor(options) {
3830
+ this.emitter = new eventemitter2_1.EventEmitter2({ ...options, wildcard: true, maxListeners: 50, verboseMemoryLeak: true });
3838
3831
  }
3839
3832
  subscribe(subscriptionTarget, handler) {
3840
3833
  return this.registerHandler(subscriptionTarget, handler);
@@ -3842,33 +3835,39 @@ class EventEmitter2EventBus {
3842
3835
  subscribeOnce(subscriptionTarget, handler) {
3843
3836
  return this.registerHandler(subscriptionTarget, handler, true);
3844
3837
  }
3845
- unsubscribe(subscriptionTarget, subscriptionId) {
3846
- return this.unregisterHandler(subscriptionTarget, subscriptionId);
3838
+ unsubscribe(subscriptionId) {
3839
+ return this.unregisterHandler(subscriptionId);
3847
3840
  }
3848
3841
  registerHandler(subscriptionTarget, handler, isOneTimeHandler = false) {
3849
3842
  const subscriptionTargetInfo = SubscriptionTargetInfo_1.SubscriptionTargetInfo.from(subscriptionTarget);
3850
- const handlerId = this.nextId++;
3851
- const handlerWrapper = (event) => {
3843
+ const listenerId = this.nextId++;
3844
+ const handlerWrapper = async (event) => {
3852
3845
  if (!subscriptionTargetInfo.isCompatibleWith(event)) {
3853
3846
  return;
3854
3847
  }
3855
- handler(event);
3856
- if (isOneTimeHandler) {
3857
- this.unsubscribe(subscriptionTarget, handlerId);
3858
- }
3848
+ const invocationPromise = (async () => await handler(event))();
3849
+ this.invocationPromises.push(invocationPromise);
3850
+ await invocationPromise;
3851
+ this.invocationPromises = this.invocationPromises.filter((p) => p !== invocationPromise);
3852
+ if (isOneTimeHandler)
3853
+ this.listeners.delete(listenerId);
3859
3854
  };
3860
- this.wrappers.set(handlerId, handlerWrapper);
3861
- this.emitter.on(subscriptionTargetInfo.namespace, handlerWrapper);
3862
- return handlerId;
3863
- }
3864
- unregisterHandler(subscriptionTarget, handlerId) {
3865
- const subscriptionTargetInfo = SubscriptionTargetInfo_1.SubscriptionTargetInfo.from(subscriptionTarget);
3866
- const handlerWrapper = this.wrappers.get(handlerId);
3867
- if (!handlerWrapper) {
3855
+ if (isOneTimeHandler) {
3856
+ const listener = this.emitter.once(subscriptionTargetInfo.namespace, handlerWrapper, { objectify: true });
3857
+ this.listeners.set(listenerId, listener);
3858
+ return listenerId;
3859
+ }
3860
+ const listener = this.emitter.on(subscriptionTargetInfo.namespace, handlerWrapper, { objectify: true });
3861
+ this.listeners.set(listenerId, listener);
3862
+ return listenerId;
3863
+ }
3864
+ unregisterHandler(listenerId) {
3865
+ const listener = this.listeners.get(listenerId);
3866
+ if (!listener) {
3868
3867
  return false;
3869
3868
  }
3870
- this.emitter.off(subscriptionTargetInfo.namespace, handlerWrapper);
3871
- this.wrappers.delete(handlerId);
3869
+ listener.off();
3870
+ this.listeners.delete(listenerId);
3872
3871
  return true;
3873
3872
  }
3874
3873
  publish(event) {
@@ -3878,6 +3877,24 @@ class EventEmitter2EventBus {
3878
3877
  }
3879
3878
  this.emitter.emit(namespace, event);
3880
3879
  }
3880
+ async close(timeout) {
3881
+ this.emitter.removeAllListeners();
3882
+ const waitForInvocations = Promise.all(this.invocationPromises).catch(() => {
3883
+ /* ignore errors */
3884
+ });
3885
+ if (!timeout) {
3886
+ await waitForInvocations;
3887
+ return;
3888
+ }
3889
+ let timeoutId;
3890
+ const timeoutPromise = new Promise((_, reject) => {
3891
+ timeoutId = setTimeout(() => {
3892
+ reject(new Error("timeout exceeded while waiting for events to process"));
3893
+ }, timeout);
3894
+ });
3895
+ await Promise.race([waitForInvocations, timeoutPromise]);
3896
+ clearTimeout(timeoutId);
3897
+ }
3881
3898
  }
3882
3899
  exports.EventEmitter2EventBus = EventEmitter2EventBus;
3883
3900
  //# sourceMappingURL=EventEmitter2EventBus.js.map