@gesslar/toolkit 3.24.0 → 3.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "name": "gesslar",
6
6
  "url": "https://gesslar.dev"
7
7
  },
8
- "version": "3.24.0",
8
+ "version": "3.25.0",
9
9
  "license": "Unlicense",
10
10
  "homepage": "https://github.com/gesslar/toolkit#readme",
11
11
  "repository": {
@@ -49,7 +49,7 @@
49
49
  "UNLICENSE.txt"
50
50
  ],
51
51
  "engines": {
52
- "node": ">=22"
52
+ "node": ">=24.13.0"
53
53
  },
54
54
  "dependencies": {
55
55
  "@eslint/js": "^9.39.2",
@@ -7,6 +7,7 @@
7
7
  import {EventEmitter} from "node:events"
8
8
 
9
9
  import Valid from "./Valid.js"
10
+ import Util from "./Util.js"
10
11
 
11
12
  /**
12
13
  * @typedef {object} NotifyEventOptions
@@ -33,12 +34,26 @@ export default new class Notify {
33
34
  * @returns {void}
34
35
  */
35
36
  emit(type, payload=undefined) {
36
- Valid.type(type, "String")
37
- Valid.assert(type.length > 0, "Event type cannot be an empty string.")
37
+ Valid.type(type, "String", {allowEmpty: false})
38
38
 
39
39
  this.#emitter.emit(type, payload)
40
40
  }
41
41
 
42
+ /**
43
+ * Emits an event asynchronously and waits for all listeners to complete.
44
+ * Unlike emit() which is synchronous, this method properly handles async
45
+ * event listeners by waiting for all of them to resolve.
46
+ *
47
+ * @param {string} type - Event name to dispatch.
48
+ * @param {unknown} [payload] - Data to send with the event.
49
+ * @returns {Promise<void>} Resolves when all listeners have completed.
50
+ */
51
+ async asyncEmit(type, payload) {
52
+ Valid.type(type, "String", {allowEmpty: false})
53
+
54
+ await Util.asyncEmit(this.#emitter, type, payload)
55
+ }
56
+
42
57
  /**
43
58
  * Emits an event and returns the payload for simple request/response flows.
44
59
  * Listeners can mutate the payload object to provide responses.
@@ -48,8 +63,7 @@ export default new class Notify {
48
63
  * @returns {unknown} The payload after listeners have processed it.
49
64
  */
50
65
  request(type, payload={}) {
51
- Valid.type(type, "String")
52
- Valid.assert(type.length > 0, "Event type cannot be an empty string.")
66
+ Valid.type(type, "String", {allowEmpty: false})
53
67
 
54
68
  this.#emitter.emit(type, payload)
55
69
 
@@ -66,8 +80,7 @@ export default new class Notify {
66
80
  * @returns {() => void} Dispose function to unregister the handler.
67
81
  */
68
82
  on(type, handler, emitter=this.#emitter, options=undefined) {
69
- Valid.type(type, "String")
70
- Valid.assert(type.length > 0, "Event type cannot be an empty string.")
83
+ Valid.type(type, "String", {allowEmpty: false})
71
84
  Valid.type(handler, "Function")
72
85
 
73
86
  if(options?.once) {
@@ -88,6 +101,8 @@ export default new class Notify {
88
101
  * @returns {void}
89
102
  */
90
103
  off(type, handler, emitter=this.#emitter) {
104
+ Valid.type(type, "String", {allowEmpty: false})
105
+
91
106
  emitter.off(type, handler)
92
107
  }
93
108
  }
@@ -108,11 +108,6 @@ export default class Util extends BrowserUtil {
108
108
  } catch(error) {
109
109
  const argsDesc = args.length > 0 ? `with arguments: ${args.map(String).join(", ")}` : "with no arguments"
110
110
 
111
- // If it's already a Sass error, just re-throw to avoid double-wrapping
112
- if(error instanceof Sass) {
113
- throw error
114
- }
115
-
116
111
  throw Sass.new(
117
112
  `Processing '${event}' event ${argsDesc}.`,
118
113
  error
@@ -144,11 +139,6 @@ export default class Util extends BrowserUtil {
144
139
  } catch(error) {
145
140
  const argsDesc = args.length > 0 ? `with arguments: ${args.map(String).join(", ")}` : "with no arguments"
146
141
 
147
- // If it's already a Sass error, just re-throw to avoid double-wrapping
148
- if(error instanceof Sass) {
149
- throw error
150
- }
151
-
152
142
  throw Sass.new(
153
143
  `Processing '${event}' event ${argsDesc}.`,
154
144
  error
@@ -11,6 +11,16 @@ declare const _default: {
11
11
  * @returns {void}
12
12
  */
13
13
  emit(type: string, payload?: unknown): void;
14
+ /**
15
+ * Emits an event asynchronously and waits for all listeners to complete.
16
+ * Unlike emit() which is synchronous, this method properly handles async
17
+ * event listeners by waiting for all of them to resolve.
18
+ *
19
+ * @param {string} type - Event name to dispatch.
20
+ * @param {unknown} [payload] - Data to send with the event.
21
+ * @returns {Promise<void>} Resolves when all listeners have completed.
22
+ */
23
+ asyncEmit(type: string, payload?: unknown): Promise<void>;
14
24
  /**
15
25
  * Emits an event and returns the payload for simple request/response flows.
16
26
  * Listeners can mutate the payload object to provide responses.
@@ -1 +1 @@
1
- {"version":3,"file":"Notify.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Notify.js"],"names":[],"mappings":";IAqBE,iDAAiD;UAAtC,MAAM;IAGjB,kDAAkD;2BAAvC,YAAY;IAGvB;;;;;;OAMG;eAHQ,MAAM,YACN,OAAO,GACL,IAAI;IASjB;;;;;;;OAOG;kBAHQ,MAAM,YACN,OAAO,GACL,OAAO;IAWpB;;;;;;;;OAQG;aALQ,MAAM,WACN,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,YAC1B,YAAY,YACZ,kBAAkB,GAChB,MAAM,IAAI;IAgBvB;;;;;;;OAOG;cAJQ,MAAM,WACN,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,YAC1B,YAAY,GACV,IAAI;;;;;;;WA3EL,OAAO;;;;aACP,WAAW"}
1
+ {"version":3,"file":"Notify.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Notify.js"],"names":[],"mappings":";IAsBE,iDAAiD;UAAtC,MAAM;IAGjB,kDAAkD;2BAAvC,YAAY;IAGvB;;;;;;OAMG;eAHQ,MAAM,YACN,OAAO,GACL,IAAI;IAQjB;;;;;;;;OAQG;oBAHQ,MAAM,YACN,OAAO,GACL,OAAO,CAAC,IAAI,CAAC;IAQ1B;;;;;;;OAOG;kBAHQ,MAAM,YACN,OAAO,GACL,OAAO;IAUpB;;;;;;;;OAQG;aALQ,MAAM,WACN,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,YAC1B,YAAY,YACZ,kBAAkB,GAChB,MAAM,IAAI;IAevB;;;;;;;OAOG;cAJQ,MAAM,WACN,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,YAC1B,YAAY,GACV,IAAI;;;;;;;WAvFL,OAAO;;;;aACP,WAAW"}
@@ -1 +1 @@
1
- {"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Util.js"],"names":[],"mappings":"AAQA;;;GAGG;AACH;IACE;;;;;OAKG;IACH,iBAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,mCAHW,MAAM,GACJ,KAAK,CAAC,MAAM,CAAC,CAazB;IAED;;;;;;;;OAQG;IACH,+CALW,MAAM,SACN,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAmBzB;IAED;;;;;;;;;;;;OAYG;IACH,0BALW,YAAY,SACZ,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAqBzB;IAED;;;;;;;;;;OAUG;IACH,+BALW,MAAM,SACN,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAyBzB;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,kBALW,MAAM,QACN,OAAO,GACL,OAAO,CAmBnB;CACF;oCApMiC,wBAAwB"}
1
+ {"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../src/node/lib/Util.js"],"names":[],"mappings":"AAQA;;;GAGG;AACH;IACE;;;;;OAKG;IACH,iBAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,mCAHW,MAAM,GACJ,KAAK,CAAC,MAAM,CAAC,CAazB;IAED;;;;;;;;OAQG;IACH,+CALW,MAAM,SACN,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAmBzB;IAED;;;;;;;;;;;;OAYG;IACH,0BALW,YAAY,SACZ,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAgBzB;IAED;;;;;;;;;;OAUG;IACH,+BALW,MAAM,SACN,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAoBzB;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,kBALW,MAAM,QACN,OAAO,GACL,OAAO,CAmBnB;CACF;oCA1LiC,wBAAwB"}