@graphql-hive/pubsub 2.2.0 → 2.2.1-rc-6cd2e76cdae3008daabc4f4cdf7d65d9293da5f2
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/CHANGELOG.md +16 -0
- package/dist/nats-jetstream.cjs +4 -12
- package/dist/nats-jetstream.d.cts +2 -13
- package/dist/nats-jetstream.d.ts +2 -13
- package/dist/nats-jetstream.js +4 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @graphql-hive/pubsub
|
|
2
2
|
|
|
3
|
+
## 2.2.1-rc-6cd2e76cdae3008daabc4f4cdf7d65d9293da5f2
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [`96a19f2`](https://github.com/graphql-hive/gateway/commit/96a19f2dc63be7ff1c9a1c6d2d239d153b82153b) Thanks [@enisdenjo](https://github.com/enisdenjo)! - Accept a `JetStreamClient` in `NATSJetStreamPubSub` so the optional NATS dependencies remain type-only imports
|
|
9
|
+
|
|
10
|
+
```diff
|
|
11
|
+
-import { NATSJetStreamPubSub } from '@graphql-hive/pubsub/nats-jetstream';
|
|
12
|
+
+import { NATSJetStreamPubSub } from '@graphql-hive/pubsub/nats-jetstream';
|
|
13
|
+
+import { jetstream } from '@nats-io/jetstream';
|
|
14
|
+
|
|
15
|
+
-const pubsub = new NATSJetStreamPubSub(nats, options);
|
|
16
|
+
+const pubsub = new NATSJetStreamPubSub(jetstream(nats), options);
|
|
17
|
+
```
|
|
18
|
+
|
|
3
19
|
## 2.2.0
|
|
4
20
|
### Minor Changes
|
|
5
21
|
|
package/dist/nats-jetstream.cjs
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var jetstream = require('@nats-io/jetstream');
|
|
4
3
|
var repeater = require('@repeaterjs/repeater');
|
|
5
4
|
var disposablestack = require('@whatwg-node/disposablestack');
|
|
6
5
|
var promiseHelpers = require('@whatwg-node/promise-helpers');
|
|
7
6
|
|
|
8
7
|
class NATSJetStreamPubSub {
|
|
9
8
|
#disposed = false;
|
|
10
|
-
#closeOnDispose;
|
|
11
|
-
#nats;
|
|
12
9
|
#js;
|
|
13
10
|
#subjectPrefix;
|
|
14
11
|
#stream;
|
|
15
12
|
#activeConsumers = /* @__PURE__ */ new Map();
|
|
16
|
-
constructor(
|
|
17
|
-
this.#
|
|
13
|
+
constructor(js, options) {
|
|
14
|
+
this.#js = js;
|
|
18
15
|
this.#subjectPrefix = options.subjectPrefix;
|
|
19
16
|
this.#stream = options.stream;
|
|
20
|
-
this.#closeOnDispose = !options.noCloseOnDispose;
|
|
21
17
|
if (String(this.#subjectPrefix || "").trim() === "") {
|
|
22
18
|
throw new Error("NATSJetStreamPubSub requires a non-empty subjectPrefix");
|
|
23
19
|
}
|
|
24
20
|
if (String(this.#stream || "").trim() === "") {
|
|
25
21
|
throw new Error("NATSJetStreamPubSub requires a non-empty stream");
|
|
26
22
|
}
|
|
27
|
-
this.#js = jetstream.jetstream(nats);
|
|
28
23
|
}
|
|
29
24
|
#topicToSubject(topic) {
|
|
30
25
|
return `${this.#subjectPrefix}:${String(topic)}`;
|
|
@@ -59,8 +54,8 @@ class NATSJetStreamPubSub {
|
|
|
59
54
|
#createConsumer(topic, cursor) {
|
|
60
55
|
return this.#js.consumers.get(this.#stream, {
|
|
61
56
|
filter_subjects: [this.#topicToSubject(topic)],
|
|
62
|
-
...cursor === void 0 ? { deliver_policy:
|
|
63
|
-
deliver_policy:
|
|
57
|
+
...cursor === void 0 ? { deliver_policy: "new" } : {
|
|
58
|
+
deliver_policy: "by_start_sequence",
|
|
64
59
|
opt_start_seq: this.#parseCursor(cursor) + 1
|
|
65
60
|
}
|
|
66
61
|
});
|
|
@@ -142,9 +137,6 @@ class NATSJetStreamPubSub {
|
|
|
142
137
|
Array.from(this.#activeConsumers.keys()).map((stop) => stop())
|
|
143
138
|
);
|
|
144
139
|
this.#activeConsumers.clear();
|
|
145
|
-
if (this.#closeOnDispose) {
|
|
146
|
-
await this.#nats.close();
|
|
147
|
-
}
|
|
148
140
|
}
|
|
149
141
|
[disposablestack.DisposableSymbols.asyncDispose]() {
|
|
150
142
|
return this.dispose();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JetStreamClient } from '@nats-io/jetstream';
|
|
2
2
|
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
3
3
|
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
4
4
|
import { T as TopicDataMap, P as PubSub, a as PubSubListener } from './pubsub-VtDb_TZC.js';
|
|
@@ -34,17 +34,6 @@ interface NATSJetStreamPubSubOptions {
|
|
|
34
34
|
* configured to capture the subjects used by this pub/sub (i.e. `${subjectPrefix}:${topic}`).
|
|
35
35
|
*/
|
|
36
36
|
stream: string;
|
|
37
|
-
/**
|
|
38
|
-
* By default, when the pub/sub instance is disposed, it will call
|
|
39
|
-
* `close` on the NATS connection. Set this to `true` if you
|
|
40
|
-
* want to keep the connection alive after disposal.
|
|
41
|
-
*
|
|
42
|
-
* This might be useful if you want to manage the NATS connection's lifecycle
|
|
43
|
-
* outside of the pub/sub instance.
|
|
44
|
-
*
|
|
45
|
-
* @default false
|
|
46
|
-
*/
|
|
47
|
-
noCloseOnDispose?: boolean;
|
|
48
37
|
}
|
|
49
38
|
/**
|
|
50
39
|
* {@link PubSub Hive PubSub} implementation using [NATS JetStream](https://docs.nats.io/nats-concepts/jetstream)
|
|
@@ -57,7 +46,7 @@ interface NATSJetStreamPubSubOptions {
|
|
|
57
46
|
*/
|
|
58
47
|
declare class NATSJetStreamPubSub<M extends TopicDataMap = TopicDataMap> implements PubSub<M, JetStreamSubscribeOptions> {
|
|
59
48
|
#private;
|
|
60
|
-
constructor(
|
|
49
|
+
constructor(js: JetStreamClient, options: NATSJetStreamPubSubOptions);
|
|
61
50
|
subscribedTopics(): Promise<(keyof M)[]>;
|
|
62
51
|
publish<Topic extends keyof M>(topic: Topic, data: M[Topic]): Promise<undefined>;
|
|
63
52
|
subscribe<Topic extends keyof M>(topic: Topic): AsyncIterable<M[Topic]>;
|
package/dist/nats-jetstream.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JetStreamClient } from '@nats-io/jetstream';
|
|
2
2
|
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
3
3
|
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
4
4
|
import { T as TopicDataMap, P as PubSub, a as PubSubListener } from './pubsub-VtDb_TZC.js';
|
|
@@ -34,17 +34,6 @@ interface NATSJetStreamPubSubOptions {
|
|
|
34
34
|
* configured to capture the subjects used by this pub/sub (i.e. `${subjectPrefix}:${topic}`).
|
|
35
35
|
*/
|
|
36
36
|
stream: string;
|
|
37
|
-
/**
|
|
38
|
-
* By default, when the pub/sub instance is disposed, it will call
|
|
39
|
-
* `close` on the NATS connection. Set this to `true` if you
|
|
40
|
-
* want to keep the connection alive after disposal.
|
|
41
|
-
*
|
|
42
|
-
* This might be useful if you want to manage the NATS connection's lifecycle
|
|
43
|
-
* outside of the pub/sub instance.
|
|
44
|
-
*
|
|
45
|
-
* @default false
|
|
46
|
-
*/
|
|
47
|
-
noCloseOnDispose?: boolean;
|
|
48
37
|
}
|
|
49
38
|
/**
|
|
50
39
|
* {@link PubSub Hive PubSub} implementation using [NATS JetStream](https://docs.nats.io/nats-concepts/jetstream)
|
|
@@ -57,7 +46,7 @@ interface NATSJetStreamPubSubOptions {
|
|
|
57
46
|
*/
|
|
58
47
|
declare class NATSJetStreamPubSub<M extends TopicDataMap = TopicDataMap> implements PubSub<M, JetStreamSubscribeOptions> {
|
|
59
48
|
#private;
|
|
60
|
-
constructor(
|
|
49
|
+
constructor(js: JetStreamClient, options: NATSJetStreamPubSubOptions);
|
|
61
50
|
subscribedTopics(): Promise<(keyof M)[]>;
|
|
62
51
|
publish<Topic extends keyof M>(topic: Topic, data: M[Topic]): Promise<undefined>;
|
|
63
52
|
subscribe<Topic extends keyof M>(topic: Topic): AsyncIterable<M[Topic]>;
|
package/dist/nats-jetstream.js
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
import { jetstream, DeliverPolicy } from '@nats-io/jetstream';
|
|
2
1
|
import { Repeater } from '@repeaterjs/repeater';
|
|
3
2
|
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
4
3
|
import { fakePromise, createDeferredPromise } from '@whatwg-node/promise-helpers';
|
|
5
4
|
|
|
6
5
|
class NATSJetStreamPubSub {
|
|
7
6
|
#disposed = false;
|
|
8
|
-
#closeOnDispose;
|
|
9
|
-
#nats;
|
|
10
7
|
#js;
|
|
11
8
|
#subjectPrefix;
|
|
12
9
|
#stream;
|
|
13
10
|
#activeConsumers = /* @__PURE__ */ new Map();
|
|
14
|
-
constructor(
|
|
15
|
-
this.#
|
|
11
|
+
constructor(js, options) {
|
|
12
|
+
this.#js = js;
|
|
16
13
|
this.#subjectPrefix = options.subjectPrefix;
|
|
17
14
|
this.#stream = options.stream;
|
|
18
|
-
this.#closeOnDispose = !options.noCloseOnDispose;
|
|
19
15
|
if (String(this.#subjectPrefix || "").trim() === "") {
|
|
20
16
|
throw new Error("NATSJetStreamPubSub requires a non-empty subjectPrefix");
|
|
21
17
|
}
|
|
22
18
|
if (String(this.#stream || "").trim() === "") {
|
|
23
19
|
throw new Error("NATSJetStreamPubSub requires a non-empty stream");
|
|
24
20
|
}
|
|
25
|
-
this.#js = jetstream(nats);
|
|
26
21
|
}
|
|
27
22
|
#topicToSubject(topic) {
|
|
28
23
|
return `${this.#subjectPrefix}:${String(topic)}`;
|
|
@@ -57,8 +52,8 @@ class NATSJetStreamPubSub {
|
|
|
57
52
|
#createConsumer(topic, cursor) {
|
|
58
53
|
return this.#js.consumers.get(this.#stream, {
|
|
59
54
|
filter_subjects: [this.#topicToSubject(topic)],
|
|
60
|
-
...cursor === void 0 ? { deliver_policy:
|
|
61
|
-
deliver_policy:
|
|
55
|
+
...cursor === void 0 ? { deliver_policy: "new" } : {
|
|
56
|
+
deliver_policy: "by_start_sequence",
|
|
62
57
|
opt_start_seq: this.#parseCursor(cursor) + 1
|
|
63
58
|
}
|
|
64
59
|
});
|
|
@@ -140,9 +135,6 @@ class NATSJetStreamPubSub {
|
|
|
140
135
|
Array.from(this.#activeConsumers.keys()).map((stop) => stop())
|
|
141
136
|
);
|
|
142
137
|
this.#activeConsumers.clear();
|
|
143
|
-
if (this.#closeOnDispose) {
|
|
144
|
-
await this.#nats.close();
|
|
145
|
-
}
|
|
146
138
|
}
|
|
147
139
|
[DisposableSymbols.asyncDispose]() {
|
|
148
140
|
return this.dispose();
|