@atcute/jetstream 1.1.1 → 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 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/subscription.d.ts +2 -45
- package/dist/subscription.d.ts.map +1 -1
- package/dist/subscription.js +1 -1
- package/dist/subscription.js.map +1 -1
- package/dist/typedefs.d.ts +16 -0
- package/dist/typedefs.d.ts.map +1 -0
- package/dist/typedefs.js +71 -0
- package/dist/typedefs.js.map +1 -0
- package/dist/types.d.ts +59 -249
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -93
- package/dist/types.js.map +1 -1
- package/lib/index.ts +3 -2
- package/lib/subscription.ts +2 -3
- package/lib/typedefs.ts +98 -0
- package/lib/types.ts +47 -259
- 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
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
|
package/dist/subscription.d.ts
CHANGED
|
@@ -2,6 +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.ts';
|
|
5
6
|
export interface JetstreamSubscriptionOptions {
|
|
6
7
|
url: string | string[];
|
|
7
8
|
cursor?: number;
|
|
@@ -31,51 +32,7 @@ export interface JetstreamSubscriptionOptions {
|
|
|
31
32
|
export declare class JetstreamSubscription {
|
|
32
33
|
#private;
|
|
33
34
|
constructor(options: JetstreamSubscriptionOptions);
|
|
34
|
-
[Symbol.asyncIterator](): EventIterator<
|
|
35
|
-
did: `did:${string}:${string}`;
|
|
36
|
-
time_us: number;
|
|
37
|
-
kind: "commit";
|
|
38
|
-
commit: {
|
|
39
|
-
rev: string;
|
|
40
|
-
collection: `${string}.${string}.${string}`;
|
|
41
|
-
rkey: string;
|
|
42
|
-
operation: "create";
|
|
43
|
-
cid: string;
|
|
44
|
-
record: Record<string, unknown>;
|
|
45
|
-
} | {
|
|
46
|
-
rev: string;
|
|
47
|
-
collection: `${string}.${string}.${string}`;
|
|
48
|
-
rkey: string;
|
|
49
|
-
operation: "update";
|
|
50
|
-
cid: string;
|
|
51
|
-
record: Record<string, unknown>;
|
|
52
|
-
} | {
|
|
53
|
-
rev: string;
|
|
54
|
-
collection: `${string}.${string}.${string}`;
|
|
55
|
-
rkey: string;
|
|
56
|
-
operation: "delete";
|
|
57
|
-
};
|
|
58
|
-
} | {
|
|
59
|
-
did: `did:${string}:${string}`;
|
|
60
|
-
time_us: number;
|
|
61
|
-
kind: "identity";
|
|
62
|
-
identity: {
|
|
63
|
-
did: `did:${string}:${string}`;
|
|
64
|
-
handle: `${string}.${string}`;
|
|
65
|
-
seq: number;
|
|
66
|
-
time: string;
|
|
67
|
-
};
|
|
68
|
-
} | {
|
|
69
|
-
did: `did:${string}:${string}`;
|
|
70
|
-
time_us: number;
|
|
71
|
-
kind: "account";
|
|
72
|
-
account: {
|
|
73
|
-
did: `did:${string}:${string}`;
|
|
74
|
-
active: boolean;
|
|
75
|
-
seq: number;
|
|
76
|
-
time: string;
|
|
77
|
-
};
|
|
78
|
-
}>;
|
|
35
|
+
[Symbol.asyncIterator](): EventIterator<JetstreamEvent>;
|
|
79
36
|
get cursor(): number;
|
|
80
37
|
getOptions(): ReadonlyDeep<JetstreamSubscriptionOptions>;
|
|
81
38
|
updateOptions(options: Partial<JetstreamSubscriptionOptions>): void;
|
|
@@ -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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventIterator } from '@mary-ext/event-iterator';
|
|
2
2
|
import { SimpleEventEmitter } from '@mary-ext/simple-event-emitter';
|
|
3
3
|
import { WebSocket as ReconnectingWebSocket } from 'partysocket';
|
|
4
|
-
import { jetstreamEventSchema } from './
|
|
4
|
+
import { jetstreamEventSchema } from './typedefs.js';
|
|
5
5
|
const PARSE_OPTIONS = { mode: 'passthrough' };
|
|
6
6
|
export class JetstreamSubscription {
|
|
7
7
|
#listening = 0;
|
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,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,SAAS,IAAI,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAIjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAmCrD,MAAM,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F,CAAC;CACD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as v from '@badrap/valita';
|
|
2
|
+
import type * as t from './types.ts';
|
|
3
|
+
export declare const createCommitSchema: v.Type<t.CreateCommit>;
|
|
4
|
+
export declare const updateCommitSchema: v.Type<t.UpdateCommit>;
|
|
5
|
+
export declare const deleteCommitSchema: v.Type<t.DeleteCommit>;
|
|
6
|
+
export declare const commitOperationSchema: v.Type<t.CommitOperation>;
|
|
7
|
+
export declare const commitEventSchema: v.Type<t.CommitEvent>;
|
|
8
|
+
export declare const identityDataSchema: v.Type<t.IdentityData>;
|
|
9
|
+
export declare const identityEventSchema: v.Type<t.IdentityEvent>;
|
|
10
|
+
export declare const accountDataSchema: v.Type<t.AccountData>;
|
|
11
|
+
export declare const accountEventSchema: v.Type<t.AccountEvent>;
|
|
12
|
+
export declare const jetstreamEventSchema: v.Type<t.JetstreamEvent>;
|
|
13
|
+
export declare const optionsUpdatePayloadSchema: v.Type<t.OptionsUpdatePayload>;
|
|
14
|
+
export declare const optionsUpdateProcedureSchema: v.Type<t.OptionsUpdateProcedure>;
|
|
15
|
+
export declare const jetstreamProcedureSchema: v.Type<t.JetstreamProcedure>;
|
|
16
|
+
//# sourceMappingURL=typedefs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isCid, isDatetime, isDid, isHandle, isNsid, isRecordKey, isTid } from '@atcute/lexicons/syntax';
|
|
2
|
+
import * as v from '@badrap/valita';
|
|
3
|
+
const cidString = v.string().assert(isCid, `must be a cid`);
|
|
4
|
+
const datetimeString = v.string().assert(isDatetime, `must be a datetime`);
|
|
5
|
+
const didString = v.string().assert(isDid, `must be a did`);
|
|
6
|
+
const handleString = v.string().assert(isHandle, `must be a handle`);
|
|
7
|
+
const nsidString = v.string().assert(isNsid, `must be an nsid`);
|
|
8
|
+
const rkeyString = v.string().assert(isRecordKey, `must be a rkey`);
|
|
9
|
+
const tidString = v.string().assert(isTid, `must be a tid`);
|
|
10
|
+
const integer = v
|
|
11
|
+
.number()
|
|
12
|
+
.assert((input) => input >= 0 && Number.isSafeInteger(input), `must be a nonnegative integer`);
|
|
13
|
+
const baseCommit = v.object({
|
|
14
|
+
rev: tidString,
|
|
15
|
+
collection: nsidString,
|
|
16
|
+
rkey: rkeyString,
|
|
17
|
+
});
|
|
18
|
+
export const createCommitSchema = baseCommit.extend({
|
|
19
|
+
operation: v.literal('create'),
|
|
20
|
+
cid: cidString,
|
|
21
|
+
record: v.record(v.unknown()),
|
|
22
|
+
});
|
|
23
|
+
export const updateCommitSchema = baseCommit.extend({
|
|
24
|
+
operation: v.literal('update'),
|
|
25
|
+
cid: cidString,
|
|
26
|
+
record: v.record(v.unknown()),
|
|
27
|
+
});
|
|
28
|
+
export const deleteCommitSchema = baseCommit.extend({
|
|
29
|
+
operation: v.literal('delete'),
|
|
30
|
+
});
|
|
31
|
+
export const commitOperationSchema = v.union(createCommitSchema, updateCommitSchema, deleteCommitSchema);
|
|
32
|
+
const baseEvent = v.object({
|
|
33
|
+
did: didString,
|
|
34
|
+
time_us: integer,
|
|
35
|
+
});
|
|
36
|
+
export const commitEventSchema = baseEvent.extend({
|
|
37
|
+
kind: v.literal('commit'),
|
|
38
|
+
commit: commitOperationSchema,
|
|
39
|
+
});
|
|
40
|
+
export const identityDataSchema = v.object({
|
|
41
|
+
did: didString,
|
|
42
|
+
handle: handleString,
|
|
43
|
+
seq: integer,
|
|
44
|
+
time: datetimeString,
|
|
45
|
+
});
|
|
46
|
+
export const identityEventSchema = baseEvent.extend({
|
|
47
|
+
kind: v.literal('identity'),
|
|
48
|
+
identity: identityDataSchema,
|
|
49
|
+
});
|
|
50
|
+
export const accountDataSchema = v.object({
|
|
51
|
+
did: didString,
|
|
52
|
+
active: v.boolean(),
|
|
53
|
+
seq: integer,
|
|
54
|
+
time: datetimeString,
|
|
55
|
+
});
|
|
56
|
+
export const accountEventSchema = baseEvent.extend({
|
|
57
|
+
kind: v.literal('account'),
|
|
58
|
+
account: accountDataSchema,
|
|
59
|
+
});
|
|
60
|
+
export const jetstreamEventSchema = v.union(commitEventSchema, identityEventSchema, accountEventSchema);
|
|
61
|
+
export const optionsUpdatePayloadSchema = v.object({
|
|
62
|
+
wantedCollections: v.array(v.string()).optional(),
|
|
63
|
+
wantedDids: v.array(didString).optional(),
|
|
64
|
+
maxMessageSizeBytes: integer.optional(),
|
|
65
|
+
});
|
|
66
|
+
export const optionsUpdateProcedureSchema = v.object({
|
|
67
|
+
type: v.literal('options_update'),
|
|
68
|
+
payload: optionsUpdatePayloadSchema,
|
|
69
|
+
});
|
|
70
|
+
export const jetstreamProcedureSchema = v.union(optionsUpdateProcedureSchema);
|
|
71
|
+
//# sourceMappingURL=typedefs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typedefs.js","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEzG,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AAIpC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;AAC5D,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC;AAC3E,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;AAC5D,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,QA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