@atcute/firehose 0.1.0 → 0.1.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.
- package/README.md +192 -4
- package/dist/frame-decoder.d.ts +1 -1
- package/dist/frame-decoder.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/subscription.d.ts +1 -1
- package/dist/subscription.d.ts.map +1 -1
- package/dist/subscription.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/lib/frame-decoder.ts +1 -1
- package/lib/index.ts +2 -2
- package/lib/subscription.ts +2 -4
- package/lib/types.ts +17 -16
- package/package.json +17 -10
package/README.md
CHANGED
|
@@ -1,23 +1,211 @@
|
|
|
1
1
|
# @atcute/firehose
|
|
2
2
|
|
|
3
|
-
lightweight
|
|
3
|
+
lightweight XRPC subscription client for AT Protocol.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @atcute/firehose
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
this package provides a generic client for XRPC subscriptions - the WebSocket-based streaming
|
|
10
|
+
protocol used by AT Protocol. it handles CBOR frame decoding, automatic reconnection, and optional
|
|
11
|
+
schema validation.
|
|
12
|
+
|
|
13
|
+
for consuming the Bluesky network firehose specifically, consider using `@atcute/jetstream` instead,
|
|
14
|
+
which provides a simpler JSON-based interface.
|
|
15
|
+
|
|
16
|
+
## usage
|
|
17
|
+
|
|
18
|
+
### subscribing to the relay firehose
|
|
4
19
|
|
|
5
20
|
```ts
|
|
6
21
|
import { FirehoseSubscription } from '@atcute/firehose';
|
|
7
22
|
import { ComAtprotoSyncSubscribeRepos } from '@atcute/atproto';
|
|
8
23
|
|
|
24
|
+
const subscription = new FirehoseSubscription({
|
|
25
|
+
service: 'wss://bsky.network',
|
|
26
|
+
nsid: ComAtprotoSyncSubscribeRepos.mainSchema,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
for await (const message of subscription) {
|
|
30
|
+
console.log(message.$type, message.seq);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
the connection opens when you start iterating and closes when you break out of the loop. the
|
|
35
|
+
underlying WebSocket automatically reconnects on disconnection.
|
|
36
|
+
|
|
37
|
+
### handling message types
|
|
38
|
+
|
|
39
|
+
messages include a `$type` field indicating their type:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
for await (const message of subscription) {
|
|
43
|
+
switch (message.$type) {
|
|
44
|
+
case 'com.atproto.sync.subscribeRepos#commit': {
|
|
45
|
+
// repository commit (record creates, updates, deletes)
|
|
46
|
+
console.log('commit:', message.repo, message.rev);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
case 'com.atproto.sync.subscribeRepos#handle': {
|
|
51
|
+
// handle change
|
|
52
|
+
console.log('handle:', message.did, message.handle);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
case 'com.atproto.sync.subscribeRepos#migrate': {
|
|
57
|
+
// account migration
|
|
58
|
+
console.log('migrate:', message.did, message.migrateTo);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
case 'com.atproto.sync.subscribeRepos#tombstone': {
|
|
63
|
+
// account deletion
|
|
64
|
+
console.log('tombstone:', message.did);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
case 'com.atproto.sync.subscribeRepos#identity': {
|
|
69
|
+
// identity update
|
|
70
|
+
console.log('identity:', message.did);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
case 'com.atproto.sync.subscribeRepos#account': {
|
|
75
|
+
// account status change
|
|
76
|
+
console.log('account:', message.did, message.active);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### tracking cursor for resumption
|
|
84
|
+
|
|
85
|
+
use a function for `params` to provide the current cursor on each connection attempt:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
9
88
|
let cursor: number | undefined;
|
|
10
89
|
|
|
90
|
+
// load saved cursor if resuming
|
|
91
|
+
const saved = localStorage.getItem('firehose-cursor');
|
|
92
|
+
if (saved) {
|
|
93
|
+
cursor = Number(saved);
|
|
94
|
+
}
|
|
95
|
+
|
|
11
96
|
const subscription = new FirehoseSubscription({
|
|
12
|
-
service:
|
|
97
|
+
service: 'wss://bsky.network',
|
|
13
98
|
nsid: ComAtprotoSyncSubscribeRepos.mainSchema,
|
|
99
|
+
// function is called on each connection/reconnection
|
|
14
100
|
params: () => ({ cursor }),
|
|
15
101
|
});
|
|
16
102
|
|
|
17
103
|
for await (const message of subscription) {
|
|
18
|
-
if (
|
|
104
|
+
if ('seq' in message) {
|
|
19
105
|
cursor = message.seq;
|
|
20
|
-
|
|
106
|
+
|
|
107
|
+
// periodically save cursor for recovery
|
|
108
|
+
if (cursor % 1000 === 0) {
|
|
109
|
+
localStorage.setItem('firehose-cursor', String(cursor));
|
|
110
|
+
}
|
|
21
111
|
}
|
|
22
112
|
}
|
|
23
113
|
```
|
|
114
|
+
|
|
115
|
+
the params function is called on each connection attempt, so when the WebSocket reconnects after a
|
|
116
|
+
disconnection, it automatically uses the latest cursor value.
|
|
117
|
+
|
|
118
|
+
### using multiple servers
|
|
119
|
+
|
|
120
|
+
pass an array of URLs for automatic failover. the client randomly selects one on each connection:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const subscription = new FirehoseSubscription({
|
|
124
|
+
service: ['wss://bsky.network', 'wss://bsky-relay.example.com'],
|
|
125
|
+
nsid: ComAtprotoSyncSubscribeRepos.mainSchema,
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### handling errors
|
|
130
|
+
|
|
131
|
+
XRPC subscriptions can send error frames. handle them with the `onError` callback:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
const subscription = new FirehoseSubscription({
|
|
135
|
+
service: 'wss://bsky.network',
|
|
136
|
+
nsid: ComAtprotoSyncSubscribeRepos.mainSchema,
|
|
137
|
+
onError(error, message) {
|
|
138
|
+
console.error('firehose error:', error, message);
|
|
139
|
+
// common errors:
|
|
140
|
+
// - "FutureCursor": cursor is ahead of the server
|
|
141
|
+
// - "ConsumerTooSlow": client is not consuming messages fast enough
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### connection lifecycle callbacks
|
|
147
|
+
|
|
148
|
+
handle connection events for logging or UI updates:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
const subscription = new FirehoseSubscription({
|
|
152
|
+
service: 'wss://bsky.network',
|
|
153
|
+
nsid: ComAtprotoSyncSubscribeRepos.mainSchema,
|
|
154
|
+
onConnectionOpen(event) {
|
|
155
|
+
console.log('connected to firehose');
|
|
156
|
+
},
|
|
157
|
+
onConnectionClose(event) {
|
|
158
|
+
console.log('disconnected:', event.code, event.reason);
|
|
159
|
+
},
|
|
160
|
+
onConnectionError(event) {
|
|
161
|
+
console.error('connection error:', event.error);
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### updating options at runtime
|
|
167
|
+
|
|
168
|
+
change options using `updateOptions()`. this triggers a reconnection:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
const subscription = new FirehoseSubscription({
|
|
172
|
+
service: 'wss://bsky.network',
|
|
173
|
+
nsid: ComAtprotoSyncSubscribeRepos.mainSchema,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// later, switch to a different service
|
|
177
|
+
subscription.updateOptions({
|
|
178
|
+
service: 'wss://different-relay.example.com',
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### disabling message validation
|
|
183
|
+
|
|
184
|
+
by default, messages are validated against the schema. disable this for better performance if you
|
|
185
|
+
trust the server:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
const subscription = new FirehoseSubscription({
|
|
189
|
+
service: 'wss://bsky.network',
|
|
190
|
+
nsid: ComAtprotoSyncSubscribeRepos.mainSchema,
|
|
191
|
+
validateMessages: false,
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### WebSocket options
|
|
196
|
+
|
|
197
|
+
pass options to the underlying
|
|
198
|
+
[partysocket](https://github.com/partykit/partykit/tree/main/packages/partysocket) WebSocket for
|
|
199
|
+
custom reconnection behavior:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
const subscription = new FirehoseSubscription({
|
|
203
|
+
service: 'wss://bsky.network',
|
|
204
|
+
nsid: ComAtprotoSyncSubscribeRepos.mainSchema,
|
|
205
|
+
ws: {
|
|
206
|
+
maxRetries: 10,
|
|
207
|
+
minReconnectionDelay: 1000,
|
|
208
|
+
maxReconnectionDelay: 30000,
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
```
|
package/dist/frame-decoder.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frame-decoder.d.ts","sourceRoot":"","sources":["../lib/frame-decoder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAA+B,MAAM,YAAY,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"frame-decoder.d.ts","sourceRoot":"","sources":["../lib/frame-decoder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAA+B,MAAM,YAAY,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,WAAW,WAAY,UAAU,KAAG,YAuBhD,CAAC;AAeF;;GAEG;AACH,eAAO,MAAM,eAAe,kBAAmB,MAAM,GAAG,SAAS,QAAQ,MAAM,KAAG,MAAM,GAAG,SAU1F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,SAAU,OAAO,iBAAiB,MAAM,GAAG,SAAS,QAAQ,MAAM,KAAG,OAQ9F,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { FirehoseSubscription } from './subscription.
|
|
2
|
-
export type { FirehoseSubscriptionOptions, MessageOf, ParamsOf } from './types.
|
|
1
|
+
export { FirehoseSubscription } from './subscription.ts';
|
|
2
|
+
export type { FirehoseSubscriptionOptions, MessageOf, ParamsOf } from './types.ts';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/subscription.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type XRPCSubscriptionMetadata } from '@atcute/lexicons/validations';
|
|
2
2
|
import { EventIterator } from '@mary-ext/event-iterator';
|
|
3
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
4
|
-
import type { FirehoseSubscriptionOptions, MessageOf } from './types.
|
|
4
|
+
import type { FirehoseSubscriptionOptions, MessageOf } from './types.ts';
|
|
5
5
|
/**
|
|
6
6
|
* generic XRPC subscription client for AT Protocol
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../lib/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAExF,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../lib/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAExF,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAG9C,OAAO,KAAK,EAAE,2BAA2B,EAAE,SAAS,EAAY,MAAM,YAAY,CAAC;AAEnF;;GAEG;AACH,qBAAa,oBAAoB,CAAC,OAAO,SAAS,wBAAwB;;IAQzE;;OAEG;IACH,YAAY,OAAO,EAAE,2BAA2B,CAAC,OAAO,CAAC,EAExD;IA0FD,CAAC,MAAM,CAAC,aAAa,CAAC,sCAkBrB;IAED;;OAEG;IACH,UAAU,IAAI,YAAY,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC,CAE/D;IAED;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAO1E;CACD"}
|
package/dist/subscription.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../lib/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiC,MAAM,8BAA8B,CAAC;AAExF,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":"AAAA,OAAO,EAAE,SAAS,EAAiC,MAAM,8BAA8B,CAAC;AAExF,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,SAAS,IAAI,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGjE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGhE;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAChC,UAAU,GAAG,CAAC,CAAC;IACf,GAAG,CAAyB;IAE5B,QAAQ,GAAG,IAAI,kBAAkB,EAAiC,CAAC;IAEnE,QAAQ,CAAuC;IAE/C;;OAEG;IACH,YAAY,OAA6C;QACxD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,OAAO;QACN,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,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vent, ErrorEvent, Options } from 'partysocket/ws';
|
|
3
2
|
import type { BaseSchema } from '@atcute/lexicons/validations';
|
|
3
|
+
import type { CloseEvent, ErrorEvent, Options } from 'partysocket/ws';
|
|
4
4
|
/**
|
|
5
5
|
* extracts the params type from an XRPC subscription schema
|
|
6
6
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEtE;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IACrB,CAAC,SAAS,wBAAwB,CAAC,MAAM,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GACxD,OAAO,SAAS,IAAI,GACnB,SAAS,GACT,OAAO,SAAS,UAAU,GACzB,WAAW,CAAC,OAAO,CAAC,GACpB,KAAK,GACP,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IACtB,CAAC,SAAS,wBAAwB,CAAC,GAAG,EAAE,MAAM,QAAQ,EAAE,GAAG,CAAC,GACzD,QAAQ,SAAS,IAAI,GACpB,OAAO,GACP,QAAQ,SAAS,UAAU,GAC1B,WAAW,CAAC,QAAQ,CAAC,GACrB,KAAK,GACP,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,WAAW,2BAA2B,CAAC,OAAO,SAAS,wBAAwB;IACpF;;OA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'./subscription.
|
|
2
|
-
export type { FirehoseSubscriptionOptions, MessageOf, ParamsOf } from './types.
|
|
1
|
+
export { FirehoseSubscription } from './subscription.ts';
|
|
2
|
+
export type { FirehoseSubscriptionOptions, MessageOf, ParamsOf } from './types.ts';
|
package/lib/subscription.ts
CHANGED
|
@@ -2,13 +2,11 @@ import { safeParse, type XRPCSubscriptionMetadata } from '@atcute/lexicons/valid
|
|
|
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
|
-
|
|
8
6
|
import type { ReadonlyDeep } from 'type-fest';
|
|
9
7
|
|
|
10
|
-
import { addTypeToBody, decodeFrame } from './frame-decoder.
|
|
11
|
-
import type { FirehoseSubscriptionOptions, MessageOf, ParamsOf } from './types.
|
|
8
|
+
import { addTypeToBody, decodeFrame } from './frame-decoder.ts';
|
|
9
|
+
import type { FirehoseSubscriptionOptions, MessageOf, ParamsOf } from './types.ts';
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* generic XRPC subscription client for AT Protocol
|
package/lib/types.ts
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import type { InferOutput, XRPCSubscriptionMetadata } from '@atcute/lexicons/validations';
|
|
2
|
+
import type { BaseSchema } from '@atcute/lexicons/validations';
|
|
2
3
|
|
|
3
4
|
import type { CloseEvent, ErrorEvent, Options } from 'partysocket/ws';
|
|
4
5
|
|
|
5
|
-
import type { BaseSchema } from '@atcute/lexicons/validations';
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* extracts the params type from an XRPC subscription schema
|
|
9
8
|
*/
|
|
10
|
-
export type ParamsOf<T> =
|
|
11
|
-
|
|
12
|
-
?
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
export type ParamsOf<T> =
|
|
10
|
+
T extends XRPCSubscriptionMetadata<infer TParams, any, any>
|
|
11
|
+
? TParams extends null
|
|
12
|
+
? undefined
|
|
13
|
+
: TParams extends BaseSchema
|
|
14
|
+
? InferOutput<TParams>
|
|
15
|
+
: never
|
|
16
|
+
: never;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* extracts the message type from an XRPC subscription schema
|
|
20
20
|
*/
|
|
21
|
-
export type MessageOf<T> =
|
|
22
|
-
|
|
23
|
-
?
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
export type MessageOf<T> =
|
|
22
|
+
T extends XRPCSubscriptionMetadata<any, infer TMessage, any>
|
|
23
|
+
? TMessage extends null
|
|
24
|
+
? unknown
|
|
25
|
+
: TMessage extends BaseSchema
|
|
26
|
+
? InferOutput<TMessage>
|
|
27
|
+
: never
|
|
28
|
+
: never;
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* configuration options for FirehoseSubscription
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"type": "module",
|
|
3
2
|
"name": "@atcute/firehose",
|
|
4
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
5
4
|
"description": "lightweight and cute XRPC subscription client for AT Protocol",
|
|
6
5
|
"license": "0BSD",
|
|
7
6
|
"repository": {
|
|
@@ -12,25 +11,33 @@
|
|
|
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
|
"@mary-ext/event-iterator": "^1.0.0",
|
|
22
|
-
"@mary-ext/simple-event-emitter": "^1.0.
|
|
23
|
-
"partysocket": "^1.1.
|
|
26
|
+
"@mary-ext/simple-event-emitter": "^1.0.1",
|
|
27
|
+
"partysocket": "^1.1.18",
|
|
24
28
|
"type-fest": "^4.41.0",
|
|
25
|
-
"@atcute/
|
|
26
|
-
"@atcute/
|
|
27
|
-
"@atcute/uint8array": "^1.
|
|
29
|
+
"@atcute/cbor": "^2.3.3",
|
|
30
|
+
"@atcute/lexicons": "^1.3.1",
|
|
31
|
+
"@atcute/uint8array": "^1.1.1"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
30
|
-
"@atcute/atproto": "^3.1.
|
|
34
|
+
"@atcute/atproto": "^3.1.12"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@atcute/lexicons": "^1.0.0"
|
|
31
38
|
},
|
|
32
39
|
"scripts": {
|
|
33
|
-
"build": "
|
|
40
|
+
"build": "tsgo",
|
|
34
41
|
"prepublish": "rm -rf dist; pnpm run build"
|
|
35
42
|
}
|
|
36
43
|
}
|