@zudojs/cqrs 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.
@@ -104,7 +104,12 @@ export declare function contextMiddleware(options?: MiddlewareOptions): CqrsMidd
104
104
  * `acquire` must resolve to a release function.
105
105
  */
106
106
  export interface CqrsLock {
107
- acquire(key: string): (() => void) | Promise<() => void>;
107
+ /**
108
+ * The release function may be synchronous or return a promise; the
109
+ * middleware awaits it. A rejected release surfaces as a `CqrsError`
110
+ * (when the handler succeeded) rather than an unhandled rejection.
111
+ */
112
+ acquire(key: string): (() => void | Promise<void>) | Promise<() => void | Promise<void>>;
108
113
  }
109
114
  /**
110
115
  * Options for `lockMiddleware`.
@@ -154,12 +154,35 @@ export function lockMiddleware(lock, options = {}) {
154
154
  lockKey: key,
155
155
  });
156
156
  }
157
+ // `release()` may be asynchronous (a Redis DEL, say). It used to be
158
+ // called and dropped, so a rejected release was an unhandled promise
159
+ // rejection — which terminates the process under Node's defaults.
160
+ let result;
157
161
  try {
158
- return await next(request, context);
162
+ result = await next(request, context);
159
163
  }
160
- finally {
161
- release();
164
+ catch (error) {
165
+ try {
166
+ await release();
167
+ }
168
+ catch {
169
+ // The handler's failure is the one the caller needs to see.
170
+ }
171
+ throw error;
172
+ }
173
+ try {
174
+ await release();
162
175
  }
176
+ catch (error) {
177
+ throw new CqrsError(`CQRS lock release failed (key "${key}").`, {
178
+ cause: error,
179
+ metadata: {
180
+ lockKey: key,
181
+ requestType: getRequestType(request),
182
+ },
183
+ });
184
+ }
185
+ return result;
163
186
  };
164
187
  }
165
188
  /**
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@zudojs/cqrs",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Command Query Responsibility Segregation (CQRS) primitives for separating read and write operations.",
5
5
  "license": "MIT",
6
+ "author": {
7
+ "name": "Oluwayemi Oyinlola",
8
+ "url": "https://github.com/oyinlola-tech"
9
+ },
6
10
  "type": "module",
7
11
  "main": "./dist/index.js",
8
12
  "module": "./dist/index.js",
@@ -21,8 +25,8 @@
21
25
  "!dist/.tsbuildinfo"
22
26
  ],
23
27
  "dependencies": {
24
- "@zudojs/errors": "1.0.0",
25
- "@zudojs/events": "1.0.0"
28
+ "@zudojs/errors": "1.0.1",
29
+ "@zudojs/events": "1.0.1"
26
30
  },
27
31
  "devDependencies": {
28
32
  "typescript": "7.0.2",