lifecycleion 0.0.19 → 0.0.21

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.
Files changed (74) hide show
  1. package/README.md +39 -36
  2. package/dist/lib/event-emitter.cjs +195 -9
  3. package/dist/lib/event-emitter.cjs.map +1 -1
  4. package/dist/lib/event-emitter.js +195 -9
  5. package/dist/lib/event-emitter.js.map +1 -1
  6. package/dist/lib/global-event-target.cjs +217 -0
  7. package/dist/lib/global-event-target.cjs.map +1 -0
  8. package/dist/lib/global-event-target.d.cts +70 -0
  9. package/dist/lib/global-event-target.d.ts +70 -0
  10. package/dist/lib/global-event-target.js +189 -0
  11. package/dist/lib/global-event-target.js.map +1 -0
  12. package/dist/lib/http-client/index.cjs +554 -193
  13. package/dist/lib/http-client/index.cjs.map +1 -1
  14. package/dist/lib/http-client/index.d.cts +9 -3
  15. package/dist/lib/http-client/index.d.ts +9 -3
  16. package/dist/lib/http-client/index.js +554 -193
  17. package/dist/lib/http-client/index.js.map +1 -1
  18. package/dist/lib/http-client-mock/index.cjs +71 -24
  19. package/dist/lib/http-client-mock/index.cjs.map +1 -1
  20. package/dist/lib/http-client-mock/index.d.cts +50 -2
  21. package/dist/lib/http-client-mock/index.d.ts +50 -2
  22. package/dist/lib/http-client-mock/index.js +71 -24
  23. package/dist/lib/http-client-mock/index.js.map +1 -1
  24. package/dist/lib/http-client-node/index.cjs +135 -33
  25. package/dist/lib/http-client-node/index.cjs.map +1 -1
  26. package/dist/lib/http-client-node/index.d.cts +33 -2
  27. package/dist/lib/http-client-node/index.d.ts +33 -2
  28. package/dist/lib/http-client-node/index.js +135 -33
  29. package/dist/lib/http-client-node/index.js.map +1 -1
  30. package/dist/lib/http-client-xhr/index.cjs +0 -14
  31. package/dist/lib/http-client-xhr/index.cjs.map +1 -1
  32. package/dist/lib/http-client-xhr/index.d.cts +3 -2
  33. package/dist/lib/http-client-xhr/index.d.ts +3 -2
  34. package/dist/lib/http-client-xhr/index.js +0 -14
  35. package/dist/lib/http-client-xhr/index.js.map +1 -1
  36. package/dist/lib/lifecycle-manager/index.cjs +199 -13
  37. package/dist/lib/lifecycle-manager/index.cjs.map +1 -1
  38. package/dist/lib/lifecycle-manager/index.js +199 -13
  39. package/dist/lib/lifecycle-manager/index.js.map +1 -1
  40. package/dist/lib/logger/index.cjs +203 -21
  41. package/dist/lib/logger/index.cjs.map +1 -1
  42. package/dist/lib/logger/index.d.cts +5 -1
  43. package/dist/lib/logger/index.d.ts +5 -1
  44. package/dist/lib/logger/index.js +203 -21
  45. package/dist/lib/logger/index.js.map +1 -1
  46. package/dist/lib/lru-cache/index.cjs +195 -9
  47. package/dist/lib/lru-cache/index.cjs.map +1 -1
  48. package/dist/lib/lru-cache/index.js +195 -9
  49. package/dist/lib/lru-cache/index.js.map +1 -1
  50. package/dist/lib/process-signal-manager.cjs +199 -13
  51. package/dist/lib/process-signal-manager.cjs.map +1 -1
  52. package/dist/lib/process-signal-manager.js +199 -13
  53. package/dist/lib/process-signal-manager.js.map +1 -1
  54. package/dist/lib/promise-protected-resolver.cjs +195 -9
  55. package/dist/lib/promise-protected-resolver.cjs.map +1 -1
  56. package/dist/lib/promise-protected-resolver.js +195 -9
  57. package/dist/lib/promise-protected-resolver.js.map +1 -1
  58. package/dist/lib/retry-utils/index.cjs +195 -9
  59. package/dist/lib/retry-utils/index.cjs.map +1 -1
  60. package/dist/lib/retry-utils/index.js +195 -9
  61. package/dist/lib/retry-utils/index.js.map +1 -1
  62. package/dist/lib/safe-handle-callback.cjs +196 -18
  63. package/dist/lib/safe-handle-callback.cjs.map +1 -1
  64. package/dist/lib/safe-handle-callback.d.cts +14 -4
  65. package/dist/lib/safe-handle-callback.d.ts +14 -4
  66. package/dist/lib/safe-handle-callback.js +196 -18
  67. package/dist/lib/safe-handle-callback.js.map +1 -1
  68. package/dist/lib/single-event-observer.cjs +195 -9
  69. package/dist/lib/single-event-observer.cjs.map +1 -1
  70. package/dist/lib/single-event-observer.js +195 -9
  71. package/dist/lib/single-event-observer.js.map +1 -1
  72. package/dist/{types-CWw885iO.d.cts → types-BFvpJPMt.d.cts} +72 -11
  73. package/dist/{types-Mso0dYOS.d.ts → types-BONtIhQ5.d.ts} +72 -11
  74. package/package.json +31 -12
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Lifecycleion v0.0.19
1
+ # Lifecycleion v0.0.21
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/lifecycleion.svg)](https://badge.fury.io/js/lifecycleion)
4
4
 
@@ -43,7 +43,9 @@ yarn add lifecycleion
43
43
  bun add lifecycleion
44
44
  ```
45
45
 
46
- For Node.js runtimes, Lifecycleion currently targets `Node >=25`. Some libraries, including `safe-handle-callback` and `lru-cache`'s `onChange`, rely on browser-style global error event APIs such as `ErrorEvent`, which are also available in Bun, Deno, and modern browsers.
46
+ For Node.js runtimes, Lifecycleion currently targets `Node >=25`. Some libraries, including `safe-handle-callback`, `logger`'s `reportError` listener, and `lru-cache`'s `onChange`, report errors using Lifecycleion's `'reportError'` convention: an `ErrorEvent` dispatched through the global `EventTarget` methods. Those are web-standard primitives (the `'reportError'` event type itself is Lifecycleion's convention, not a web standard), and browsers, Bun, and Deno expose them on `globalThis` natively.
47
+
48
+ Node.js is a partial case: `ErrorEvent` is native in Node 25+, but `globalThis` is still not an `EventTarget`, so Lifecycleion automatically supplies the missing global event methods without overwriting native or user-installed implementations. See [global-event-target](./docs/global-event-target.md).
47
49
 
48
50
  ## Quick Example
49
51
 
@@ -91,40 +93,41 @@ Tip: listen for `lifecycle-manager:shutdown-completed` when you want one place t
91
93
 
92
94
  Each library has comprehensive documentation in the [docs](./docs) folder. Click on any library name in the table below to view detailed usage examples, API references, and best practices.
93
95
 
94
- | Library | Import Path | Description |
95
- | ------------------------------------------------------------------ | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
96
- | [arrays](./docs/arrays.md) | `lifecycleion/arrays` | Array utility functions for filtering, comparison, deduplication, and string manipulation |
97
- | [ascii-tables](./docs/ascii-tables.md) | `lifecycleion/ascii-tables` | Key-value and multi-column ASCII tables with word wrapping, nesting, and emoji support |
98
- | [clamp](./docs/clamp.md) | `lifecycleion/clamp` | Number clamping utilities with safe handling for non-finite values and nullish inputs |
99
- | [constants](./docs/constants.md) | `lifecycleion/constants` | Common string constants including whitespace helpers and Python-style character sets |
100
- | [curly-brackets](./docs/curly-brackets.md) | `lifecycleion/curly-brackets` | String templating with `{{placeholders}}`, fallbacks, escaping, and compiled templates |
101
- | [deep-clone](./docs/deep-clone.md) | `lifecycleion/deep-clone` | Deep clone utility with circular reference detection for objects, arrays, Maps, Sets, and more |
102
- | [dev-mode](./docs/dev-mode.md) | `lifecycleion/dev-mode` | Runtime-settable dev/production mode flag with auto-detection from CLI args or NODE_ENV |
103
- | [domain-utils](./docs/domain-utils.md) | `lifecycleion/domain-utils` | Hardened helpers for normalizing and matching domains and origins for CORS and routing, with IDNA/TR46, IPv6, and wildcard semantics |
104
- | [error-to-string](./docs/error-to-string.md) | `lifecycleion/error-to-string` | Format errors into readable ASCII tables with support for nested info and sensitive field masking |
105
- | [event-emitter](./docs/event-emitter.md) | `lifecycleion/event-emitter` | Lightweight event emitter with protected and public variants, type safety, and memory management |
106
- | [http-client](./docs/http-client.md) | `lifecycleion/http-client` (+ `-node`, `-xhr`, `-mock`) | Fluent HTTP client with Fetch, Node.js native, XHR, and Mock adapters, interceptors, observers, retries, cookies, and redirect control |
107
- | [id-helpers](./docs/id-helpers.md) | `lifecycleion/id-helpers` | Unified ID generation and validation for ObjectID, UUID v4, UUID v7, and ULID |
108
- | [is-boolean](./docs/is-boolean.md) | `lifecycleion/is-boolean` | Type guard to check if a value is a boolean |
109
- | [is-function](./docs/is-function.md) | `lifecycleion/is-function` | Check whether a value is a function |
110
- | [is-number](./docs/is-number.md) | `lifecycleion/is-number` | Type guards to check whether a value is a valid number, with and without finite enforcement |
111
- | [is-plain-object](./docs/is-plain-object.md) | `lifecycleion/is-plain-object` | Type guard to check if a value is a plain object (not null, not an array) |
112
- | [is-promise](./docs/is-promise.md) | `lifecycleion/is-promise` | Thenable/promise detection following the Promises/A+ specification |
113
- | [json-helpers](./docs/json-helpers.md) | `lifecycleion/json-helpers` | JSON formatting utilities |
114
- | [lru-cache](./docs/lru-cache.md) | `lifecycleion/lru-cache` | TTL-aware LRU cache with entry-count and size-based eviction, custom size calculators, and per-entry TTL overrides |
115
- | [lifecycle-manager](./docs/lifecycle-manager.md) | `lifecycleion/lifecycle-manager` | Lifecycle orchestration for managing startup, shutdown, and runtime control of application components |
116
- | [logger](./docs/logger.md) | `lifecycleion/logger` | Flexible sink-based logger with log levels, redaction, template strings, and service scoping |
117
- | [padding-utils](./docs/padding-utils.md) | `lifecycleion/padding-utils` | String padding utilities for left, right, and center alignment with a configurable pad character |
118
- | [process-signal-manager](./docs/process-signal-manager.md) | `lifecycleion/process-signal-manager` | Unified handler for process signals (SIGINT, SIGTERM, SIGHUP, etc.) and keyboard shortcuts with graceful shutdown and hot-reload support |
119
- | [promise-protected-resolver](./docs/promise-protected-resolver.md) | `lifecycleion/promise-protected-resolver` | Promise wrapper with `resolveOnce` and `rejectOnce` that guarantee a promise is only settled once |
120
- | [retry-utils](./docs/retry-utils.md) | `lifecycleion/retry-utils` | Retry logic with fixed and exponential backoff via `RetryPolicy` (low-level) and `RetryRunner` (high-level with events and cancellation) |
121
- | [safe-handle-callback](./docs/safe-handle-callback.md) | `lifecycleion/safe-handle-callback` | Safely execute sync or async callbacks with automatic error reporting via browser-style `reportError`/`ErrorEvent` globals |
122
- | [serialize-error](./docs/serialize-error.md) | `lifecycleion/serialize-error` | Convert any `Error` into a plain JSON-serializable object and back again for IPC, RPCs, and database storage |
123
- | [single-event-observer](./docs/single-event-observer.md) | `lifecycleion/single-event-observer` | Lightweight type-safe observer pattern for a single event type, with public and protected notify variants |
124
- | [sleep](./docs/sleep.md) | `lifecycleion/sleep` | Pause async execution for a given number of milliseconds |
125
- | [strings](./docs/strings.md) | `lifecycleion/strings` | String type guard, case conversion (PascalCase, camelCase, CONSTANT_CASE), grapheme splitting, character filtering, and chopping helpers |
126
- | [tmp-dir](./docs/tmp-dir.md) | `lifecycleion/tmp-dir` | Create and automatically clean up uniquely-named temporary directories with configurable prefix, postfix, and unsafe cleanup support |
127
- | [unix-time-helpers](./docs/unix-time-helpers.md) | `lifecycleion/unix-time-helpers` | Unix timestamp utilities for seconds, milliseconds, high-resolution timing, and unit conversion |
96
+ | Library | Import Path | Description |
97
+ | ------------------------------------------------------------------ | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
98
+ | [arrays](./docs/arrays.md) | `lifecycleion/arrays` | Array utility functions for filtering, comparison, deduplication, and string manipulation |
99
+ | [ascii-tables](./docs/ascii-tables.md) | `lifecycleion/ascii-tables` | Key-value and multi-column ASCII tables with word wrapping, nesting, and emoji support |
100
+ | [clamp](./docs/clamp.md) | `lifecycleion/clamp` | Number clamping utilities with safe handling for non-finite values and nullish inputs |
101
+ | [constants](./docs/constants.md) | `lifecycleion/constants` | Common string constants including whitespace helpers and Python-style character sets |
102
+ | [curly-brackets](./docs/curly-brackets.md) | `lifecycleion/curly-brackets` | String templating with `{{placeholders}}`, fallbacks, escaping, and compiled templates |
103
+ | [deep-clone](./docs/deep-clone.md) | `lifecycleion/deep-clone` | Deep clone utility with circular reference detection for objects, arrays, Maps, Sets, and more |
104
+ | [dev-mode](./docs/dev-mode.md) | `lifecycleion/dev-mode` | Runtime-settable dev/production mode flag with auto-detection from CLI args or NODE_ENV |
105
+ | [domain-utils](./docs/domain-utils.md) | `lifecycleion/domain-utils` | Hardened helpers for normalizing and matching domains and origins for CORS and routing, with IDNA/TR46, IPv6, and wildcard semantics |
106
+ | [error-to-string](./docs/error-to-string.md) | `lifecycleion/error-to-string` | Format errors into readable ASCII tables with support for nested info and sensitive field masking |
107
+ | [event-emitter](./docs/event-emitter.md) | `lifecycleion/event-emitter` | Lightweight event emitter with protected and public variants, type safety, and memory management |
108
+ | [global-event-target](./docs/global-event-target.md) | `lifecycleion/global-event-target` | Conservative polyfill giving `globalThis` the `EventTarget` methods on Node.js, so `'reportError'` dispatch works there |
109
+ | [http-client](./docs/http-client.md) | `lifecycleion/http-client` (+ `-node`, `-xhr`, `-mock`) | Fluent HTTP client with Fetch, Node.js native, XHR, and Mock adapters, interceptors, observers, retries, cookies, and redirect control |
110
+ | [id-helpers](./docs/id-helpers.md) | `lifecycleion/id-helpers` | Unified ID generation and validation for ObjectID, UUID v4, UUID v7, and ULID |
111
+ | [is-boolean](./docs/is-boolean.md) | `lifecycleion/is-boolean` | Type guard to check if a value is a boolean |
112
+ | [is-function](./docs/is-function.md) | `lifecycleion/is-function` | Check whether a value is a function |
113
+ | [is-number](./docs/is-number.md) | `lifecycleion/is-number` | Type guards to check whether a value is a valid number, with and without finite enforcement |
114
+ | [is-plain-object](./docs/is-plain-object.md) | `lifecycleion/is-plain-object` | Type guard to check if a value is a plain object (not null, not an array) |
115
+ | [is-promise](./docs/is-promise.md) | `lifecycleion/is-promise` | Thenable/promise detection following the Promises/A+ specification |
116
+ | [json-helpers](./docs/json-helpers.md) | `lifecycleion/json-helpers` | JSON formatting utilities |
117
+ | [lru-cache](./docs/lru-cache.md) | `lifecycleion/lru-cache` | TTL-aware LRU cache with entry-count and size-based eviction, custom size calculators, and per-entry TTL overrides |
118
+ | [lifecycle-manager](./docs/lifecycle-manager.md) | `lifecycleion/lifecycle-manager` | Lifecycle orchestration for managing startup, shutdown, and runtime control of application components |
119
+ | [logger](./docs/logger.md) | `lifecycleion/logger` | Flexible sink-based logger with log levels, redaction, template strings, and service scoping |
120
+ | [padding-utils](./docs/padding-utils.md) | `lifecycleion/padding-utils` | String padding utilities for left, right, and center alignment with a configurable pad character |
121
+ | [process-signal-manager](./docs/process-signal-manager.md) | `lifecycleion/process-signal-manager` | Unified handler for process signals (SIGINT, SIGTERM, SIGHUP, etc.) and keyboard shortcuts with graceful shutdown and hot-reload support |
122
+ | [promise-protected-resolver](./docs/promise-protected-resolver.md) | `lifecycleion/promise-protected-resolver` | Promise wrapper with `resolveOnce` and `rejectOnce` that guarantee a promise is only settled once |
123
+ | [retry-utils](./docs/retry-utils.md) | `lifecycleion/retry-utils` | Retry logic with fixed and exponential backoff via `RetryPolicy` (low-level) and `RetryRunner` (high-level with events and cancellation) |
124
+ | [safe-handle-callback](./docs/safe-handle-callback.md) | `lifecycleion/safe-handle-callback` | Safely execute sync or async callbacks with automatic error reporting via the `'reportError'` convention (`ErrorEvent` + global `EventTarget`) |
125
+ | [serialize-error](./docs/serialize-error.md) | `lifecycleion/serialize-error` | Convert any `Error` into a plain JSON-serializable object and back again for IPC, RPCs, and database storage |
126
+ | [single-event-observer](./docs/single-event-observer.md) | `lifecycleion/single-event-observer` | Lightweight type-safe observer pattern for a single event type, with public and protected notify variants |
127
+ | [sleep](./docs/sleep.md) | `lifecycleion/sleep` | Pause async execution for a given number of milliseconds |
128
+ | [strings](./docs/strings.md) | `lifecycleion/strings` | String type guard, case conversion (PascalCase, camelCase, CONSTANT_CASE), grapheme splitting, character filtering, and chopping helpers |
129
+ | [tmp-dir](./docs/tmp-dir.md) | `lifecycleion/tmp-dir` | Create and automatically clean up uniquely-named temporary directories with configurable prefix, postfix, and unsafe cleanup support |
130
+ | [unix-time-helpers](./docs/unix-time-helpers.md) | `lifecycleion/unix-time-helpers` | Unix timestamp utilities for seconds, milliseconds, high-resolution timing, and unit conversion |
128
131
 
129
132
  ## Change Log
130
133
 
@@ -751,18 +751,204 @@ function isFunction(value) {
751
751
  return typeof value === "function" || value instanceof Function;
752
752
  }
753
753
 
754
+ // src/lib/global-event-target.ts
755
+ var GLOBAL_KEY = "__lifecycleion_global_event_target__";
756
+ var METHOD_NAMES = [
757
+ "addEventListener",
758
+ "removeEventListener",
759
+ "dispatchEvent"
760
+ ];
761
+ var g = globalThis;
762
+ function getState() {
763
+ const value = readGlobal(GLOBAL_KEY);
764
+ return value === UNREADABLE ? void 0 : asUsableState(value);
765
+ }
766
+ function asUsableState(value) {
767
+ if (typeof value !== "object" || value === null) {
768
+ return void 0;
769
+ }
770
+ return asUsableTarget(readMember(value, "target")) === null ? void 0 : value;
771
+ }
772
+ function asUsableTarget(value) {
773
+ if (typeof value !== "object" || value === null) {
774
+ return null;
775
+ }
776
+ for (const name of METHOD_NAMES) {
777
+ if (typeof readMember(value, name) !== "function") {
778
+ return null;
779
+ }
780
+ }
781
+ return value;
782
+ }
783
+ function bindTargetMethods(target) {
784
+ const bound = {};
785
+ for (const name of METHOD_NAMES) {
786
+ const method = readMember(target, name);
787
+ if (typeof method !== "function") {
788
+ return null;
789
+ }
790
+ let boundMethod;
791
+ try {
792
+ boundMethod = method.bind(target);
793
+ } catch {
794
+ return null;
795
+ }
796
+ if (typeof boundMethod !== "function") {
797
+ return null;
798
+ }
799
+ bound[name] = boundMethod;
800
+ }
801
+ return bound;
802
+ }
803
+ function isStateInstalled(state) {
804
+ return state !== void 0 && readMember(state, "isInstalled") === true;
805
+ }
806
+ function readStateTarget(state) {
807
+ if (state === void 0) {
808
+ return null;
809
+ }
810
+ return asUsableTarget(readMember(state, "target"));
811
+ }
812
+ var UNREADABLE = /* @__PURE__ */ Symbol("lifecycleion.unreadable");
813
+ function readGlobal(name) {
814
+ try {
815
+ return g[name];
816
+ } catch {
817
+ return UNREADABLE;
818
+ }
819
+ }
820
+ function readMember(source, key) {
821
+ try {
822
+ return source[key];
823
+ } catch {
824
+ return UNREADABLE;
825
+ }
826
+ }
827
+ function probeMember(name) {
828
+ const value = readGlobal(name);
829
+ if (value === UNREADABLE) {
830
+ return "hostile";
831
+ }
832
+ if (typeof value === "function") {
833
+ return "usable";
834
+ }
835
+ return value === void 0 ? "absent" : "occupied";
836
+ }
837
+ function canDefineProperty(key) {
838
+ const descriptor = Object.getOwnPropertyDescriptor(g, key);
839
+ if (descriptor === void 0) {
840
+ return Object.isExtensible(g);
841
+ }
842
+ return descriptor.configurable === true;
843
+ }
844
+ function installGlobalEventTarget() {
845
+ const members = METHOD_NAMES.map((name) => probeMember(name));
846
+ if (members.every((member) => member === "usable")) {
847
+ return isStateInstalled(getState()) ? "already-installed" : "native";
848
+ }
849
+ if (members.some((member) => member !== "absent")) {
850
+ return "partial";
851
+ }
852
+ const eventTargetConstructor = readGlobal("EventTarget");
853
+ if (typeof eventTargetConstructor !== "function") {
854
+ return "unsupported";
855
+ }
856
+ const isDefinable = [...METHOD_NAMES, GLOBAL_KEY].every(
857
+ (key) => canDefineProperty(key)
858
+ );
859
+ if (!isDefinable) {
860
+ return "blocked";
861
+ }
862
+ const existingState = getState();
863
+ const defined = [];
864
+ const priorStateDescriptor = Object.getOwnPropertyDescriptor(g, GLOBAL_KEY);
865
+ const rollback = () => {
866
+ for (const key of defined) {
867
+ if (key === GLOBAL_KEY && priorStateDescriptor !== void 0) {
868
+ try {
869
+ Object.defineProperty(g, GLOBAL_KEY, priorStateDescriptor);
870
+ } catch {
871
+ }
872
+ continue;
873
+ }
874
+ try {
875
+ Reflect.deleteProperty(g, key);
876
+ } catch {
877
+ }
878
+ }
879
+ };
880
+ const reusableTarget = readStateTarget(existingState);
881
+ const reusableMethods = reusableTarget === null ? null : bindTargetMethods(reusableTarget);
882
+ let state;
883
+ let methods;
884
+ try {
885
+ if (existingState === void 0 || reusableMethods === null) {
886
+ let target;
887
+ try {
888
+ target = new eventTargetConstructor();
889
+ } catch {
890
+ return "unsupported";
891
+ }
892
+ const freshMethods = bindTargetMethods(target);
893
+ if (freshMethods === null) {
894
+ return "unsupported";
895
+ }
896
+ state = { target, isInstalled: false };
897
+ methods = freshMethods;
898
+ Object.defineProperty(g, GLOBAL_KEY, {
899
+ value: state,
900
+ enumerable: false,
901
+ writable: false,
902
+ configurable: true
903
+ });
904
+ defined.push(GLOBAL_KEY);
905
+ } else {
906
+ state = existingState;
907
+ methods = reusableMethods;
908
+ }
909
+ for (const name of METHOD_NAMES) {
910
+ Object.defineProperty(g, name, {
911
+ value: methods[name],
912
+ enumerable: false,
913
+ writable: true,
914
+ configurable: true
915
+ });
916
+ defined.push(name);
917
+ }
918
+ if (readMember(state, "isInstalled") !== true) {
919
+ state.isInstalled = true;
920
+ }
921
+ } catch {
922
+ rollback();
923
+ return "blocked";
924
+ }
925
+ return "installed";
926
+ }
927
+ function isGlobalEventTargetAvailable() {
928
+ return METHOD_NAMES.every((name) => probeMember(name) === "usable") && probeMember("ErrorEvent") === "usable";
929
+ }
930
+
754
931
  // src/lib/safe-handle-callback.ts
932
+ installGlobalEventTarget();
933
+ function reportCallbackError(callbackName, error) {
934
+ installGlobalEventTarget();
935
+ if (!isGlobalEventTargetAvailable()) {
936
+ return;
937
+ }
938
+ try {
939
+ globalThis.dispatchEvent(
940
+ new ErrorEvent("reportError", {
941
+ error: new Error(
942
+ `Error in a callback ${callbackName}: ${DOUBLE_EOL}${errorToString(error)}`
943
+ )
944
+ })
945
+ );
946
+ } catch {
947
+ }
948
+ }
755
949
  function safeHandleCallback(callbackName, callback, ...args) {
756
950
  const handleError = (error) => {
757
- if (typeof globalThis.dispatchEvent === "function") {
758
- globalThis.dispatchEvent(
759
- new ErrorEvent("reportError", {
760
- error: new Error(
761
- `Error in a callback ${callbackName}: ${DOUBLE_EOL}${errorToString(error)}`
762
- )
763
- })
764
- );
765
- }
951
+ reportCallbackError(callbackName, error);
766
952
  };
767
953
  if (isFunction(callback)) {
768
954
  try {