@wandelbots/nova-js 4.12.0-pr.342.98a4769 → 4.13.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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wandelbots/nova-js",
3
3
  "type": "module",
4
- "version": "4.12.0-pr.342.98a4769",
4
+ "version": "4.13.0",
5
5
  "description": "Official JS client for the Wandelbots API",
6
6
  "sideEffects": false,
7
7
  "packageManager": "pnpm@11.9.0+sha512.bd682d5d03fe525ef7c9fd6780c6884d1e756ac4c9c9fe00c538782824310dcf90e3ddc4f53835f06dfaebd5085e41855e0bcbb3b60de2ac5bbab89e5036f03b",
@@ -61,7 +61,7 @@
61
61
  "@biomejs/biome": "^2.5.6",
62
62
  "@types/node": "^25.9.5",
63
63
  "@types/ws": "^8.18.1",
64
- "@wandelbots/nova-api": "26.7.3",
64
+ "@wandelbots/nova-api": "26.7.5",
65
65
  "concurrently": "^10.0.4",
66
66
  "conventional-changelog-conventionalcommits": "^9.3.1",
67
67
  "jsdom": "^29.1.1",
@@ -65,18 +65,24 @@ export type NatsSubscribeOptions = {
65
65
 
66
66
  /**
67
67
  * What `subscribe()` returns: a function that unsubscribes when called, with
68
- * a `closed` promise that resolves when the subscription has ended. After
69
- * that, the subscription receives no more messages; subscribe again to
70
- * receive them.
68
+ * a method `closed()`, whose promise resolves when the subscription has
69
+ * ended. After that, the subscription receives no more messages; subscribe
70
+ * again to receive them.
71
71
  *
72
- * `closed` resolves with `undefined` when the subscription ended without an
73
- * error: after an unsubscribe, or because the connection was closed. It
72
+ * The promise resolves with `undefined` when the subscription ended without
73
+ * an error: after an unsubscribe, or because the connection was closed. It
74
74
  * resolves with the error when the server or the NATS library ended it, for
75
75
  * example when the server refused the subject, or when JetStream could not
76
76
  * create a lost consumer again.
77
+ *
78
+ * The promise resolves only after the handler has finished with the last
79
+ * message, so the handler is never called after that. While a handler still
80
+ * runs, the promise waits for it, as `closed` of a nats.js subscription waits
81
+ * for the code that iterates its messages. So a handler must not wait for
82
+ * `closed()` of its own subscription.
77
83
  */
78
84
  export type NatsSubscription = (() => void) & {
79
- closed: Promise<Error | undefined>
85
+ closed(): Promise<Error | undefined>
80
86
  }
81
87
 
82
88
  type NatsMessageHandler<K extends NatsSubscribeSubject> = (
@@ -166,8 +172,9 @@ export class NovaNatsClient {
166
172
  * message persisted for each matching subject is replayed to the handler
167
173
  * immediately, before live messages (see {@link NatsSubscribeOptions}).
168
174
  *
169
- * Returns a function that unsubscribes when called. Its `closed` promise
170
- * resolves when the subscription has ended (see {@link NatsSubscription}).
175
+ * Returns a function that unsubscribes when called. The promise of its
176
+ * `closed()` resolves when the subscription has ended (see
177
+ * {@link NatsSubscription}).
171
178
  */
172
179
  async subscribe<K extends NatsSubscribeSubject>(
173
180
  subject: K,
@@ -248,13 +255,15 @@ export class NovaNatsClient {
248
255
  deliver_policy: DeliverPolicy.LastPerSubject,
249
256
  })
250
257
  const messages = await consumer.consume()
258
+ const closed = dispatch(messages)
251
259
  return Object.assign(() => void messages.close(), {
252
- closed: dispatch(messages),
260
+ closed: () => closed,
253
261
  })
254
262
  }
255
263
 
256
264
  const sub = nc.subscribe(resolvedSubject)
257
- return Object.assign(() => sub.unsubscribe(), { closed: dispatch(sub) })
265
+ const closed = dispatch(sub)
266
+ return Object.assign(() => sub.unsubscribe(), { closed: () => closed })
258
267
  }
259
268
 
260
269
  /**