@zudojs/events 1.0.0 → 1.0.1

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.
@@ -5,6 +5,7 @@ import { isEvent } from "../eventTypes/eventDefinition.type.js";
5
5
  import { EventEmitter } from "../eventEmitter/eventEmitter.core.js";
6
6
  import { EventErrorMode } from "../eventEmitter/eventEmitter.type.js";
7
7
  import { EventRegistry } from "../eventRegistry/eventRegistry.store.js";
8
+ import { normalizeRegistryEventType } from "../eventRegistry/eventRegistry.registration.js";
8
9
  import { EventBusDisposedError, EventBusStoppedError, EventError, toEventError, } from "../eventErrors/eventError.base.js";
9
10
  import { EventBusState } from "./eventBus.type.js";
10
11
  export { EventBusState } from "./eventBus.type.js";
@@ -135,9 +136,13 @@ export class EventBus {
135
136
  this.ensureNotDisposed();
136
137
  const removed = this.registry.unregister(eventType);
137
138
  if (options.removeHandlers) {
138
- const definition = this.registry.getHandlersForType(eventType);
139
- for (const handler of definition) {
140
- if (handler.eventType !== "*" && !handler.eventType.endsWith(".*")) {
139
+ /**
140
+ * Compare patterns on the full handler list: the matching
141
+ * query skips disabled handlers, which must be dropped too.
142
+ */
143
+ const type = normalizeRegistryEventType(eventType);
144
+ for (const handler of this.registry.getHandlers()) {
145
+ if (handler.eventType === type) {
141
146
  this.registry.unregisterHandler(handler.id);
142
147
  }
143
148
  }
@@ -42,25 +42,31 @@ export async function busPublish(event, options, deps) {
42
42
  signal: options.signal,
43
43
  metadata: options.metadata,
44
44
  });
45
+ /**
46
+ * The emit result is captured here, at the terminal, rather
47
+ * than read back from the pipeline's return value: a middleware
48
+ * that awaits next() and returns nothing (or something else)
49
+ * has still dispatched the handlers, and their outcome must not
50
+ * be reported as a short-circuit.
51
+ */
52
+ let emitResult;
45
53
  const terminal = async () => {
46
- return deps.emitter.emit(event, {
54
+ const result = await deps.emitter.emit(event, {
47
55
  mode: options.mode,
48
56
  errorMode: options.errorMode,
49
57
  signal: options.signal,
50
58
  metadata: options.metadata,
51
59
  });
60
+ emitResult = result;
61
+ return result;
52
62
  };
53
- let emitResult;
54
63
  let middlewareExecutions;
55
64
  if (allMiddleware.length > 0) {
56
65
  const pipelineResult = await executeEventMiddlewarePipeline(allMiddleware, middlewareContext, terminal);
57
66
  middlewareExecutions = pipelineResult.executions;
58
- if (isEventEmitResult(pipelineResult.result)) {
59
- emitResult = pipelineResult.result;
60
- }
61
67
  }
62
68
  else {
63
- emitResult = await terminal();
69
+ await terminal();
64
70
  }
65
71
  deps.notify({
66
72
  type: "published",
@@ -138,7 +138,15 @@ export class EventEmitter {
138
138
  if (this.disposed) {
139
139
  return;
140
140
  }
141
- this.removeAllListeners();
141
+ /**
142
+ * A shared store (the bus registry) may already have been
143
+ * disposed, in which case its handlers are gone and querying
144
+ * it would throw; disposing the emitter must still succeed.
145
+ */
146
+ const store = this.store;
147
+ if (typeof store.isDisposed !== "function" || !store.isDisposed()) {
148
+ this.removeAllListeners();
149
+ }
142
150
  this.disposed = true;
143
151
  }
144
152
  isDisposed() {
@@ -151,13 +151,12 @@ function freezeRecursively(value, visited) {
151
151
  * Removes undefined properties from an object payload.
152
152
  */
153
153
  export function stripUndefinedValues(payload) {
154
- const result = {};
155
- for (const [key, value] of Object.entries(payload)) {
156
- if (value !== undefined) {
157
- result[key] = value;
158
- }
159
- }
160
- return result;
154
+ /**
155
+ * Object.fromEntries defines every entry as an own data
156
+ * property, so a key such as "__proto__" (e.g. from JSON.parse)
157
+ * is copied as data instead of replacing the result's prototype.
158
+ */
159
+ return Object.fromEntries(Object.entries(payload).filter(([, value]) => value !== undefined));
161
160
  }
162
161
  /**
163
162
  * Merges two object payloads.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zudojs/events",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Event-driven architecture with event bus, emitter, middleware, and registry for decoupled communication.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,8 +20,8 @@
20
20
  ],
21
21
  "sideEffects": false,
22
22
  "dependencies": {
23
- "@zudojs/errors": "1.0.0",
24
- "@zudojs/constants": "1.0.0"
23
+ "@zudojs/errors": "1.0.1",
24
+ "@zudojs/constants": "1.0.1"
25
25
  },
26
26
  "engines": {
27
27
  "node": ">=24.0.0"
@@ -31,6 +31,10 @@
31
31
  "typescript": "7.0.2"
32
32
  },
33
33
  "license": "MIT",
34
+ "author": {
35
+ "name": "Oluwayemi Oyinlola",
36
+ "url": "https://github.com/oyinlola-tech"
37
+ },
34
38
  "publishConfig": {
35
39
  "access": "public"
36
40
  },