@atcute/jetstream 1.1.2 → 1.1.3
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 +222 -13
- package/dist/index.d.ts +3 -3
- package/dist/subscription.d.ts +1 -1
- package/dist/subscription.d.ts.map +1 -1
- package/dist/subscription.js.map +1 -1
- package/dist/typedefs.d.ts +1 -1
- package/dist/typedefs.d.ts.map +1 -1
- package/dist/typedefs.js +1 -1
- package/dist/typedefs.js.map +1 -1
- package/lib/index.ts +3 -3
- package/lib/subscription.ts +2 -4
- package/lib/typedefs.ts +3 -3
- package/package.json +13 -12
package/README.md
CHANGED
|
@@ -1,34 +1,243 @@
|
|
|
1
1
|
# @atcute/jetstream
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
lightweight Jetstream subscriber for AT Protocol.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @atcute/jetstream
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
[Jetstream](https://docs.bsky.app/blog/jetstream) is a streaming service that delivers a filtered
|
|
10
|
+
firehose of events from the AT Protocol network over WebSocket. this package provides a simple
|
|
11
|
+
client to subscribe to these events.
|
|
12
|
+
|
|
13
|
+
## usage
|
|
14
|
+
|
|
15
|
+
### subscribing to events
|
|
16
|
+
|
|
17
|
+
create a subscription and iterate over events with `for await`:
|
|
4
18
|
|
|
5
19
|
```ts
|
|
6
20
|
import { JetstreamSubscription } from '@atcute/jetstream';
|
|
7
|
-
import { is } from '@atcute/lexicons';
|
|
8
21
|
|
|
9
|
-
|
|
22
|
+
const subscription = new JetstreamSubscription({
|
|
23
|
+
url: 'wss://jetstream2.us-east.bsky.network',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
for await (const event of subscription) {
|
|
27
|
+
console.log(event.kind, event.did);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
10
30
|
|
|
31
|
+
the connection opens when you start iterating and closes when you break out of the loop. the
|
|
32
|
+
underlying WebSocket automatically reconnects on disconnection.
|
|
33
|
+
|
|
34
|
+
### filtering by collection
|
|
35
|
+
|
|
36
|
+
use `wantedCollections` to receive only events for specific record types:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
11
39
|
const subscription = new JetstreamSubscription({
|
|
12
40
|
url: 'wss://jetstream2.us-east.bsky.network',
|
|
13
|
-
wantedCollections: ['app.bsky.feed.post'],
|
|
41
|
+
wantedCollections: ['app.bsky.feed.post', 'app.bsky.feed.like'],
|
|
14
42
|
});
|
|
15
43
|
|
|
16
44
|
for await (const event of subscription) {
|
|
17
45
|
if (event.kind === 'commit') {
|
|
18
|
-
|
|
46
|
+
console.log(event.commit.collection, event.commit.operation);
|
|
47
|
+
// -> "app.bsky.feed.post" "create"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
19
51
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
52
|
+
### filtering by account
|
|
53
|
+
|
|
54
|
+
use `wantedDids` to receive only events from specific accounts:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
const subscription = new JetstreamSubscription({
|
|
58
|
+
url: 'wss://jetstream2.us-east.bsky.network',
|
|
59
|
+
wantedDids: ['did:plc:z72i7hdynmk6r22z27h6tvur'], // @bsky.app
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### handling event types
|
|
64
|
+
|
|
65
|
+
jetstream delivers three kinds of events:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
for await (const event of subscription) {
|
|
69
|
+
switch (event.kind) {
|
|
70
|
+
case 'commit': {
|
|
71
|
+
// record was created, updated, or deleted
|
|
72
|
+
const { collection, operation, rkey, rev } = event.commit;
|
|
23
73
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
continue;
|
|
74
|
+
if (operation === 'create' || operation === 'update') {
|
|
75
|
+
// record and cid are available on create/update
|
|
76
|
+
console.log(event.commit.record);
|
|
28
77
|
}
|
|
29
78
|
|
|
30
|
-
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
case 'identity': {
|
|
83
|
+
// handle or DID document changed
|
|
84
|
+
const { did, handle, seq, time } = event.identity;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
case 'account': {
|
|
89
|
+
// account status changed (activated, deactivated, etc.)
|
|
90
|
+
const { did, active, seq, time } = event.account;
|
|
91
|
+
break;
|
|
31
92
|
}
|
|
32
93
|
}
|
|
33
94
|
}
|
|
34
95
|
```
|
|
96
|
+
|
|
97
|
+
### validating records
|
|
98
|
+
|
|
99
|
+
jetstream events include the raw record data. use `is()` from `@atcute/lexicons` to validate and
|
|
100
|
+
narrow the type:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { JetstreamSubscription } from '@atcute/jetstream';
|
|
104
|
+
import { is } from '@atcute/lexicons';
|
|
105
|
+
|
|
106
|
+
import { AppBskyFeedPost } from '@atcute/bluesky';
|
|
107
|
+
|
|
108
|
+
const subscription = new JetstreamSubscription({
|
|
109
|
+
url: 'wss://jetstream2.us-east.bsky.network',
|
|
110
|
+
wantedCollections: ['app.bsky.feed.post'],
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
for await (const event of subscription) {
|
|
114
|
+
if (event.kind !== 'commit') {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const commit = event.commit;
|
|
119
|
+
if (commit.operation !== 'create') {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// validate the record against the schema
|
|
124
|
+
if (!is(AppBskyFeedPost.mainSchema, commit.record)) {
|
|
125
|
+
console.warn('invalid record', commit.record);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// commit.record is now typed as AppBskyFeedPost.$record
|
|
130
|
+
console.log(`@${event.did}: ${commit.record.text}`);
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### resuming from a cursor
|
|
135
|
+
|
|
136
|
+
jetstream supports cursors for resuming from a specific point. the cursor is a timestamp in
|
|
137
|
+
microseconds:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
const subscription = new JetstreamSubscription({
|
|
141
|
+
url: 'wss://jetstream2.us-east.bsky.network',
|
|
142
|
+
// resume from a saved cursor
|
|
143
|
+
cursor: 1699900000000000,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// save the cursor periodically to resume later
|
|
147
|
+
setInterval(() => {
|
|
148
|
+
localStorage.setItem('jetstream-cursor', String(subscription.cursor));
|
|
149
|
+
}, 5_000);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
when switching between jetstream instances (e.g., when using multiple URLs for failover), the client
|
|
153
|
+
automatically rolls back the cursor by 10 seconds to avoid missing events due to clock differences.
|
|
154
|
+
|
|
155
|
+
### using multiple servers
|
|
156
|
+
|
|
157
|
+
pass an array of URLs for automatic failover. the client randomly selects one on each connection:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
const subscription = new JetstreamSubscription({
|
|
161
|
+
url: [
|
|
162
|
+
'wss://jetstream1.us-east.bsky.network',
|
|
163
|
+
'wss://jetstream2.us-east.bsky.network',
|
|
164
|
+
'wss://jetstream1.us-west.bsky.network',
|
|
165
|
+
'wss://jetstream2.us-west.bsky.network',
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### updating options at runtime
|
|
171
|
+
|
|
172
|
+
change filters without reconnecting using `updateOptions()`:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
// start with all collections
|
|
176
|
+
const subscription = new JetstreamSubscription({
|
|
177
|
+
url: 'wss://jetstream2.us-east.bsky.network',
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// later, filter to only posts
|
|
181
|
+
subscription.updateOptions({
|
|
182
|
+
wantedCollections: ['app.bsky.feed.post'],
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// add accounts to filter
|
|
186
|
+
subscription.updateOptions({
|
|
187
|
+
wantedDids: ['did:plc:...'],
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
changes to `wantedCollections` and `wantedDids` are sent to the server without reconnecting. other
|
|
192
|
+
option changes trigger a reconnection.
|
|
193
|
+
|
|
194
|
+
### connection lifecycle callbacks
|
|
195
|
+
|
|
196
|
+
handle connection events for logging or UI updates:
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
const subscription = new JetstreamSubscription({
|
|
200
|
+
url: 'wss://jetstream2.us-east.bsky.network',
|
|
201
|
+
onConnectionOpen(event) {
|
|
202
|
+
console.log('connected to jetstream');
|
|
203
|
+
},
|
|
204
|
+
onConnectionClose(event) {
|
|
205
|
+
console.log('disconnected from jetstream', event.code, event.reason);
|
|
206
|
+
},
|
|
207
|
+
onConnectionError(event) {
|
|
208
|
+
console.error('jetstream error', event.error);
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### disabling event validation
|
|
214
|
+
|
|
215
|
+
by default, jetstream events are validated. disable this for slightly better performance if you
|
|
216
|
+
trust the server:
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
const subscription = new JetstreamSubscription({
|
|
220
|
+
url: 'wss://jetstream2.us-east.bsky.network',
|
|
221
|
+
validateEvents: false,
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
note: this only disables validation of the event envelope. you should still validate records using
|
|
226
|
+
`is()` from `@atcute/lexicons`.
|
|
227
|
+
|
|
228
|
+
### WebSocket options
|
|
229
|
+
|
|
230
|
+
pass options to the underlying
|
|
231
|
+
[partysocket](https://github.com/partykit/partykit/tree/main/packages/partysocket) WebSocket for
|
|
232
|
+
custom reconnection behavior:
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
const subscription = new JetstreamSubscription({
|
|
236
|
+
url: 'wss://jetstream2.us-east.bsky.network',
|
|
237
|
+
ws: {
|
|
238
|
+
maxRetries: 10,
|
|
239
|
+
minReconnectionDelay: 1000,
|
|
240
|
+
maxReconnectionDelay: 30000,
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './subscription.
|
|
2
|
-
export * from './types.
|
|
3
|
-
export * from './typedefs.
|
|
1
|
+
export * from './subscription.ts';
|
|
2
|
+
export * from './types.ts';
|
|
3
|
+
export * from './typedefs.ts';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/subscription.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Did } from '@atcute/lexicons';
|
|
|
2
2
|
import { EventIterator } from '@mary-ext/event-iterator';
|
|
3
3
|
import type { CloseEvent, ErrorEvent, Options } from 'partysocket/ws';
|
|
4
4
|
import type { ReadonlyDeep } from 'type-fest';
|
|
5
|
-
import type { JetstreamEvent } from './types.
|
|
5
|
+
import type { JetstreamEvent } from './types.ts';
|
|
6
6
|
export interface JetstreamSubscriptionOptions {
|
|
7
7
|
url: string | string[];
|
|
8
8
|
cursor?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../lib/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../lib/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGzD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAG9C,OAAO,KAAK,EAAE,cAAc,EAAsB,MAAM,YAAY,CAAC;AAErE,MAAM,WAAW,4BAA4B;IAC5C,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IAEnB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC1C,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAChD,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,EAAE,CAAC,EAAE,OAAO,CAAC;CACb;AAID,qBAAa,qBAAqB;;IAUjC,YAAY,OAAO,EAAE,4BAA4B,EAQhD;IA4GD,CAAC,MAAM,CAAC,aAAa,CAAC,kCAkBrB;IAED,IAAI,MAAM,WAET;IAED,UAAU,IAAI,YAAY,CAAC,4BAA4B,CAAC,CAEvD;IAED,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,4BAA4B,CAAC,GAAG,IAAI,CAkBlE;CACD"}
|
package/dist/subscription.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../lib/subscription.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../lib/subscription.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,a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AAC,CAAC,CAAC;YAEH,IAAI,eAAe,EAAE,CAAC;gBACrB,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAChB,IAAI,CAAC,OAAO,EAAE,CAAC;YAChB,CAAC;QACF,CAAC;IACF,CAAC;CACD"}
|
package/dist/typedefs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as v from '@badrap/valita';
|
|
2
|
-
import type * as t from './types.
|
|
2
|
+
import type * as t from './types.ts';
|
|
3
3
|
export declare const createCommitSchema: v.Type<t.CreateCommit>;
|
|
4
4
|
export declare const updateCommitSchema: v.Type<t.UpdateCommit>;
|
|
5
5
|
export declare const deleteCommitSchema: v.Type<t.DeleteCommit>;
|
package/dist/typedefs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AAEpC,OAAO,KAAK,KAAK,CAAC,MAAM,YAAY,CAAC;AAoBrC,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAIpD,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAIpD,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAEpD,CAAC;AAEH,eAAO,MAAM,qBAAqB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAI3D,CAAC;AAOF,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAGlD,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAKpD,CAAC;AAEH,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAGtD,CAAC;AAEH,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAKlD,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAGpD,CAAC;AAEH,eAAO,MAAM,oBAAoB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAIzD,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAIpE,CAAC;AAEH,eAAO,MAAM,4BAA4B,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,sBAAsB,CAGxE,CAAC;AAEH,eAAO,MAAM,wBAAwB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAyC,CAAC"}
|
package/dist/typedefs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as v from '@badrap/valita';
|
|
2
1
|
import { isCid, isDatetime, isDid, isHandle, isNsid, isRecordKey, isTid } from '@atcute/lexicons/syntax';
|
|
2
|
+
import * as v from '@badrap/valita';
|
|
3
3
|
const cidString = v.string().assert(isCid, `must be a cid`);
|
|
4
4
|
const datetimeString = v.string().assert(isDatetime, `must be a datetime`);
|
|
5
5
|
const didString = v.string().assert(isDid, `must be a did`);
|
package/dist/typedefs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typedefs.js","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"typedefs.js","sourceRoot":"","sources":["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
|
+
export * from './subscription.ts';
|
|
2
|
+
export * from './types.ts';
|
|
3
|
+
export * from './typedefs.ts';
|
package/lib/subscription.ts
CHANGED
|
@@ -2,14 +2,12 @@ import type { Did } from '@atcute/lexicons';
|
|
|
2
2
|
|
|
3
3
|
import { EventIterator } from '@mary-ext/event-iterator';
|
|
4
4
|
import { SimpleEventEmitter } from '@mary-ext/simple-event-emitter';
|
|
5
|
-
|
|
6
5
|
import { WebSocket as ReconnectingWebSocket } from 'partysocket';
|
|
7
6
|
import type { CloseEvent, ErrorEvent, Options } from 'partysocket/ws';
|
|
8
|
-
|
|
9
7
|
import type { ReadonlyDeep } from 'type-fest';
|
|
10
8
|
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
9
|
+
import { jetstreamEventSchema } from './typedefs.ts';
|
|
10
|
+
import type { JetstreamEvent, JetstreamProcedure } from './types.ts';
|
|
13
11
|
|
|
14
12
|
export interface JetstreamSubscriptionOptions {
|
|
15
13
|
url: string | string[];
|
package/lib/typedefs.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as v from '@badrap/valita';
|
|
2
|
-
|
|
3
1
|
import { isCid, isDatetime, isDid, isHandle, isNsid, isRecordKey, isTid } from '@atcute/lexicons/syntax';
|
|
4
2
|
|
|
5
|
-
import
|
|
3
|
+
import * as v from '@badrap/valita';
|
|
4
|
+
|
|
5
|
+
import type * as t from './types.ts';
|
|
6
6
|
|
|
7
7
|
const cidString = v.string().assert(isCid, `must be a cid`);
|
|
8
8
|
const datetimeString = v.string().assert(isDatetime, `must be a datetime`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"type": "module",
|
|
3
2
|
"name": "@atcute/jetstream",
|
|
4
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
5
4
|
"description": "lightweight and cute Jetstream subscriber for AT Protocol",
|
|
6
5
|
"license": "0BSD",
|
|
7
6
|
"repository": {
|
|
@@ -12,27 +11,29 @@
|
|
|
12
11
|
"dist/",
|
|
13
12
|
"lib/",
|
|
14
13
|
"!lib/**/*.bench.ts",
|
|
15
|
-
"!lib/**/*.test.ts"
|
|
14
|
+
"!lib/**/*.test.ts",
|
|
15
|
+
"!dist/**/*.{test,bench}.*"
|
|
16
16
|
],
|
|
17
|
+
"type": "module",
|
|
17
18
|
"exports": {
|
|
18
19
|
".": "./dist/index.js"
|
|
19
20
|
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
20
24
|
"dependencies": {
|
|
21
25
|
"@badrap/valita": "^0.4.6",
|
|
22
26
|
"@mary-ext/event-iterator": "^1.0.0",
|
|
23
|
-
"@mary-ext/simple-event-emitter": "^1.0.
|
|
24
|
-
"partysocket": "^1.1.
|
|
27
|
+
"@mary-ext/simple-event-emitter": "^1.0.1",
|
|
28
|
+
"partysocket": "^1.1.18",
|
|
25
29
|
"type-fest": "^4.41.0",
|
|
26
|
-
"
|
|
27
|
-
"@atcute/lexicons": "^1.2.2"
|
|
30
|
+
"@atcute/lexicons": "^1.3.1"
|
|
28
31
|
},
|
|
29
|
-
"
|
|
30
|
-
"@
|
|
31
|
-
"vitest": "^3.2.4"
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@atcute/lexicons": "^1.0.0"
|
|
32
34
|
},
|
|
33
35
|
"scripts": {
|
|
34
|
-
"build": "
|
|
35
|
-
"test": "vitest run --coverage",
|
|
36
|
+
"build": "tsgo",
|
|
36
37
|
"prepublish": "rm -rf dist; pnpm run build"
|
|
37
38
|
}
|
|
38
39
|
}
|