@zudojs/events 1.3.0 → 1.3.2

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/README.md CHANGED
@@ -50,13 +50,39 @@ await bus.publishEvent({
50
50
  - Event bus with a middleware pipeline (`use()`, constructor and per-publish middleware)
51
51
  - Sequential or parallel handler dispatch with `THROW` / `CONTINUE` error modes
52
52
  - Handler priorities, one-time handlers, per-handler timeouts
53
- - Wildcard subscriptions (`"user.*"`, `"*"`)
53
+ - Wildcard subscriptions (`"user.*"`, `"*"`) — multi-level, see [Wildcard patterns](#wildcard-patterns)
54
54
  - Event registry for typed definitions; handlers registered on the registry are dispatched by the bus
55
55
  - Deep-frozen events (`freezeEvents`, on by default) so handlers cannot alter what other handlers see: handlers receive a frozen *copy* (`createFrozenEventSnapshot`), so the publisher's own objects are never frozen, and Map, Set and Date values (including `event.timestamp`) become read-only variants that throw on mutation. Class instances are passed by reference.
56
56
  - A handler unsubscribed by an earlier handler in the same dispatch, or left over after the bus is disposed mid-dispatch, does not run
57
57
  - Listener-leak warnings (`maxListeners`, reported through `onWarning` or, by default, `process.emitWarning` with type `ZudojsEventsWarning`) and an `onError` hook for fire-and-forget publishes
58
58
  - Typed error classes from `@zudojs/errors` (`EventHandlerError`, `EventMiddlewareError`, `EventDispatchAbortedError`, …)
59
59
 
60
+ ## Wildcard patterns
61
+
62
+ A handler's event type can be an exact type, a namespace wildcard, or the
63
+ catch-all `"*"`:
64
+
65
+ | Pattern | Matches | Does not match |
66
+ |---------|---------|----------------|
67
+ | `"task.created"` | `task.created` | `task.created.v2`, `task` |
68
+ | `"task.*"` | `task`, `task.created`, `task.sub.created` (any depth) | `tasks.created`, `order.created` |
69
+ | `"*"` | every event | — |
70
+
71
+ A namespace wildcard is **multi-level**: `"task.*"` matches every event
72
+ under `task` at any depth, plus the bare `task` event, like a prefix match
73
+ on whole segments. There is no single-level form — `"task.*.created"`,
74
+ `"task.cre*"` and other positions are rejected as invalid patterns. To
75
+ handle only direct children, filter in the handler:
76
+
77
+ ```typescript
78
+ import { getEventTypeSegments } from "@zudojs/events";
79
+
80
+ bus.on("task.*", (event) => {
81
+ if (getEventTypeSegments(event.type).length !== 2) return; // task.x only
82
+ // ...
83
+ });
84
+ ```
85
+
60
86
  ## Lifecycle
61
87
 
62
88
  ```
@@ -55,6 +55,10 @@ export declare function isValidEventType(value: unknown): value is EventType;
55
55
  * Supported forms are an exact event type, a namespace wildcard
56
56
  * ("user.*") and the catch-all "*". Wildcards in any other
57
57
  * position ("user.*.created", "user.cre*") are rejected.
58
+ *
59
+ * A namespace wildcard is multi-level: "user.*" matches every event
60
+ * under "user" at any depth, and "user" itself (see matchesEventType).
61
+ * There is no single-level form.
58
62
  */
59
63
  export declare function isValidEventTypePattern(value: unknown): value is EventTypePattern;
60
64
  /**
@@ -112,8 +116,16 @@ export declare function normalizeEventTypePattern(pattern: string): EventTypePat
112
116
  * "user.created" matches "user.*"
113
117
  * "user" matches "user.*" (a namespace pattern also
114
118
  * matches the bare namespace event)
119
+ * "user.profile.updated" matches "user.*" (multi-level: the
120
+ * wildcard covers every depth below the namespace)
115
121
  * "user.created" matches "*"
116
122
  * "order.created" does not match "user.*"
123
+ * "username.set" does not match "user.*" (segments, not prefixes)
124
+ *
125
+ * A "*" segment stands for the rest of the type, not for one segment,
126
+ * and there is no single-level wildcard. To handle only direct children,
127
+ * subscribe to "user.*" and check
128
+ * `getEventTypeSegments(event.type).length === 2` in the handler.
117
129
  *
118
130
  * Both arguments are expected to be normalized (see
119
131
  * normalizeEventType / normalizeEventTypePattern); no
@@ -133,10 +145,13 @@ export declare function isChildEventType(type: EventType, parent: EventType): bo
133
145
  /**
134
146
  * Creates a wildcard pattern for an event namespace.
135
147
  *
148
+ * The pattern is multi-level: it matches every event type under the
149
+ * namespace at any depth, and the bare namespace itself.
150
+ *
136
151
  * Example:
137
152
  *
138
153
  * createEventTypePattern("user")
139
- * → "user.*"
154
+ * → "user.*" (matches "user", "user.created", "user.profile.updated")
140
155
  */
141
156
  export declare function createEventTypePattern(namespace: string): EventTypePattern;
142
157
  /**
@@ -38,6 +38,10 @@ export function isValidEventType(value) {
38
38
  * Supported forms are an exact event type, a namespace wildcard
39
39
  * ("user.*") and the catch-all "*". Wildcards in any other
40
40
  * position ("user.*.created", "user.cre*") are rejected.
41
+ *
42
+ * A namespace wildcard is multi-level: "user.*" matches every event
43
+ * under "user" at any depth, and "user" itself (see matchesEventType).
44
+ * There is no single-level form.
41
45
  */
42
46
  export function isValidEventTypePattern(value) {
43
47
  if (value === "*") {
@@ -164,8 +168,16 @@ export function normalizeEventTypePattern(pattern) {
164
168
  * "user.created" matches "user.*"
165
169
  * "user" matches "user.*" (a namespace pattern also
166
170
  * matches the bare namespace event)
171
+ * "user.profile.updated" matches "user.*" (multi-level: the
172
+ * wildcard covers every depth below the namespace)
167
173
  * "user.created" matches "*"
168
174
  * "order.created" does not match "user.*"
175
+ * "username.set" does not match "user.*" (segments, not prefixes)
176
+ *
177
+ * A "*" segment stands for the rest of the type, not for one segment,
178
+ * and there is no single-level wildcard. To handle only direct children,
179
+ * subscribe to "user.*" and check
180
+ * `getEventTypeSegments(event.type).length === 2` in the handler.
169
181
  *
170
182
  * Both arguments are expected to be normalized (see
171
183
  * normalizeEventType / normalizeEventTypePattern); no
@@ -201,10 +213,13 @@ export function isChildEventType(type, parent) {
201
213
  /**
202
214
  * Creates a wildcard pattern for an event namespace.
203
215
  *
216
+ * The pattern is multi-level: it matches every event type under the
217
+ * namespace at any depth, and the bare namespace itself.
218
+ *
204
219
  * Example:
205
220
  *
206
221
  * createEventTypePattern("user")
207
- * → "user.*"
222
+ * → "user.*" (matches "user", "user.created", "user.profile.updated")
208
223
  */
209
224
  export function createEventTypePattern(namespace) {
210
225
  const normalized = normalizeEventType(namespace);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zudojs/events",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
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,9 +20,9 @@
20
20
  ],
21
21
  "sideEffects": false,
22
22
  "dependencies": {
23
- "@zudojs/constants": "1.1.2",
24
- "@zudojs/errors": "1.3.0",
25
- "@zudojs/middleware": "1.1.0"
23
+ "@zudojs/constants": "1.1.3",
24
+ "@zudojs/errors": "1.3.1",
25
+ "@zudojs/middleware": "1.1.1"
26
26
  },
27
27
  "engines": {
28
28
  "node": ">=24.0.0"