@openfeature/web-sdk 0.4.10 → 0.4.12

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/dist/esm/index.js CHANGED
@@ -1,27 +1,9 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __getProtoOf = Object.getPrototypeOf;
9
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __reflectGet = Reflect.get;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
7
  var __commonJS = (cb, mod) => function __require() {
26
8
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
27
9
  };
@@ -41,27 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
41
23
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
24
  mod
43
25
  ));
44
- var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
45
- var __async = (__this, __arguments, generator) => {
46
- return new Promise((resolve, reject) => {
47
- var fulfilled = (value) => {
48
- try {
49
- step(generator.next(value));
50
- } catch (e) {
51
- reject(e);
52
- }
53
- };
54
- var rejected = (value) => {
55
- try {
56
- step(generator.throw(value));
57
- } catch (e) {
58
- reject(e);
59
- }
60
- };
61
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
62
- step((generator = generator.apply(__this, __arguments)).next());
63
- });
64
- };
65
26
 
66
27
  // ../../node_modules/events/events.js
67
28
  var require_events = __commonJS({
@@ -455,12 +416,11 @@ import {
455
416
  var import_events = __toESM(require_events());
456
417
  import { GenericEventEmitter } from "@openfeature/core";
457
418
  var OpenFeatureEventEmitter = class extends GenericEventEmitter {
419
+ eventEmitter = new import_events.default({ captureRejections: true });
458
420
  constructor() {
459
421
  super();
460
- this.eventEmitter = new import_events.default({ captureRejections: true });
461
422
  this.eventEmitter.on("error", (err) => {
462
- var _a;
463
- (_a = this._logger) == null ? void 0 : _a.error("Error running event handler:", err);
423
+ this._logger?.error("Error running event handler:", err);
464
424
  });
465
425
  }
466
426
  };
@@ -472,11 +432,9 @@ import { ClientProviderEvents } from "@openfeature/core";
472
432
  import { ProviderStatus } from "@openfeature/core";
473
433
  var REASON_NO_OP = "No-op";
474
434
  var NoopFeatureProvider = class {
475
- constructor() {
476
- this.metadata = {
477
- name: "No-op Provider"
478
- };
479
- }
435
+ metadata = {
436
+ name: "No-op Provider"
437
+ };
480
438
  get status() {
481
439
  return ProviderStatus.NOT_READY;
482
440
  }
@@ -514,6 +472,7 @@ import {
514
472
  // src/provider/in-memory-provider/variant-not-found-error.ts
515
473
  import { ErrorCode, OpenFeatureError } from "@openfeature/core";
516
474
  var VariantNotFoundError = class extends OpenFeatureError {
475
+ code;
517
476
  constructor(message) {
518
477
  super(message);
519
478
  Object.setPrototypeOf(this, VariantNotFoundError.prototype);
@@ -524,48 +483,46 @@ var VariantNotFoundError = class extends OpenFeatureError {
524
483
 
525
484
  // src/provider/in-memory-provider/in-memory-provider.ts
526
485
  var InMemoryProvider = class {
486
+ events = new OpenFeatureEventEmitter();
487
+ runsOn = "client";
488
+ status = ProviderStatus2.NOT_READY;
489
+ metadata = {
490
+ name: "in-memory"
491
+ };
492
+ _flagConfiguration;
493
+ _context;
527
494
  constructor(flagConfiguration = {}) {
528
- this.events = new OpenFeatureEventEmitter();
529
- this.runsOn = "client";
530
- this.status = ProviderStatus2.NOT_READY;
531
- this.metadata = {
532
- name: "in-memory"
533
- };
534
- this._flagConfiguration = __spreadValues({}, flagConfiguration);
495
+ this._flagConfiguration = { ...flagConfiguration };
535
496
  }
536
- initialize(context) {
537
- return __async(this, null, function* () {
538
- try {
539
- for (const key in this._flagConfiguration) {
540
- this.resolveFlagWithReason(key, context);
541
- }
542
- this._context = context;
543
- this.status = ProviderStatus2.READY;
544
- } catch (error) {
545
- this.status = ProviderStatus2.ERROR;
546
- throw error;
497
+ async initialize(context) {
498
+ try {
499
+ for (const key in this._flagConfiguration) {
500
+ this.resolveFlagWithReason(key, context);
547
501
  }
548
- });
502
+ this._context = context;
503
+ this.status = ProviderStatus2.READY;
504
+ } catch (error) {
505
+ this.status = ProviderStatus2.ERROR;
506
+ throw error;
507
+ }
549
508
  }
550
509
  /**
551
510
  * Overwrites the configured flags.
552
511
  * @param { FlagConfiguration } flagConfiguration new flag configuration
553
512
  */
554
- putConfiguration(flagConfiguration) {
555
- return __async(this, null, function* () {
556
- const flagsChanged = Object.entries(flagConfiguration).filter(([key, value]) => this._flagConfiguration[key] !== value).map(([key]) => key);
557
- this.status = ProviderStatus2.STALE;
558
- this.events.emit(ClientProviderEvents.Stale);
559
- this._flagConfiguration = __spreadValues({}, flagConfiguration);
560
- this.events.emit(ClientProviderEvents.ConfigurationChanged, { flagsChanged });
561
- try {
562
- yield this.initialize(this._context);
563
- this.events.emit(ClientProviderEvents.Ready);
564
- } catch (err) {
565
- this.events.emit(ClientProviderEvents.Error);
566
- throw err;
567
- }
568
- });
513
+ async putConfiguration(flagConfiguration) {
514
+ const flagsChanged = Object.entries(flagConfiguration).filter(([key, value]) => this._flagConfiguration[key] !== value).map(([key]) => key);
515
+ this.status = ProviderStatus2.STALE;
516
+ this.events.emit(ClientProviderEvents.Stale);
517
+ this._flagConfiguration = { ...flagConfiguration };
518
+ this.events.emit(ClientProviderEvents.ConfigurationChanged, { flagsChanged });
519
+ try {
520
+ await this.initialize(this._context);
521
+ this.events.emit(ClientProviderEvents.Ready);
522
+ } catch (err) {
523
+ this.events.emit(ClientProviderEvents.Error);
524
+ throw err;
525
+ }
569
526
  }
570
527
  resolveBooleanEvaluation(flagKey, defaultValue, context, logger) {
571
528
  return this.resolveAndCheckFlag(flagKey, defaultValue, context || this._context, logger);
@@ -582,7 +539,7 @@ var InMemoryProvider = class {
582
539
  resolveAndCheckFlag(flagKey, defaultValue, context, logger) {
583
540
  if (!(flagKey in this._flagConfiguration)) {
584
541
  const message = `no flag found with key ${flagKey}`;
585
- logger == null ? void 0 : logger.debug(message);
542
+ logger?.debug(message);
586
543
  throw new FlagNotFoundError(message);
587
544
  }
588
545
  if (this._flagConfiguration[flagKey].disabled) {
@@ -591,7 +548,7 @@ var InMemoryProvider = class {
591
548
  const resolvedFlag = this.resolveFlagWithReason(flagKey, context);
592
549
  if (resolvedFlag.value === void 0) {
593
550
  const message = `no value associated with variant provided for ${flagKey} found`;
594
- logger == null ? void 0 : logger.error(message);
551
+ logger?.error(message);
595
552
  throw new VariantNotFoundError(message);
596
553
  }
597
554
  if (typeof resolvedFlag.value != typeof defaultValue) {
@@ -605,24 +562,23 @@ var InMemoryProvider = class {
605
562
  return resolutionResult;
606
563
  } catch (error) {
607
564
  if (!(error instanceof OpenFeatureError2)) {
608
- throw new GeneralError((error == null ? void 0 : error.message) || "unknown error");
565
+ throw new GeneralError(error?.message || "unknown error");
609
566
  }
610
567
  throw error;
611
568
  }
612
569
  }
613
570
  lookupFlagValue(flagKey, ctx) {
614
- var _a;
615
571
  const flagSpec = this._flagConfiguration[flagKey];
616
- const isContextEval = ctx && (flagSpec == null ? void 0 : flagSpec.contextEvaluator);
617
- const variant = isContextEval ? (_a = flagSpec.contextEvaluator) == null ? void 0 : _a.call(flagSpec, ctx) : flagSpec.defaultVariant;
618
- const value = variant && (flagSpec == null ? void 0 : flagSpec.variants[variant]);
572
+ const isContextEval = ctx && flagSpec?.contextEvaluator;
573
+ const variant = isContextEval ? flagSpec.contextEvaluator?.(ctx) : flagSpec.defaultVariant;
574
+ const value = variant && flagSpec?.variants[variant];
619
575
  const evalReason = isContextEval ? StandardResolutionReasons.TARGETING_MATCH : StandardResolutionReasons.STATIC;
620
576
  const reason = this.status === ProviderStatus2.STALE ? StandardResolutionReasons.CACHED : evalReason;
621
- return __spreadProps(__spreadValues({
622
- value
623
- }, variant && { variant }), {
577
+ return {
578
+ value,
579
+ ...variant && { variant },
624
580
  reason
625
- });
581
+ };
626
582
  }
627
583
  };
628
584
 
@@ -630,12 +586,12 @@ var InMemoryProvider = class {
630
586
  var GLOBAL_OPENFEATURE_API_KEY = Symbol.for("@openfeature/web-sdk/api");
631
587
  var _globalThis = globalThis;
632
588
  var OpenFeatureAPI = class extends OpenFeatureCommonAPI {
589
+ _events = new OpenFeatureEventEmitter();
590
+ _defaultProvider = NOOP_PROVIDER;
591
+ _createEventEmitter = () => new OpenFeatureEventEmitter();
592
+ _namedProviderContext = /* @__PURE__ */ new Map();
633
593
  constructor() {
634
594
  super("client");
635
- this._events = new OpenFeatureEventEmitter();
636
- this._defaultProvider = NOOP_PROVIDER;
637
- this._createEventEmitter = () => new OpenFeatureEventEmitter();
638
- this._namedProviderContext = /* @__PURE__ */ new Map();
639
595
  }
640
596
  /**
641
597
  * Gets a singleton instance of the OpenFeature API.
@@ -651,39 +607,36 @@ var OpenFeatureAPI = class extends OpenFeatureCommonAPI {
651
607
  _globalThis[GLOBAL_OPENFEATURE_API_KEY] = instance;
652
608
  return instance;
653
609
  }
654
- setContext(nameOrContext, contextOrUndefined) {
655
- return __async(this, null, function* () {
656
- var _a, _b;
657
- const clientName = stringOrUndefined(nameOrContext);
658
- const context = (_b = (_a = objectOrUndefined(nameOrContext)) != null ? _a : objectOrUndefined(contextOrUndefined)) != null ? _b : {};
659
- if (clientName) {
660
- const provider = this._clientProviders.get(clientName);
661
- if (provider) {
662
- const oldContext = this.getContext(clientName);
663
- this._namedProviderContext.set(clientName, context);
664
- yield this.runProviderContextChangeHandler(clientName, provider, oldContext, context);
665
- } else {
666
- this._namedProviderContext.set(clientName, context);
667
- }
610
+ async setContext(nameOrContext, contextOrUndefined) {
611
+ const clientName = stringOrUndefined(nameOrContext);
612
+ const context = objectOrUndefined(nameOrContext) ?? objectOrUndefined(contextOrUndefined) ?? {};
613
+ if (clientName) {
614
+ const provider = this._clientProviders.get(clientName);
615
+ if (provider) {
616
+ const oldContext = this.getContext(clientName);
617
+ this._namedProviderContext.set(clientName, context);
618
+ await this.runProviderContextChangeHandler(clientName, provider, oldContext, context);
668
619
  } else {
669
- const oldContext = this._context;
670
- this._context = context;
671
- const defaultContextNameProviders = Array.from(this._clientProviders.entries()).filter(([name]) => !this._namedProviderContext.has(name)).reduce((acc, [name, provider]) => {
672
- acc.push({ name, provider });
673
- return acc;
674
- }, []);
675
- const allProviders = [
676
- // add in the default (no name)
677
- { name: void 0, provider: this._defaultProvider },
678
- ...defaultContextNameProviders
679
- ];
680
- yield Promise.all(
681
- allProviders.map(
682
- (tuple) => this.runProviderContextChangeHandler(tuple.name, tuple.provider, oldContext, context)
683
- )
684
- );
620
+ this._namedProviderContext.set(clientName, context);
685
621
  }
686
- });
622
+ } else {
623
+ const oldContext = this._context;
624
+ this._context = context;
625
+ const defaultContextNameProviders = Array.from(this._clientProviders.entries()).filter(([name]) => !this._namedProviderContext.has(name)).reduce((acc, [name, provider]) => {
626
+ acc.push({ name, provider });
627
+ return acc;
628
+ }, []);
629
+ const allProviders = [
630
+ // add in the default (no name)
631
+ { name: void 0, provider: this._defaultProvider },
632
+ ...defaultContextNameProviders
633
+ ];
634
+ await Promise.all(
635
+ allProviders.map(
636
+ (tuple) => this.runProviderContextChangeHandler(tuple.name, tuple.provider, oldContext, context)
637
+ )
638
+ );
639
+ }
687
640
  }
688
641
  getContext(nameOrUndefined) {
689
642
  const clientName = stringOrUndefined(nameOrUndefined);
@@ -697,33 +650,29 @@ var OpenFeatureAPI = class extends OpenFeatureCommonAPI {
697
650
  }
698
651
  return this._context;
699
652
  }
700
- clearContext(nameOrUndefined) {
701
- return __async(this, null, function* () {
702
- const clientName = stringOrUndefined(nameOrUndefined);
703
- if (clientName) {
704
- const provider = this._clientProviders.get(clientName);
705
- if (provider) {
706
- const oldContext = this.getContext(clientName);
707
- this._namedProviderContext.delete(clientName);
708
- const newContext = this.getContext();
709
- yield this.runProviderContextChangeHandler(clientName, provider, oldContext, newContext);
710
- } else {
711
- this._namedProviderContext.delete(clientName);
712
- }
653
+ async clearContext(nameOrUndefined) {
654
+ const clientName = stringOrUndefined(nameOrUndefined);
655
+ if (clientName) {
656
+ const provider = this._clientProviders.get(clientName);
657
+ if (provider) {
658
+ const oldContext = this.getContext(clientName);
659
+ this._namedProviderContext.delete(clientName);
660
+ const newContext = this.getContext();
661
+ await this.runProviderContextChangeHandler(clientName, provider, oldContext, newContext);
713
662
  } else {
714
- return this.setContext({});
663
+ this._namedProviderContext.delete(clientName);
715
664
  }
716
- });
665
+ } else {
666
+ return this.setContext({});
667
+ }
717
668
  }
718
669
  /**
719
670
  * Resets the global evaluation context and removes the evaluation context for
720
671
  * all named clients.
721
672
  */
722
- clearContexts() {
723
- return __async(this, null, function* () {
724
- yield this.clearContext();
725
- yield Promise.allSettled(Array.from(this._clientProviders.keys()).map((name) => this.clearContext(name)));
726
- });
673
+ async clearContexts() {
674
+ await this.clearContext();
675
+ await Promise.allSettled(Array.from(this._clientProviders.keys()).map((name) => this.clearContext(name)));
727
676
  }
728
677
  /**
729
678
  * A factory function for creating new named OpenFeature clients. Clients can contain
@@ -750,32 +699,27 @@ var OpenFeatureAPI = class extends OpenFeatureCommonAPI {
750
699
  * Clears all registered providers and resets the default provider.
751
700
  * @returns {Promise<void>}
752
701
  */
753
- clearProviders() {
754
- return __async(this, null, function* () {
755
- yield __superGet(OpenFeatureAPI.prototype, this, "clearProvidersAndSetDefault").call(this, NOOP_PROVIDER);
756
- this._namedProviderContext.clear();
757
- });
702
+ async clearProviders() {
703
+ await super.clearProvidersAndSetDefault(NOOP_PROVIDER);
704
+ this._namedProviderContext.clear();
758
705
  }
759
- runProviderContextChangeHandler(clientName, provider, oldContext, newContext) {
760
- return __async(this, null, function* () {
761
- var _a, _b, _c, _d, _e;
762
- const providerName = provider.metadata.name;
763
- try {
764
- yield (_a = provider.onContextChange) == null ? void 0 : _a.call(provider, oldContext, newContext);
765
- this.getAssociatedEventEmitters(clientName).forEach((emitter) => {
766
- emitter == null ? void 0 : emitter.emit(ClientProviderEvents.ContextChanged, { clientName, providerName });
767
- });
768
- (_b = this._events) == null ? void 0 : _b.emit(ClientProviderEvents.ContextChanged, { clientName, providerName });
769
- } catch (err) {
770
- const error = err;
771
- const message = `Error running ${(_c = provider == null ? void 0 : provider.metadata) == null ? void 0 : _c.name}'s context change handler: ${error == null ? void 0 : error.message}`;
772
- (_d = this._logger) == null ? void 0 : _d.error(`${message}`, err);
773
- this.getAssociatedEventEmitters(clientName).forEach((emitter) => {
774
- emitter == null ? void 0 : emitter.emit(ClientProviderEvents.Error, { clientName, providerName, message });
775
- });
776
- (_e = this._events) == null ? void 0 : _e.emit(ClientProviderEvents.Error, { clientName, providerName, message });
777
- }
778
- });
706
+ async runProviderContextChangeHandler(clientName, provider, oldContext, newContext) {
707
+ const providerName = provider.metadata.name;
708
+ try {
709
+ await provider.onContextChange?.(oldContext, newContext);
710
+ this.getAssociatedEventEmitters(clientName).forEach((emitter) => {
711
+ emitter?.emit(ClientProviderEvents.ContextChanged, { clientName, providerName });
712
+ });
713
+ this._events?.emit(ClientProviderEvents.ContextChanged, { clientName, providerName });
714
+ } catch (err) {
715
+ const error = err;
716
+ const message = `Error running ${provider?.metadata?.name}'s context change handler: ${error?.message}`;
717
+ this._logger?.error(`${message}`, err);
718
+ this.getAssociatedEventEmitters(clientName).forEach((emitter) => {
719
+ emitter?.emit(ClientProviderEvents.Error, { clientName, providerName, message });
720
+ });
721
+ this._events?.emit(ClientProviderEvents.Error, { clientName, providerName, message });
722
+ }
779
723
  }
780
724
  };
781
725
  var OpenFeature = OpenFeatureAPI.getInstance();
@@ -787,8 +731,9 @@ var OpenFeatureClient = class {
787
731
  this.emitterAccessor = emitterAccessor;
788
732
  this.globalLogger = globalLogger;
789
733
  this.options = options;
790
- this._hooks = [];
791
734
  }
735
+ _hooks = [];
736
+ _clientLogger;
792
737
  get metadata() {
793
738
  return {
794
739
  name: this.options.name,
@@ -797,18 +742,16 @@ var OpenFeatureClient = class {
797
742
  };
798
743
  }
799
744
  get providerStatus() {
800
- var _a;
801
- return ((_a = this.providerAccessor()) == null ? void 0 : _a.status) || ProviderStatus3.READY;
745
+ return this.providerAccessor()?.status || ProviderStatus3.READY;
802
746
  }
803
747
  addHandler(eventType, handler) {
804
- var _a;
805
748
  this.emitterAccessor().addHandler(eventType, handler);
806
749
  const shouldRunNow = statusMatchesEvent(eventType, this._provider.status);
807
750
  if (shouldRunNow) {
808
751
  try {
809
752
  handler({ clientName: this.metadata.name, providerName: this._provider.metadata.name });
810
753
  } catch (err) {
811
- (_a = this._logger) == null ? void 0 : _a.error("Error running event handler:", err);
754
+ this._logger?.error("Error running event handler:", err);
812
755
  }
813
756
  }
814
757
  }
@@ -872,7 +815,6 @@ var OpenFeatureClient = class {
872
815
  return this.evaluate(flagKey, this._provider.resolveObjectEvaluation, defaultValue, "object", options);
873
816
  }
874
817
  evaluate(flagKey, resolver, defaultValue, flagType, options = {}) {
875
- var _a, _b;
876
818
  const allHooks = [
877
819
  ...OpenFeature.getHooks(),
878
820
  ...this.getHooks(),
@@ -880,7 +822,9 @@ var OpenFeatureClient = class {
880
822
  ...this._provider.hooks || []
881
823
  ];
882
824
  const allHooksReversed = [...allHooks].reverse();
883
- const context = __spreadValues({}, OpenFeature.getContext((_a = this == null ? void 0 : this.options) == null ? void 0 : _a.name));
825
+ const context = {
826
+ ...OpenFeature.getContext(this?.options?.name)
827
+ };
884
828
  const hookContext = {
885
829
  flagKey,
886
830
  defaultValue,
@@ -893,15 +837,16 @@ var OpenFeatureClient = class {
893
837
  try {
894
838
  this.beforeHooks(allHooks, hookContext, options);
895
839
  const resolution = resolver.call(this._provider, flagKey, defaultValue, context, this._logger);
896
- const evaluationDetails = __spreadProps(__spreadValues({}, resolution), {
897
- flagMetadata: Object.freeze((_b = resolution.flagMetadata) != null ? _b : {}),
840
+ const evaluationDetails = {
841
+ ...resolution,
842
+ flagMetadata: Object.freeze(resolution.flagMetadata ?? {}),
898
843
  flagKey
899
- });
844
+ };
900
845
  this.afterHooks(allHooksReversed, hookContext, evaluationDetails, options);
901
846
  return evaluationDetails;
902
847
  } catch (err) {
903
- const errorMessage = err == null ? void 0 : err.message;
904
- const errorCode = (err == null ? void 0 : err.code) || ErrorCode2.GENERAL;
848
+ const errorMessage = err?.message;
849
+ const errorCode = err?.code || ErrorCode2.GENERAL;
905
850
  this.errorHooks(allHooksReversed, hookContext, err, options);
906
851
  return {
907
852
  errorCode,
@@ -916,44 +861,40 @@ var OpenFeatureClient = class {
916
861
  }
917
862
  }
918
863
  beforeHooks(hooks, hookContext, options) {
919
- var _a;
920
864
  Object.freeze(hookContext);
921
865
  Object.freeze(hookContext.context);
922
866
  for (const hook of hooks) {
923
- (_a = hook == null ? void 0 : hook.before) == null ? void 0 : _a.call(hook, hookContext, Object.freeze(options.hookHints));
867
+ hook?.before?.(hookContext, Object.freeze(options.hookHints));
924
868
  }
925
869
  }
926
870
  afterHooks(hooks, hookContext, evaluationDetails, options) {
927
- var _a;
928
871
  for (const hook of hooks) {
929
- (_a = hook == null ? void 0 : hook.after) == null ? void 0 : _a.call(hook, hookContext, evaluationDetails, options.hookHints);
872
+ hook?.after?.(hookContext, evaluationDetails, options.hookHints);
930
873
  }
931
874
  }
932
875
  errorHooks(hooks, hookContext, err, options) {
933
- var _a;
934
876
  for (const hook of hooks) {
935
877
  try {
936
- (_a = hook == null ? void 0 : hook.error) == null ? void 0 : _a.call(hook, hookContext, err, options.hookHints);
878
+ hook?.error?.(hookContext, err, options.hookHints);
937
879
  } catch (err2) {
938
880
  this._logger.error(`Unhandled error during 'error' hook: ${err2}`);
939
881
  if (err2 instanceof Error) {
940
882
  this._logger.error(err2.stack);
941
883
  }
942
- this._logger.error(err2 == null ? void 0 : err2.stack);
884
+ this._logger.error(err2?.stack);
943
885
  }
944
886
  }
945
887
  }
946
888
  finallyHooks(hooks, hookContext, options) {
947
- var _a;
948
889
  for (const hook of hooks) {
949
890
  try {
950
- (_a = hook == null ? void 0 : hook.finally) == null ? void 0 : _a.call(hook, hookContext, options.hookHints);
891
+ hook?.finally?.(hookContext, options.hookHints);
951
892
  } catch (err) {
952
893
  this._logger.error(`Unhandled error during 'finally' hook: ${err}`);
953
894
  if (err instanceof Error) {
954
895
  this._logger.error(err.stack);
955
896
  }
956
- this._logger.error(err == null ? void 0 : err.stack);
897
+ this._logger.error(err?.stack);
957
898
  }
958
899
  }
959
900
  }