@atcute/jetstream 1.0.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/LICENSE +17 -0
- package/README.md +34 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/subscription.d.ts +82 -0
- package/dist/subscription.js +117 -0
- package/dist/subscription.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.js +94 -0
- package/dist/types.js.map +1 -0
- package/lib/index.ts +2 -0
- package/lib/subscription.ts +192 -0
- package/lib/types.ts +286 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
2
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
3
|
+
in the Software without restriction, including without limitation the rights
|
|
4
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
5
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
6
|
+
furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all
|
|
9
|
+
copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
12
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
14
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
17
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @atcute/jetstream
|
|
2
|
+
|
|
3
|
+
a simple Jetstream client
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { JetstreamSubscription } from '@atcute/jetstream';
|
|
7
|
+
import { is } from '@atcute/lexicons';
|
|
8
|
+
|
|
9
|
+
import { AppBskyFeedPost } from '@atcute/bluesky';
|
|
10
|
+
|
|
11
|
+
const subscription = new JetstreamSubscription({
|
|
12
|
+
url: 'wss://jetstream2.us-east.bsky.network',
|
|
13
|
+
wantedCollections: ['app.bsky.feed.post'],
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
for await (const event of subscription) {
|
|
17
|
+
if (event.kind === 'commit') {
|
|
18
|
+
const commit = event.commit;
|
|
19
|
+
|
|
20
|
+
if (commit.collection !== 'app.bsky.feed.post') {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (commit.operation === 'create') {
|
|
25
|
+
const record = commit.record;
|
|
26
|
+
if (!is(AppBskyFeedPost.mainSchema, record)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log(`${record.text}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Did } from '@atcute/lexicons';
|
|
2
|
+
import { EventIterator } from '@mary-ext/event-iterator';
|
|
3
|
+
import type { CloseEvent, ErrorEvent, Options } from 'partysocket/ws';
|
|
4
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
5
|
+
export interface JetstreamSubscriptionOptions {
|
|
6
|
+
url: string;
|
|
7
|
+
cursor?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Array of collection NSIDs that you're interested in receiving commit events
|
|
10
|
+
* for, pass in an empty array for no commit events.
|
|
11
|
+
*/
|
|
12
|
+
wantedCollections?: string[];
|
|
13
|
+
/**
|
|
14
|
+
* Array of account DIDs that you're interested in receiving commit events
|
|
15
|
+
* for, pass in an empty array for no commit events.
|
|
16
|
+
*/
|
|
17
|
+
wantedDids?: Did[];
|
|
18
|
+
/**
|
|
19
|
+
* Whether to validate Jetstream's events, you'd still need to validate the records.
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
validateEvents?: boolean;
|
|
23
|
+
onConnectionOpen?: (event: Event) => void;
|
|
24
|
+
onConnectionClose?: (event: CloseEvent) => void;
|
|
25
|
+
onConnectionError?: (event: ErrorEvent) => void;
|
|
26
|
+
/**
|
|
27
|
+
* WebSocket connection options
|
|
28
|
+
*/
|
|
29
|
+
ws?: Options;
|
|
30
|
+
}
|
|
31
|
+
export declare class JetstreamSubscription {
|
|
32
|
+
#private;
|
|
33
|
+
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
|
+
}>;
|
|
79
|
+
get cursor(): number;
|
|
80
|
+
getOptions(): ReadonlyDeep<JetstreamSubscriptionOptions>;
|
|
81
|
+
updateOptions(options: Partial<JetstreamSubscriptionOptions>): void;
|
|
82
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { EventIterator } from '@mary-ext/event-iterator';
|
|
2
|
+
import { SimpleEventEmitter } from '@mary-ext/simple-event-emitter';
|
|
3
|
+
import { WebSocket as ReconnectingWebSocket } from 'partysocket';
|
|
4
|
+
import { jetstreamEventSchema } from './types.js';
|
|
5
|
+
const PARSE_OPTIONS = { mode: 'passthrough' };
|
|
6
|
+
export class JetstreamSubscription {
|
|
7
|
+
#listening = 0;
|
|
8
|
+
#ws;
|
|
9
|
+
#emitter = new SimpleEventEmitter();
|
|
10
|
+
#options;
|
|
11
|
+
#cursor;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.#options = options;
|
|
14
|
+
this.#cursor = options.cursor ?? Date.now() * 1_000;
|
|
15
|
+
}
|
|
16
|
+
#sendOptionsUpdate() {
|
|
17
|
+
const ws = this.#ws;
|
|
18
|
+
if (ws === undefined) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const payload = {
|
|
22
|
+
type: 'options_update',
|
|
23
|
+
payload: {
|
|
24
|
+
wantedCollections: this.#options.wantedCollections,
|
|
25
|
+
wantedDids: this.#options.wantedDids,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
ws.send(JSON.stringify(payload));
|
|
29
|
+
}
|
|
30
|
+
#create() {
|
|
31
|
+
if (this.#ws !== undefined) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const { url: wsUrl, ws: wsOptions, validateEvents = true, onConnectionClose, onConnectionError, onConnectionOpen, } = this.#options;
|
|
35
|
+
const emitter = this.#emitter;
|
|
36
|
+
const getUrl = () => {
|
|
37
|
+
const url = new URL('/subscribe', wsUrl);
|
|
38
|
+
url.searchParams.set('requireHello', 'true');
|
|
39
|
+
url.searchParams.set('cursor', '' + this.#cursor);
|
|
40
|
+
return url.toString();
|
|
41
|
+
};
|
|
42
|
+
const ws = new ReconnectingWebSocket(getUrl, null, wsOptions);
|
|
43
|
+
this.#ws = ws;
|
|
44
|
+
ws.binaryType = 'arraybuffer';
|
|
45
|
+
ws.onerror = onConnectionError ?? null;
|
|
46
|
+
ws.onclose = onConnectionClose ?? null;
|
|
47
|
+
ws.onopen = (ev) => {
|
|
48
|
+
this.#sendOptionsUpdate();
|
|
49
|
+
onConnectionOpen?.(ev);
|
|
50
|
+
};
|
|
51
|
+
ws.onmessage = (ev) => {
|
|
52
|
+
const raw = JSON.parse(ev.data);
|
|
53
|
+
let event;
|
|
54
|
+
if (validateEvents) {
|
|
55
|
+
const result = jetstreamEventSchema.try(raw, PARSE_OPTIONS);
|
|
56
|
+
if (!result.ok) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
event = result.value;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
event = raw;
|
|
63
|
+
}
|
|
64
|
+
this.#cursor = event.time_us;
|
|
65
|
+
emitter.emit(event);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
#destroy() {
|
|
69
|
+
const ws = this.#ws;
|
|
70
|
+
if (ws === undefined) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
ws.close();
|
|
74
|
+
this.#ws = undefined;
|
|
75
|
+
}
|
|
76
|
+
[Symbol.asyncIterator]() {
|
|
77
|
+
return new EventIterator((emit) => {
|
|
78
|
+
if (this.#listening === 0) {
|
|
79
|
+
this.#create();
|
|
80
|
+
}
|
|
81
|
+
this.#listening++;
|
|
82
|
+
this.#emitter.subscribe(emit);
|
|
83
|
+
return () => {
|
|
84
|
+
if (this.#listening === 1) {
|
|
85
|
+
this.#destroy();
|
|
86
|
+
}
|
|
87
|
+
this.#listening--;
|
|
88
|
+
this.#emitter.unsubscribe(emit);
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
get cursor() {
|
|
93
|
+
return this.#cursor;
|
|
94
|
+
}
|
|
95
|
+
getOptions() {
|
|
96
|
+
return this.#options;
|
|
97
|
+
}
|
|
98
|
+
updateOptions(options) {
|
|
99
|
+
this.#options = { ...this.#options, ...options };
|
|
100
|
+
if (options.cursor !== undefined) {
|
|
101
|
+
this.#cursor = options.cursor;
|
|
102
|
+
}
|
|
103
|
+
if (this.#ws !== undefined) {
|
|
104
|
+
const isOptionsUpdate = Object.keys(options).every((key) => {
|
|
105
|
+
return key === 'wantedCollections' || key === 'wantedDids';
|
|
106
|
+
});
|
|
107
|
+
if (isOptionsUpdate) {
|
|
108
|
+
this.#sendOptionsUpdate();
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
this.#destroy();
|
|
112
|
+
this.#create();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=subscription.js.map
|
|
@@ -0,0 +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,E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C;YAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAC/B,CAAC;QAED,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC1D,OAAO,GAAG,KAAK,mBAAmB,IAAI,GAAG,KAAK,YAAY,CAAC;YAC5D,CAAC,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/types.d.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import * as v from '@badrap/valita';
|
|
2
|
+
declare const _cidStringSchema: v.Type<string>;
|
|
3
|
+
declare const cidStringSchema: cidStringSchema.$schema;
|
|
4
|
+
declare namespace cidStringSchema {
|
|
5
|
+
export {};
|
|
6
|
+
type $schematype = typeof _cidStringSchema;
|
|
7
|
+
export interface $schema extends $schematype {
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare const _datetimeStringSchema: v.Type<string>;
|
|
11
|
+
declare const datetimeStringSchema: datetimeStringSchema.$schema;
|
|
12
|
+
declare namespace datetimeStringSchema {
|
|
13
|
+
export {};
|
|
14
|
+
type $schematype = typeof _datetimeStringSchema;
|
|
15
|
+
export interface $schema extends $schematype {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
declare const _didStringSchema: v.Type<`did:${string}:${string}`>;
|
|
19
|
+
declare const didStringSchema: didStringSchema.$schema;
|
|
20
|
+
declare namespace didStringSchema {
|
|
21
|
+
export {};
|
|
22
|
+
type $schematype = typeof _didStringSchema;
|
|
23
|
+
export interface $schema extends $schematype {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
declare const _handleStringSchema: v.Type<`${string}.${string}`>;
|
|
27
|
+
declare const handleStringSchema: handleStringSchema.$schema;
|
|
28
|
+
declare namespace handleStringSchema {
|
|
29
|
+
export {};
|
|
30
|
+
type $schematype = typeof _handleStringSchema;
|
|
31
|
+
export interface $schema extends $schematype {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
declare const _nsidStringSchema: v.Type<`${string}.${string}.${string}`>;
|
|
35
|
+
declare const nsidStringSchema: nsidStringSchema.$schema;
|
|
36
|
+
declare namespace nsidStringSchema {
|
|
37
|
+
export {};
|
|
38
|
+
type $schematype = typeof _nsidStringSchema;
|
|
39
|
+
export interface $schema extends $schematype {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
declare const _rkeyStringSchema: v.Type<string>;
|
|
43
|
+
declare const rkeyStringSchema: rkeyStringSchema.$schema;
|
|
44
|
+
declare namespace rkeyStringSchema {
|
|
45
|
+
export {};
|
|
46
|
+
type $schematype = typeof _rkeyStringSchema;
|
|
47
|
+
export interface $schema extends $schematype {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
declare const _tidStringSchema: v.Type<string>;
|
|
51
|
+
declare const tidStringSchema: tidStringSchema.$schema;
|
|
52
|
+
declare namespace tidStringSchema {
|
|
53
|
+
export {};
|
|
54
|
+
type $schematype = typeof _tidStringSchema;
|
|
55
|
+
export interface $schema extends $schematype {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
declare const _integerSchema: v.Type<number>;
|
|
59
|
+
declare const integerSchema: integerSchema.$schema;
|
|
60
|
+
declare namespace integerSchema {
|
|
61
|
+
export {};
|
|
62
|
+
type $schematype = typeof _integerSchema;
|
|
63
|
+
export interface $schema extends $schematype {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
declare const _createCommitSchema: v.ObjectType<Omit<{
|
|
67
|
+
rev: tidStringSchema.$schema;
|
|
68
|
+
collection: nsidStringSchema.$schema;
|
|
69
|
+
rkey: rkeyStringSchema.$schema;
|
|
70
|
+
}, "operation" | "cid" | "record"> & {
|
|
71
|
+
operation: v.Type<"create">;
|
|
72
|
+
cid: cidStringSchema.$schema;
|
|
73
|
+
record: v.Type<Record<string, unknown>>;
|
|
74
|
+
}, undefined>;
|
|
75
|
+
export declare const createCommitSchema: createCommitSchema.$schema;
|
|
76
|
+
export interface CreateCommit extends v.Infer<typeof createCommitSchema> {
|
|
77
|
+
}
|
|
78
|
+
export declare namespace createCommitSchema {
|
|
79
|
+
export {};
|
|
80
|
+
type $schematype = typeof _createCommitSchema;
|
|
81
|
+
export interface $schema extends $schematype {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
declare const _updateCommitSchema: v.ObjectType<Omit<{
|
|
85
|
+
rev: tidStringSchema.$schema;
|
|
86
|
+
collection: nsidStringSchema.$schema;
|
|
87
|
+
rkey: rkeyStringSchema.$schema;
|
|
88
|
+
}, "operation" | "cid" | "record"> & {
|
|
89
|
+
operation: v.Type<"update">;
|
|
90
|
+
cid: cidStringSchema.$schema;
|
|
91
|
+
record: v.Type<Record<string, unknown>>;
|
|
92
|
+
}, undefined>;
|
|
93
|
+
export declare const updateCommitSchema: updateCommitSchema.$schema;
|
|
94
|
+
export interface UpdateCommit extends v.Infer<typeof updateCommitSchema> {
|
|
95
|
+
}
|
|
96
|
+
export declare namespace updateCommitSchema {
|
|
97
|
+
export {};
|
|
98
|
+
type $schematype = typeof _updateCommitSchema;
|
|
99
|
+
export interface $schema extends $schematype {
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
declare const _deleteCommitSchema: v.ObjectType<Omit<{
|
|
103
|
+
rev: tidStringSchema.$schema;
|
|
104
|
+
collection: nsidStringSchema.$schema;
|
|
105
|
+
rkey: rkeyStringSchema.$schema;
|
|
106
|
+
}, "operation"> & {
|
|
107
|
+
operation: v.Type<"delete">;
|
|
108
|
+
}, undefined>;
|
|
109
|
+
export declare const deleteCommitSchema: deleteCommitSchema.$schema;
|
|
110
|
+
export interface DeleteCommit extends v.Infer<typeof deleteCommitSchema> {
|
|
111
|
+
}
|
|
112
|
+
export declare namespace deleteCommitSchema {
|
|
113
|
+
export {};
|
|
114
|
+
type $schematype = typeof _deleteCommitSchema;
|
|
115
|
+
export interface $schema extends $schematype {
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
declare const _commitOperationSchema: v.UnionType<[createCommitSchema.$schema, updateCommitSchema.$schema, deleteCommitSchema.$schema]>;
|
|
119
|
+
export declare const commitOperationSchema: commitSchema.$schema;
|
|
120
|
+
export type CommitOperation = v.Infer<typeof commitOperationSchema>;
|
|
121
|
+
export declare namespace commitSchema {
|
|
122
|
+
export {};
|
|
123
|
+
type $schematype = typeof _commitOperationSchema;
|
|
124
|
+
export interface $schema extends $schematype {
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
declare const _commitEventSchema: v.ObjectType<Omit<{
|
|
128
|
+
did: didStringSchema.$schema;
|
|
129
|
+
time_us: integerSchema.$schema;
|
|
130
|
+
}, "kind" | "commit"> & {
|
|
131
|
+
kind: v.Type<"commit">;
|
|
132
|
+
commit: commitSchema.$schema;
|
|
133
|
+
}, undefined>;
|
|
134
|
+
export declare const commitEventSchema: commitEventSchema.$schema;
|
|
135
|
+
export interface CommitEvent extends v.Infer<typeof commitEventSchema> {
|
|
136
|
+
}
|
|
137
|
+
export declare namespace commitEventSchema {
|
|
138
|
+
export {};
|
|
139
|
+
type $schematype = typeof _commitEventSchema;
|
|
140
|
+
export interface $schema extends $schematype {
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
declare const _identityDataSchema: v.ObjectType<{
|
|
144
|
+
did: didStringSchema.$schema;
|
|
145
|
+
handle: handleStringSchema.$schema;
|
|
146
|
+
seq: integerSchema.$schema;
|
|
147
|
+
time: datetimeStringSchema.$schema;
|
|
148
|
+
}, undefined>;
|
|
149
|
+
export declare const identityDataSchema: identityData.$schema;
|
|
150
|
+
export interface IdentityData extends v.Infer<typeof identityDataSchema> {
|
|
151
|
+
}
|
|
152
|
+
export declare namespace identityData {
|
|
153
|
+
export {};
|
|
154
|
+
type $schematype = typeof _identityDataSchema;
|
|
155
|
+
export interface $schema extends $schematype {
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
declare const _identityEventSchema: v.ObjectType<Omit<{
|
|
159
|
+
did: didStringSchema.$schema;
|
|
160
|
+
time_us: integerSchema.$schema;
|
|
161
|
+
}, "kind" | "identity"> & {
|
|
162
|
+
kind: v.Type<"identity">;
|
|
163
|
+
identity: identityData.$schema;
|
|
164
|
+
}, undefined>;
|
|
165
|
+
export declare const identityEventSchema: identityEventSchema.$schema;
|
|
166
|
+
export interface IdentityEvent extends v.Infer<typeof identityEventSchema> {
|
|
167
|
+
}
|
|
168
|
+
export declare namespace identityEventSchema {
|
|
169
|
+
export {};
|
|
170
|
+
type $schematype = typeof _identityEventSchema;
|
|
171
|
+
export interface $schema extends $schematype {
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
declare const _accountDataSchema: v.ObjectType<{
|
|
175
|
+
did: didStringSchema.$schema;
|
|
176
|
+
active: v.Type<boolean>;
|
|
177
|
+
seq: integerSchema.$schema;
|
|
178
|
+
time: datetimeStringSchema.$schema;
|
|
179
|
+
}, undefined>;
|
|
180
|
+
export declare const accountDataSchema: accountDataSchema.$schema;
|
|
181
|
+
export interface AccountData extends v.Infer<typeof accountDataSchema> {
|
|
182
|
+
}
|
|
183
|
+
export declare namespace accountDataSchema {
|
|
184
|
+
export {};
|
|
185
|
+
type $schematype = typeof _accountDataSchema;
|
|
186
|
+
export interface $schema extends $schematype {
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
declare const _accountEventSchema: v.ObjectType<Omit<{
|
|
190
|
+
did: didStringSchema.$schema;
|
|
191
|
+
time_us: integerSchema.$schema;
|
|
192
|
+
}, "kind" | "account"> & {
|
|
193
|
+
kind: v.Type<"account">;
|
|
194
|
+
account: accountDataSchema.$schema;
|
|
195
|
+
}, undefined>;
|
|
196
|
+
export declare const accountEventSchema: accountEventSchema.$schema;
|
|
197
|
+
export interface AccountEvent extends v.Infer<typeof accountEventSchema> {
|
|
198
|
+
}
|
|
199
|
+
export declare namespace accountEventSchema {
|
|
200
|
+
export {};
|
|
201
|
+
type $schematype = typeof _accountEventSchema;
|
|
202
|
+
export interface $schema extends $schematype {
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
declare const _jetstreamEventSchema: v.UnionType<[commitEventSchema.$schema, identityEventSchema.$schema, accountEventSchema.$schema]>;
|
|
206
|
+
export declare const jetstreamEventSchema: jetstreamEventSchema.$schema;
|
|
207
|
+
export type JetstreamEvent = v.Infer<typeof jetstreamEventSchema>;
|
|
208
|
+
export declare namespace jetstreamEventSchema {
|
|
209
|
+
export {};
|
|
210
|
+
type $schematype = typeof _jetstreamEventSchema;
|
|
211
|
+
export interface $schema extends $schematype {
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
declare const _optionsUpdatePayloadSchema: v.ObjectType<{
|
|
215
|
+
wantedCollections: v.Optional<string[]>;
|
|
216
|
+
wantedDids: v.Optional<`did:${string}:${string}`[]>;
|
|
217
|
+
maxMessageSizeBytes: v.Optional<number>;
|
|
218
|
+
}, undefined>;
|
|
219
|
+
export declare const optionsUpdatePayloadSchema: optionsUpdatePayloadSchema.$schema;
|
|
220
|
+
export interface OptionsUpdatePayload extends v.Infer<typeof optionsUpdatePayloadSchema> {
|
|
221
|
+
}
|
|
222
|
+
export declare namespace optionsUpdatePayloadSchema {
|
|
223
|
+
export {};
|
|
224
|
+
type $schematype = typeof _optionsUpdatePayloadSchema;
|
|
225
|
+
export interface $schema extends $schematype {
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
declare const _optionsUpdateProcedureSchema: v.ObjectType<{
|
|
229
|
+
type: v.Type<"options_update">;
|
|
230
|
+
payload: optionsUpdatePayloadSchema.$schema;
|
|
231
|
+
}, undefined>;
|
|
232
|
+
export declare const optionsUpdateProcedureSchema: optionsUpdateProcedureSchema.$schema;
|
|
233
|
+
export interface OptionsUpdateProcedure extends v.Infer<typeof optionsUpdateProcedureSchema> {
|
|
234
|
+
}
|
|
235
|
+
export declare namespace optionsUpdateProcedureSchema {
|
|
236
|
+
export {};
|
|
237
|
+
type $schematype = typeof _optionsUpdateProcedureSchema;
|
|
238
|
+
export interface $schema extends $schematype {
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
declare const _jetstreamProcedureSchema: v.UnionType<[optionsUpdateProcedureSchema.$schema]>;
|
|
242
|
+
export declare const jetstreamProcedureSchema: jetstreamProcedureSchema.$schema;
|
|
243
|
+
export type JetstreamProcedure = v.Infer<typeof jetstreamProcedureSchema>;
|
|
244
|
+
export declare namespace jetstreamProcedureSchema {
|
|
245
|
+
export {};
|
|
246
|
+
type $schematype = typeof _jetstreamProcedureSchema;
|
|
247
|
+
export interface $schema extends $schematype {
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as syntax from '@atcute/lexicons/syntax';
|
|
2
|
+
import * as v from '@badrap/valita';
|
|
3
|
+
const _cidStringSchema = v.string();
|
|
4
|
+
const cidStringSchema = _cidStringSchema;
|
|
5
|
+
const _datetimeStringSchema = v.string().assert(syntax.isDatetime, `must be a datetime`);
|
|
6
|
+
const datetimeStringSchema = _datetimeStringSchema;
|
|
7
|
+
const _didStringSchema = v.string().assert(syntax.isDid, `must be a did`);
|
|
8
|
+
const didStringSchema = _didStringSchema;
|
|
9
|
+
const _handleStringSchema = v.string().assert(syntax.isHandle, `must be a handle`);
|
|
10
|
+
const handleStringSchema = _handleStringSchema;
|
|
11
|
+
const _nsidStringSchema = v.string().assert(syntax.isNsid, `must be an nsid`);
|
|
12
|
+
const nsidStringSchema = _nsidStringSchema;
|
|
13
|
+
const _rkeyStringSchema = v.string().assert(syntax.isRecordKey, `must be a rkey`);
|
|
14
|
+
const rkeyStringSchema = _rkeyStringSchema;
|
|
15
|
+
const _tidStringSchema = v.string().assert(syntax.isTid, `must be a tid`);
|
|
16
|
+
const tidStringSchema = _tidStringSchema;
|
|
17
|
+
const _integerSchema = v
|
|
18
|
+
.number()
|
|
19
|
+
.assert((input) => input >= 0 && Number.isSafeInteger(input), `must be a nonnegative integer`);
|
|
20
|
+
const integerSchema = _integerSchema;
|
|
21
|
+
const _baseCommitSchema = v.object({
|
|
22
|
+
rev: tidStringSchema,
|
|
23
|
+
collection: nsidStringSchema,
|
|
24
|
+
rkey: rkeyStringSchema,
|
|
25
|
+
});
|
|
26
|
+
const baseCommitSchema = _baseCommitSchema;
|
|
27
|
+
const _createCommitSchema = baseCommitSchema.extend({
|
|
28
|
+
operation: v.literal('create'),
|
|
29
|
+
cid: cidStringSchema,
|
|
30
|
+
record: v.record(v.unknown()),
|
|
31
|
+
});
|
|
32
|
+
export const createCommitSchema = _createCommitSchema;
|
|
33
|
+
const _updateCommitSchema = baseCommitSchema.extend({
|
|
34
|
+
operation: v.literal('update'),
|
|
35
|
+
cid: cidStringSchema,
|
|
36
|
+
record: v.record(v.unknown()),
|
|
37
|
+
});
|
|
38
|
+
export const updateCommitSchema = _updateCommitSchema;
|
|
39
|
+
const _deleteCommitSchema = baseCommitSchema.extend({
|
|
40
|
+
operation: v.literal('delete'),
|
|
41
|
+
});
|
|
42
|
+
export const deleteCommitSchema = _deleteCommitSchema;
|
|
43
|
+
const _commitOperationSchema = v.union(createCommitSchema, updateCommitSchema, deleteCommitSchema);
|
|
44
|
+
export const commitOperationSchema = _commitOperationSchema;
|
|
45
|
+
const _baseEventSchema = v.object({
|
|
46
|
+
did: didStringSchema,
|
|
47
|
+
time_us: integerSchema,
|
|
48
|
+
});
|
|
49
|
+
const baseEventSchema = _baseEventSchema;
|
|
50
|
+
const _commitEventSchema = baseEventSchema.extend({
|
|
51
|
+
kind: v.literal('commit'),
|
|
52
|
+
commit: commitOperationSchema,
|
|
53
|
+
});
|
|
54
|
+
export const commitEventSchema = _commitEventSchema;
|
|
55
|
+
const _identityDataSchema = v.object({
|
|
56
|
+
did: didStringSchema,
|
|
57
|
+
handle: handleStringSchema,
|
|
58
|
+
seq: integerSchema,
|
|
59
|
+
time: datetimeStringSchema,
|
|
60
|
+
});
|
|
61
|
+
export const identityDataSchema = _identityDataSchema;
|
|
62
|
+
const _identityEventSchema = baseEventSchema.extend({
|
|
63
|
+
kind: v.literal('identity'),
|
|
64
|
+
identity: identityDataSchema,
|
|
65
|
+
});
|
|
66
|
+
export const identityEventSchema = _identityEventSchema;
|
|
67
|
+
const _accountDataSchema = v.object({
|
|
68
|
+
did: didStringSchema,
|
|
69
|
+
active: v.boolean(),
|
|
70
|
+
seq: integerSchema,
|
|
71
|
+
time: datetimeStringSchema,
|
|
72
|
+
});
|
|
73
|
+
export const accountDataSchema = _accountDataSchema;
|
|
74
|
+
const _accountEventSchema = baseEventSchema.extend({
|
|
75
|
+
kind: v.literal('account'),
|
|
76
|
+
account: accountDataSchema,
|
|
77
|
+
});
|
|
78
|
+
export const accountEventSchema = _accountEventSchema;
|
|
79
|
+
const _jetstreamEventSchema = v.union(commitEventSchema, identityEventSchema, accountEventSchema);
|
|
80
|
+
export const jetstreamEventSchema = _jetstreamEventSchema;
|
|
81
|
+
const _optionsUpdatePayloadSchema = v.object({
|
|
82
|
+
wantedCollections: v.array(v.string()).optional(),
|
|
83
|
+
wantedDids: v.array(didStringSchema).optional(),
|
|
84
|
+
maxMessageSizeBytes: integerSchema.optional(),
|
|
85
|
+
});
|
|
86
|
+
export const optionsUpdatePayloadSchema = _optionsUpdatePayloadSchema;
|
|
87
|
+
const _optionsUpdateProcedureSchema = v.object({
|
|
88
|
+
type: v.literal('options_update'),
|
|
89
|
+
payload: optionsUpdatePayloadSchema,
|
|
90
|
+
});
|
|
91
|
+
export const optionsUpdateProcedureSchema = _optionsUpdateProcedureSchema;
|
|
92
|
+
const _jetstreamProcedureSchema = v.union(optionsUpdateProcedureSchema);
|
|
93
|
+
export const jetstreamProcedureSchema = _jetstreamProcedureSchema;
|
|
94
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,yBAAyB,CAAC;AAElD,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AAEpC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;AAEpC,MAAM,eAAe,GAAG,gBAA2C,CAAC;AAOpE,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC;AAEzF,MAAM,oBAAoB,GAAG,qBAAqD,CAAC;AAOnF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;AAE1E,MAAM,eAAe,GAAG,gBAA2C,CAAC;AAOpE,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AAEnF,MAAM,kBAAkB,GAAG,mBAAiD,CAAC;AAO7E,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAE9E,MAAM,gBAAgB,GAAG,iBAA6C,CAAC;AAOvE,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;AAElF,MAAM,gBAAgB,GAAG,iBAA6C,CAAC;AAOvE,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC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AAC,MAAM,CAAC;IAClD,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAC1B,OAAO,EAAE,iBAAiB;CAC1B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,mBAAiD,CAAC;AASpF,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,iBAAiB,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;AAElG,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAqD,CAAC;AAS1F,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,iBAAiB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACjD,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,QAAQ,EAAE;IAC/C,mBAAmB,EAAE,aAAa,CAAC,QAAQ,EAAE;CAC7C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG,2BAAiE,CAAC;AAS5G,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACjC,OAAO,EAAE,0BAA0B;CACnC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,4BAA4B,GACxC,6BAAqE,CAAC;AASvE,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,wBAAwB,GAAG,yBAA6D,CAAC"}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { Did } from '@atcute/lexicons';
|
|
2
|
+
|
|
3
|
+
import { EventIterator } from '@mary-ext/event-iterator';
|
|
4
|
+
import { SimpleEventEmitter } from '@mary-ext/simple-event-emitter';
|
|
5
|
+
|
|
6
|
+
import { WebSocket as ReconnectingWebSocket } from 'partysocket';
|
|
7
|
+
import type { CloseEvent, ErrorEvent, Options } from 'partysocket/ws';
|
|
8
|
+
|
|
9
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
10
|
+
|
|
11
|
+
import { jetstreamEventSchema, type JetstreamEvent, type JetstreamProcedure } from './types.js';
|
|
12
|
+
|
|
13
|
+
export interface JetstreamSubscriptionOptions {
|
|
14
|
+
url: string;
|
|
15
|
+
|
|
16
|
+
cursor?: number;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Array of collection NSIDs that you're interested in receiving commit events
|
|
20
|
+
* for, pass in an empty array for no commit events.
|
|
21
|
+
*/
|
|
22
|
+
wantedCollections?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Array of account DIDs that you're interested in receiving commit events
|
|
25
|
+
* for, pass in an empty array for no commit events.
|
|
26
|
+
*/
|
|
27
|
+
wantedDids?: Did[];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether to validate Jetstream's events, you'd still need to validate the records.
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
validateEvents?: boolean;
|
|
34
|
+
|
|
35
|
+
onConnectionOpen?: (event: Event) => void;
|
|
36
|
+
onConnectionClose?: (event: CloseEvent) => void;
|
|
37
|
+
onConnectionError?: (event: ErrorEvent) => void;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* WebSocket connection options
|
|
41
|
+
*/
|
|
42
|
+
ws?: Options;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const PARSE_OPTIONS = { mode: 'passthrough' } as const;
|
|
46
|
+
|
|
47
|
+
export class JetstreamSubscription {
|
|
48
|
+
#listening = 0;
|
|
49
|
+
#ws?: ReconnectingWebSocket;
|
|
50
|
+
|
|
51
|
+
#emitter = new SimpleEventEmitter<[event: JetstreamEvent]>();
|
|
52
|
+
|
|
53
|
+
#options: JetstreamSubscriptionOptions;
|
|
54
|
+
#cursor: number;
|
|
55
|
+
|
|
56
|
+
constructor(options: JetstreamSubscriptionOptions) {
|
|
57
|
+
this.#options = options;
|
|
58
|
+
this.#cursor = options.cursor ?? Date.now() * 1_000;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#sendOptionsUpdate() {
|
|
62
|
+
const ws = this.#ws;
|
|
63
|
+
if (ws === undefined) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const payload: JetstreamProcedure = {
|
|
68
|
+
type: 'options_update',
|
|
69
|
+
payload: {
|
|
70
|
+
wantedCollections: this.#options.wantedCollections,
|
|
71
|
+
wantedDids: this.#options.wantedDids,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
ws.send(JSON.stringify(payload));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#create() {
|
|
79
|
+
if (this.#ws !== undefined) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const {
|
|
84
|
+
url: wsUrl,
|
|
85
|
+
ws: wsOptions,
|
|
86
|
+
validateEvents = true,
|
|
87
|
+
onConnectionClose,
|
|
88
|
+
onConnectionError,
|
|
89
|
+
onConnectionOpen,
|
|
90
|
+
} = this.#options;
|
|
91
|
+
const emitter = this.#emitter;
|
|
92
|
+
|
|
93
|
+
const getUrl = () => {
|
|
94
|
+
const url = new URL('/subscribe', wsUrl);
|
|
95
|
+
url.searchParams.set('requireHello', 'true');
|
|
96
|
+
url.searchParams.set('cursor', '' + this.#cursor);
|
|
97
|
+
|
|
98
|
+
return url.toString();
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const ws = new ReconnectingWebSocket(getUrl, null, wsOptions);
|
|
102
|
+
this.#ws = ws;
|
|
103
|
+
|
|
104
|
+
ws.binaryType = 'arraybuffer';
|
|
105
|
+
|
|
106
|
+
ws.onerror = onConnectionError ?? null;
|
|
107
|
+
ws.onclose = onConnectionClose ?? null;
|
|
108
|
+
|
|
109
|
+
ws.onopen = (ev) => {
|
|
110
|
+
this.#sendOptionsUpdate();
|
|
111
|
+
onConnectionOpen?.(ev);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
ws.onmessage = (ev) => {
|
|
115
|
+
const raw = JSON.parse(ev.data);
|
|
116
|
+
|
|
117
|
+
let event: JetstreamEvent;
|
|
118
|
+
if (validateEvents) {
|
|
119
|
+
const result = jetstreamEventSchema.try(raw, PARSE_OPTIONS);
|
|
120
|
+
if (!result.ok) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
event = result.value;
|
|
125
|
+
} else {
|
|
126
|
+
event = raw;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.#cursor = event.time_us;
|
|
130
|
+
emitter.emit(event);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#destroy() {
|
|
135
|
+
const ws = this.#ws;
|
|
136
|
+
if (ws === undefined) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
ws.close();
|
|
141
|
+
|
|
142
|
+
this.#ws = undefined;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
[Symbol.asyncIterator]() {
|
|
146
|
+
return new EventIterator<JetstreamEvent>((emit) => {
|
|
147
|
+
if (this.#listening === 0) {
|
|
148
|
+
this.#create();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this.#listening++;
|
|
152
|
+
this.#emitter.subscribe(emit);
|
|
153
|
+
|
|
154
|
+
return () => {
|
|
155
|
+
if (this.#listening === 1) {
|
|
156
|
+
this.#destroy();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
this.#listening--;
|
|
160
|
+
this.#emitter.unsubscribe(emit);
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
get cursor() {
|
|
166
|
+
return this.#cursor;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
getOptions(): ReadonlyDeep<JetstreamSubscriptionOptions> {
|
|
170
|
+
return this.#options;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
updateOptions(options: Partial<JetstreamSubscriptionOptions>): void {
|
|
174
|
+
this.#options = { ...this.#options, ...options };
|
|
175
|
+
if (options.cursor !== undefined) {
|
|
176
|
+
this.#cursor = options.cursor;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (this.#ws !== undefined) {
|
|
180
|
+
const isOptionsUpdate = Object.keys(options).every((key) => {
|
|
181
|
+
return key === 'wantedCollections' || key === 'wantedDids';
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
if (isOptionsUpdate) {
|
|
185
|
+
this.#sendOptionsUpdate();
|
|
186
|
+
} else {
|
|
187
|
+
this.#destroy();
|
|
188
|
+
this.#create();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
package/lib/types.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import * as syntax from '@atcute/lexicons/syntax';
|
|
2
|
+
|
|
3
|
+
import * as v from '@badrap/valita';
|
|
4
|
+
|
|
5
|
+
const _cidStringSchema = v.string();
|
|
6
|
+
|
|
7
|
+
const cidStringSchema = _cidStringSchema as cidStringSchema.$schema;
|
|
8
|
+
declare namespace cidStringSchema {
|
|
9
|
+
export {};
|
|
10
|
+
|
|
11
|
+
type $schematype = typeof _cidStringSchema;
|
|
12
|
+
export interface $schema extends $schematype {}
|
|
13
|
+
}
|
|
14
|
+
const _datetimeStringSchema = v.string().assert(syntax.isDatetime, `must be a datetime`);
|
|
15
|
+
|
|
16
|
+
const datetimeStringSchema = _datetimeStringSchema as datetimeStringSchema.$schema;
|
|
17
|
+
declare namespace datetimeStringSchema {
|
|
18
|
+
export {};
|
|
19
|
+
|
|
20
|
+
type $schematype = typeof _datetimeStringSchema;
|
|
21
|
+
export interface $schema extends $schematype {}
|
|
22
|
+
}
|
|
23
|
+
const _didStringSchema = v.string().assert(syntax.isDid, `must be a did`);
|
|
24
|
+
|
|
25
|
+
const didStringSchema = _didStringSchema as didStringSchema.$schema;
|
|
26
|
+
declare namespace didStringSchema {
|
|
27
|
+
export {};
|
|
28
|
+
|
|
29
|
+
type $schematype = typeof _didStringSchema;
|
|
30
|
+
export interface $schema extends $schematype {}
|
|
31
|
+
}
|
|
32
|
+
const _handleStringSchema = v.string().assert(syntax.isHandle, `must be a handle`);
|
|
33
|
+
|
|
34
|
+
const handleStringSchema = _handleStringSchema as handleStringSchema.$schema;
|
|
35
|
+
declare namespace handleStringSchema {
|
|
36
|
+
export {};
|
|
37
|
+
|
|
38
|
+
type $schematype = typeof _handleStringSchema;
|
|
39
|
+
export interface $schema extends $schematype {}
|
|
40
|
+
}
|
|
41
|
+
const _nsidStringSchema = v.string().assert(syntax.isNsid, `must be an nsid`);
|
|
42
|
+
|
|
43
|
+
const nsidStringSchema = _nsidStringSchema as nsidStringSchema.$schema;
|
|
44
|
+
declare namespace nsidStringSchema {
|
|
45
|
+
export {};
|
|
46
|
+
|
|
47
|
+
type $schematype = typeof _nsidStringSchema;
|
|
48
|
+
export interface $schema extends $schematype {}
|
|
49
|
+
}
|
|
50
|
+
const _rkeyStringSchema = v.string().assert(syntax.isRecordKey, `must be a rkey`);
|
|
51
|
+
|
|
52
|
+
const rkeyStringSchema = _rkeyStringSchema as rkeyStringSchema.$schema;
|
|
53
|
+
declare namespace rkeyStringSchema {
|
|
54
|
+
export {};
|
|
55
|
+
|
|
56
|
+
type $schematype = typeof _rkeyStringSchema;
|
|
57
|
+
export interface $schema extends $schematype {}
|
|
58
|
+
}
|
|
59
|
+
const _tidStringSchema = v.string().assert(syntax.isTid, `must be a tid`);
|
|
60
|
+
|
|
61
|
+
const tidStringSchema = _tidStringSchema as tidStringSchema.$schema;
|
|
62
|
+
declare namespace tidStringSchema {
|
|
63
|
+
export {};
|
|
64
|
+
|
|
65
|
+
type $schematype = typeof _tidStringSchema;
|
|
66
|
+
export interface $schema extends $schematype {}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const _integerSchema = v
|
|
70
|
+
.number()
|
|
71
|
+
.assert((input) => input >= 0 && Number.isSafeInteger(input), `must be a nonnegative integer`);
|
|
72
|
+
|
|
73
|
+
const integerSchema = _integerSchema as integerSchema.$schema;
|
|
74
|
+
declare namespace integerSchema {
|
|
75
|
+
export {};
|
|
76
|
+
|
|
77
|
+
type $schematype = typeof _integerSchema;
|
|
78
|
+
export interface $schema extends $schematype {}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const _baseCommitSchema = v.object({
|
|
82
|
+
rev: tidStringSchema,
|
|
83
|
+
collection: nsidStringSchema,
|
|
84
|
+
rkey: rkeyStringSchema,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const baseCommitSchema = _baseCommitSchema as baseCommitSchema.$schema;
|
|
88
|
+
declare namespace baseCommitSchema {
|
|
89
|
+
export {};
|
|
90
|
+
|
|
91
|
+
type $schematype = typeof _baseCommitSchema;
|
|
92
|
+
export interface $schema extends $schematype {}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const _createCommitSchema = baseCommitSchema.extend({
|
|
96
|
+
operation: v.literal('create'),
|
|
97
|
+
cid: cidStringSchema,
|
|
98
|
+
record: v.record(v.unknown()),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export const createCommitSchema = _createCommitSchema as createCommitSchema.$schema;
|
|
102
|
+
export interface CreateCommit extends v.Infer<typeof createCommitSchema> {}
|
|
103
|
+
export declare namespace createCommitSchema {
|
|
104
|
+
export {};
|
|
105
|
+
|
|
106
|
+
type $schematype = typeof _createCommitSchema;
|
|
107
|
+
export interface $schema extends $schematype {}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const _updateCommitSchema = baseCommitSchema.extend({
|
|
111
|
+
operation: v.literal('update'),
|
|
112
|
+
cid: cidStringSchema,
|
|
113
|
+
record: v.record(v.unknown()),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export const updateCommitSchema = _updateCommitSchema as updateCommitSchema.$schema;
|
|
117
|
+
export interface UpdateCommit extends v.Infer<typeof updateCommitSchema> {}
|
|
118
|
+
export declare namespace updateCommitSchema {
|
|
119
|
+
export {};
|
|
120
|
+
|
|
121
|
+
type $schematype = typeof _updateCommitSchema;
|
|
122
|
+
export interface $schema extends $schematype {}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const _deleteCommitSchema = baseCommitSchema.extend({
|
|
126
|
+
operation: v.literal('delete'),
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export const deleteCommitSchema = _deleteCommitSchema as deleteCommitSchema.$schema;
|
|
130
|
+
export interface DeleteCommit extends v.Infer<typeof deleteCommitSchema> {}
|
|
131
|
+
export declare namespace deleteCommitSchema {
|
|
132
|
+
export {};
|
|
133
|
+
|
|
134
|
+
type $schematype = typeof _deleteCommitSchema;
|
|
135
|
+
export interface $schema extends $schematype {}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const _commitOperationSchema = v.union(createCommitSchema, updateCommitSchema, deleteCommitSchema);
|
|
139
|
+
|
|
140
|
+
export const commitOperationSchema = _commitOperationSchema as commitSchema.$schema;
|
|
141
|
+
export type CommitOperation = v.Infer<typeof commitOperationSchema>;
|
|
142
|
+
export declare namespace commitSchema {
|
|
143
|
+
export {};
|
|
144
|
+
|
|
145
|
+
type $schematype = typeof _commitOperationSchema;
|
|
146
|
+
export interface $schema extends $schematype {}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const _baseEventSchema = v.object({
|
|
150
|
+
did: didStringSchema,
|
|
151
|
+
time_us: integerSchema,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const baseEventSchema = _baseEventSchema as baseEventSchema.$schema;
|
|
155
|
+
declare namespace baseEventSchema {
|
|
156
|
+
export {};
|
|
157
|
+
|
|
158
|
+
type $schematype = typeof _baseEventSchema;
|
|
159
|
+
export interface $schema extends $schematype {}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const _commitEventSchema = baseEventSchema.extend({
|
|
163
|
+
kind: v.literal('commit'),
|
|
164
|
+
commit: commitOperationSchema,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export const commitEventSchema = _commitEventSchema as commitEventSchema.$schema;
|
|
168
|
+
export interface CommitEvent extends v.Infer<typeof commitEventSchema> {}
|
|
169
|
+
export declare namespace commitEventSchema {
|
|
170
|
+
export {};
|
|
171
|
+
|
|
172
|
+
type $schematype = typeof _commitEventSchema;
|
|
173
|
+
export interface $schema extends $schematype {}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const _identityDataSchema = v.object({
|
|
177
|
+
did: didStringSchema,
|
|
178
|
+
handle: handleStringSchema,
|
|
179
|
+
seq: integerSchema,
|
|
180
|
+
time: datetimeStringSchema,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
export const identityDataSchema = _identityDataSchema as identityData.$schema;
|
|
184
|
+
export interface IdentityData extends v.Infer<typeof identityDataSchema> {}
|
|
185
|
+
export declare namespace identityData {
|
|
186
|
+
export {};
|
|
187
|
+
|
|
188
|
+
type $schematype = typeof _identityDataSchema;
|
|
189
|
+
export interface $schema extends $schematype {}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const _identityEventSchema = baseEventSchema.extend({
|
|
193
|
+
kind: v.literal('identity'),
|
|
194
|
+
identity: identityDataSchema,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
export const identityEventSchema = _identityEventSchema as identityEventSchema.$schema;
|
|
198
|
+
export interface IdentityEvent extends v.Infer<typeof identityEventSchema> {}
|
|
199
|
+
export declare namespace identityEventSchema {
|
|
200
|
+
export {};
|
|
201
|
+
|
|
202
|
+
type $schematype = typeof _identityEventSchema;
|
|
203
|
+
export interface $schema extends $schematype {}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const _accountDataSchema = v.object({
|
|
207
|
+
did: didStringSchema,
|
|
208
|
+
active: v.boolean(),
|
|
209
|
+
seq: integerSchema,
|
|
210
|
+
time: datetimeStringSchema,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
export const accountDataSchema = _accountDataSchema as accountDataSchema.$schema;
|
|
214
|
+
export interface AccountData extends v.Infer<typeof accountDataSchema> {}
|
|
215
|
+
export declare namespace accountDataSchema {
|
|
216
|
+
export {};
|
|
217
|
+
|
|
218
|
+
type $schematype = typeof _accountDataSchema;
|
|
219
|
+
export interface $schema extends $schematype {}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const _accountEventSchema = baseEventSchema.extend({
|
|
223
|
+
kind: v.literal('account'),
|
|
224
|
+
account: accountDataSchema,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
export const accountEventSchema = _accountEventSchema as accountEventSchema.$schema;
|
|
228
|
+
export interface AccountEvent extends v.Infer<typeof accountEventSchema> {}
|
|
229
|
+
export declare namespace accountEventSchema {
|
|
230
|
+
export {};
|
|
231
|
+
|
|
232
|
+
type $schematype = typeof _accountEventSchema;
|
|
233
|
+
export interface $schema extends $schematype {}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const _jetstreamEventSchema = v.union(commitEventSchema, identityEventSchema, accountEventSchema);
|
|
237
|
+
|
|
238
|
+
export const jetstreamEventSchema = _jetstreamEventSchema as jetstreamEventSchema.$schema;
|
|
239
|
+
export type JetstreamEvent = v.Infer<typeof jetstreamEventSchema>;
|
|
240
|
+
export declare namespace jetstreamEventSchema {
|
|
241
|
+
export {};
|
|
242
|
+
|
|
243
|
+
type $schematype = typeof _jetstreamEventSchema;
|
|
244
|
+
export interface $schema extends $schematype {}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const _optionsUpdatePayloadSchema = v.object({
|
|
248
|
+
wantedCollections: v.array(v.string()).optional(),
|
|
249
|
+
wantedDids: v.array(didStringSchema).optional(),
|
|
250
|
+
maxMessageSizeBytes: integerSchema.optional(),
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
export const optionsUpdatePayloadSchema = _optionsUpdatePayloadSchema as optionsUpdatePayloadSchema.$schema;
|
|
254
|
+
export interface OptionsUpdatePayload extends v.Infer<typeof optionsUpdatePayloadSchema> {}
|
|
255
|
+
export declare namespace optionsUpdatePayloadSchema {
|
|
256
|
+
export {};
|
|
257
|
+
|
|
258
|
+
type $schematype = typeof _optionsUpdatePayloadSchema;
|
|
259
|
+
export interface $schema extends $schematype {}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const _optionsUpdateProcedureSchema = v.object({
|
|
263
|
+
type: v.literal('options_update'),
|
|
264
|
+
payload: optionsUpdatePayloadSchema,
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
export const optionsUpdateProcedureSchema =
|
|
268
|
+
_optionsUpdateProcedureSchema as optionsUpdateProcedureSchema.$schema;
|
|
269
|
+
export interface OptionsUpdateProcedure extends v.Infer<typeof optionsUpdateProcedureSchema> {}
|
|
270
|
+
export declare namespace optionsUpdateProcedureSchema {
|
|
271
|
+
export {};
|
|
272
|
+
|
|
273
|
+
type $schematype = typeof _optionsUpdateProcedureSchema;
|
|
274
|
+
export interface $schema extends $schematype {}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const _jetstreamProcedureSchema = v.union(optionsUpdateProcedureSchema);
|
|
278
|
+
|
|
279
|
+
export const jetstreamProcedureSchema = _jetstreamProcedureSchema as jetstreamProcedureSchema.$schema;
|
|
280
|
+
export type JetstreamProcedure = v.Infer<typeof jetstreamProcedureSchema>;
|
|
281
|
+
export declare namespace jetstreamProcedureSchema {
|
|
282
|
+
export {};
|
|
283
|
+
|
|
284
|
+
type $schematype = typeof _jetstreamProcedureSchema;
|
|
285
|
+
export interface $schema extends $schematype {}
|
|
286
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@atcute/jetstream",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "lightweight and cute Jetstream subscriber for AT Protocol",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"url": "https://github.com/mary-ext/atcute",
|
|
9
|
+
"directory": "packages/core/jetstream"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/",
|
|
13
|
+
"lib/",
|
|
14
|
+
"!lib/**/*.bench.ts",
|
|
15
|
+
"!lib/**/*.test.ts"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@badrap/valita": "^0.4.2",
|
|
22
|
+
"@mary-ext/event-iterator": "^1.0.0",
|
|
23
|
+
"@mary-ext/simple-event-emitter": "^1.0.0",
|
|
24
|
+
"partysocket": "^1.1.4",
|
|
25
|
+
"type-fest": "^4.41.0",
|
|
26
|
+
"yocto-queue": "^1.2.1",
|
|
27
|
+
"@atcute/lexicons": "^1.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@vitest/coverage-v8": "^3.0.4",
|
|
31
|
+
"vitest": "^3.0.4"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc --project tsconfig.build.json",
|
|
35
|
+
"test": "vitest run --coverage",
|
|
36
|
+
"prepublish": "rm -rf dist; pnpm run build"
|
|
37
|
+
}
|
|
38
|
+
}
|