@atproto/sync 0.1.40 → 0.2.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/events.d.ts +12 -13
  3. package/dist/events.d.ts.map +1 -1
  4. package/dist/events.js.map +1 -1
  5. package/dist/firehose/index.d.ts +8 -8
  6. package/dist/firehose/index.d.ts.map +1 -1
  7. package/dist/firehose/index.js +23 -13
  8. package/dist/firehose/index.js.map +1 -1
  9. package/dist/lexicons/com/atproto/sync/subscribeRepos.d.ts +3 -0
  10. package/dist/lexicons/com/atproto/sync/subscribeRepos.d.ts.map +1 -0
  11. package/dist/lexicons/com/atproto/sync/subscribeRepos.defs.d.ts +152 -0
  12. package/dist/lexicons/com/atproto/sync/subscribeRepos.defs.d.ts.map +1 -0
  13. package/dist/lexicons/com/atproto/sync/subscribeRepos.defs.js +75 -0
  14. package/dist/lexicons/com/atproto/sync/subscribeRepos.defs.js.map +1 -0
  15. package/dist/lexicons/com/atproto/sync/subscribeRepos.js +45 -0
  16. package/dist/lexicons/com/atproto/sync/subscribeRepos.js.map +1 -0
  17. package/dist/lexicons/com/atproto/sync.d.ts +2 -0
  18. package/dist/lexicons/com/atproto/sync.d.ts.map +1 -0
  19. package/dist/lexicons/com/atproto/sync.js +41 -0
  20. package/dist/lexicons/com/atproto/sync.js.map +1 -0
  21. package/dist/lexicons/com/atproto.d.ts +2 -0
  22. package/dist/lexicons/com/atproto.d.ts.map +1 -0
  23. package/dist/lexicons/com/atproto.js +41 -0
  24. package/dist/lexicons/com/atproto.js.map +1 -0
  25. package/dist/lexicons/com.d.ts +2 -0
  26. package/dist/lexicons/com.d.ts.map +1 -0
  27. package/dist/lexicons/com.js +41 -0
  28. package/dist/lexicons/com.js.map +1 -0
  29. package/dist/lexicons/index.d.ts +2 -0
  30. package/dist/lexicons/index.d.ts.map +1 -0
  31. package/dist/lexicons/index.js +41 -0
  32. package/dist/lexicons/index.js.map +1 -0
  33. package/dist/util.d.ts +2 -2
  34. package/dist/util.d.ts.map +1 -1
  35. package/dist/util.js +7 -3
  36. package/dist/util.js.map +1 -1
  37. package/package.json +8 -7
  38. package/src/events.ts +12 -13
  39. package/src/firehose/index.ts +53 -45
  40. package/src/util.ts +10 -10
  41. package/tests/firehose.test.ts +11 -8
  42. package/tests/runner.test.ts +1 -1
  43. package/tsconfig.build.tsbuildinfo +1 -1
  44. package/tsconfig.json +4 -1
  45. package/tsconfig.tests.json +8 -0
  46. package/dist/firehose/lexicons.d.ts +0 -105
  47. package/dist/firehose/lexicons.d.ts.map +0 -1
  48. package/dist/firehose/lexicons.js +0 -299
  49. package/dist/firehose/lexicons.js.map +0 -1
  50. package/src/firehose/lexicons.ts +0 -446
@@ -1,446 +0,0 @@
1
- import type { IncomingMessage } from 'node:http'
2
- import type { CID } from 'multiformats/cid'
3
- import { type LexiconDoc, Lexicons } from '@atproto/lexicon'
4
- import type { Auth, ErrorFrame } from '@atproto/xrpc-server'
5
-
6
- // @NOTE: this file is an ugly copy job of codegen output. I'd like to clean this whole thing up
7
-
8
- export function isObj(v: unknown): v is Record<string, unknown> {
9
- return typeof v === 'object' && v !== null
10
- }
11
-
12
- export function hasProp<K extends PropertyKey>(
13
- data: object,
14
- prop: K,
15
- ): data is Record<K, unknown> {
16
- return prop in data
17
- }
18
-
19
- export interface QueryParams {
20
- /** The last known event seq number to backfill from. */
21
- cursor?: number
22
- }
23
-
24
- export type RepoEvent =
25
- | Commit
26
- | Identity
27
- | Account
28
- | Sync
29
- | Info
30
- | { $type: string; [k: string]: unknown }
31
- export type HandlerError = ErrorFrame<'FutureCursor' | 'ConsumerTooSlow'>
32
- export type HandlerOutput = HandlerError | RepoEvent
33
- export type HandlerReqCtx<HA extends Auth = never> = {
34
- auth: HA
35
- params: QueryParams
36
- req: IncomingMessage
37
- signal: AbortSignal
38
- }
39
- export type Handler<HA extends Auth = never> = (
40
- ctx: HandlerReqCtx<HA>,
41
- ) => AsyncIterable<HandlerOutput>
42
-
43
- /** Represents an update of repository state. Note that empty commits are allowed, which include no repo data changes, but an update to rev and signature. */
44
- export interface Commit {
45
- /** The stream sequence number of this message. */
46
- seq: number
47
- /** DEPRECATED -- unused */
48
- rebase: boolean
49
- /** Indicates that this commit contained too many ops, or data size was too large. Consumers will need to make a separate request to get missing data. */
50
- tooBig: boolean
51
- /** The repo this event comes from. */
52
- repo: string
53
- /** Repo commit object CID. */
54
- commit: CID
55
- /** DEPRECATED -- unused. WARNING -- nullable and optional; stick with optional to ensure golang interoperability. */
56
- prev?: CID | null
57
- /** The rev of the emitted commit. Note that this information is also in the commit object included in blocks, unless this is a tooBig event. */
58
- rev: string
59
- /** The rev of the last emitted commit from this repo (if any). */
60
- since: string | null
61
- /** CAR file containing relevant blocks, as a diff since the previous repo state. */
62
- blocks: Uint8Array
63
- ops: RepoOp[]
64
- blobs: CID[]
65
- /** Timestamp of when this message was originally broadcast. */
66
- time: string
67
- [k: string]: unknown
68
- }
69
-
70
- export function isCommit(v: unknown): v is Commit {
71
- return (
72
- isObj(v) &&
73
- hasProp(v, '$type') &&
74
- v.$type === 'com.atproto.sync.subscribeRepos#commit'
75
- )
76
- }
77
-
78
- /** Updates the repo to a new state, without necessarily including that state on the firehose. Used to recover from broken commit streams, data loss incidents, or in situations where upstream host does not know recent state of the repository. */
79
- export interface Sync {
80
- $type?: 'com.atproto.sync.subscribeRepos#sync'
81
- /** The stream sequence number of this message. */
82
- seq: number
83
- /** The account this repo event corresponds to. Must match that in the commit object. */
84
- did: string
85
- /** CAR file containing the commit, as a block. The CAR header must include the commit block CID as the first 'root'. */
86
- blocks: Uint8Array
87
- /** The rev of the commit. This value must match that in the commit object. */
88
- rev: string
89
- /** Timestamp of when this message was originally broadcast. */
90
- time: string
91
- }
92
-
93
- export function isSync(v: unknown): v is Sync {
94
- return (
95
- isObj(v) &&
96
- hasProp(v, '$type') &&
97
- v.$type === 'com.atproto.sync.subscribeRepos#sync'
98
- )
99
- }
100
-
101
- /** Represents a change to an account's identity. Could be an updated handle, signing key, or pds hosting endpoint. Serves as a prod to all downstream services to refresh their identity cache. */
102
- export interface Identity {
103
- seq: number
104
- did: string
105
- time: string
106
- /** The current handle for the account, or 'handle.invalid' if validation fails. This field is optional, might have been validated or passed-through from an upstream source. Semantics and behaviors for PDS vs Relay may evolve in the future; see atproto specs for more details. */
107
- handle?: string
108
- [k: string]: unknown
109
- }
110
-
111
- export function isIdentity(v: unknown): v is Identity {
112
- return (
113
- isObj(v) &&
114
- hasProp(v, '$type') &&
115
- v.$type === 'com.atproto.sync.subscribeRepos#identity'
116
- )
117
- }
118
-
119
- /** Represents a change to an account's status on a host (eg, PDS or Relay). The semantics of this event are that the status is at the host which emitted the event, not necessarily that at the currently active PDS. Eg, a Relay takedown would emit a takedown with active=false, even if the PDS is still active. */
120
- export interface Account {
121
- seq: number
122
- did: string
123
- time: string
124
- /** Indicates that the account has a repository which can be fetched from the host that emitted this event. */
125
- active: boolean
126
- /** If active=false, this optional field indicates a reason for why the account is not active. */
127
- status?: 'takendown' | 'suspended' | 'deleted' | 'deactivated' | string
128
- [k: string]: unknown
129
- }
130
-
131
- export function isAccount(v: unknown): v is Account {
132
- return (
133
- isObj(v) &&
134
- hasProp(v, '$type') &&
135
- v.$type === 'com.atproto.sync.subscribeRepos#account'
136
- )
137
- }
138
-
139
- export interface Info {
140
- name: 'OutdatedCursor' | string
141
- message?: string
142
- [k: string]: unknown
143
- }
144
-
145
- export function isInfo(v: unknown): v is Info {
146
- return (
147
- isObj(v) &&
148
- hasProp(v, '$type') &&
149
- v.$type === 'com.atproto.sync.subscribeRepos#info'
150
- )
151
- }
152
-
153
- /** A repo operation, ie a mutation of a single record. */
154
- export interface RepoOp {
155
- action: 'create' | 'update' | 'delete' | string
156
- path: string
157
- /** For creates and updates, the new record CID. For deletions, null. */
158
- cid: CID | null
159
- [k: string]: unknown
160
- }
161
-
162
- export function isRepoOp(v: unknown): v is RepoOp {
163
- return (
164
- isObj(v) &&
165
- hasProp(v, '$type') &&
166
- v.$type === 'com.atproto.sync.subscribeRepos#repoOp'
167
- )
168
- }
169
-
170
- export const ComAtprotoSyncSubscribeRepos: LexiconDoc = {
171
- lexicon: 1,
172
- id: 'com.atproto.sync.subscribeRepos',
173
- defs: {
174
- main: {
175
- type: 'subscription',
176
- description:
177
- 'Repository event stream, aka Firehose endpoint. Outputs repo commits with diff data, and identity update events, for all repositories on the current server. See the atproto specifications for details around stream sequencing, repo versioning, CAR diff format, and more. Public and does not require auth; implemented by PDS and Relay.',
178
- parameters: {
179
- type: 'params',
180
- properties: {
181
- cursor: {
182
- type: 'integer',
183
- description: 'The last known event seq number to backfill from.',
184
- },
185
- },
186
- },
187
- message: {
188
- schema: {
189
- type: 'union',
190
- refs: [
191
- 'lex:com.atproto.sync.subscribeRepos#commit',
192
- 'lex:com.atproto.sync.subscribeRepos#sync',
193
- 'lex:com.atproto.sync.subscribeRepos#identity',
194
- 'lex:com.atproto.sync.subscribeRepos#account',
195
- 'lex:com.atproto.sync.subscribeRepos#info',
196
- ],
197
- },
198
- },
199
- errors: [
200
- {
201
- name: 'FutureCursor',
202
- },
203
- {
204
- name: 'ConsumerTooSlow',
205
- description:
206
- 'If the consumer of the stream can not keep up with events, and a backlog gets too large, the server will drop the connection.',
207
- },
208
- ],
209
- },
210
- commit: {
211
- type: 'object',
212
- description:
213
- 'Represents an update of repository state. Note that empty commits are allowed, which include no repo data changes, but an update to rev and signature.',
214
- required: [
215
- 'seq',
216
- 'rebase',
217
- 'tooBig',
218
- 'repo',
219
- 'commit',
220
- 'rev',
221
- 'since',
222
- 'blocks',
223
- 'ops',
224
- 'blobs',
225
- 'time',
226
- ],
227
- nullable: ['since'],
228
- properties: {
229
- seq: {
230
- type: 'integer',
231
- description: 'The stream sequence number of this message.',
232
- },
233
- rebase: {
234
- type: 'boolean',
235
- description: 'DEPRECATED -- unused',
236
- },
237
- tooBig: {
238
- type: 'boolean',
239
- description:
240
- 'DEPRECATED -- replaced by #sync event and data limits. Indicates that this commit contained too many ops, or data size was too large. Consumers will need to make a separate request to get missing data.',
241
- },
242
- repo: {
243
- type: 'string',
244
- format: 'did',
245
- description:
246
- "The repo this event comes from. Note that all other message types name this field 'did'.",
247
- },
248
- commit: {
249
- type: 'cid-link',
250
- description: 'Repo commit object CID.',
251
- },
252
- rev: {
253
- type: 'string',
254
- format: 'tid',
255
- description:
256
- 'The rev of the emitted commit. Note that this information is also in the commit object included in blocks, unless this is a tooBig event.',
257
- },
258
- since: {
259
- type: 'string',
260
- format: 'tid',
261
- description:
262
- 'The rev of the last emitted commit from this repo (if any).',
263
- },
264
- blocks: {
265
- type: 'bytes',
266
- description:
267
- "CAR file containing relevant blocks, as a diff since the previous repo state. The commit must be included as a block, and the commit block CID must be the first entry in the CAR header 'roots' list.",
268
- maxLength: 2000000,
269
- },
270
- ops: {
271
- type: 'array',
272
- items: {
273
- type: 'ref',
274
- ref: 'lex:com.atproto.sync.subscribeRepos#repoOp',
275
- description:
276
- 'List of repo mutation operations in this commit (eg, records created, updated, or deleted).',
277
- },
278
- maxLength: 200,
279
- },
280
- blobs: {
281
- type: 'array',
282
- items: {
283
- type: 'cid-link',
284
- description:
285
- 'DEPRECATED -- will soon always be empty. List of new blobs (by CID) referenced by records in this commit.',
286
- },
287
- },
288
- prevData: {
289
- type: 'cid-link',
290
- description:
291
- "The root CID of the MST tree for the previous commit from this repo (indicated by the 'since' revision field in this message). Corresponds to the 'data' field in the repo commit object. NOTE: this field is effectively required for the 'inductive' version of firehose.",
292
- },
293
- time: {
294
- type: 'string',
295
- format: 'datetime',
296
- description:
297
- 'Timestamp of when this message was originally broadcast.',
298
- },
299
- },
300
- },
301
- sync: {
302
- type: 'object',
303
- description:
304
- 'Updates the repo to a new state, without necessarily including that state on the firehose. Used to recover from broken commit streams, data loss incidents, or in situations where upstream host does not know recent state of the repository.',
305
- required: ['seq', 'did', 'blocks', 'rev', 'time'],
306
- properties: {
307
- seq: {
308
- type: 'integer',
309
- description: 'The stream sequence number of this message.',
310
- },
311
- did: {
312
- type: 'string',
313
- format: 'did',
314
- description:
315
- 'The account this repo event corresponds to. Must match that in the commit object.',
316
- },
317
- blocks: {
318
- type: 'bytes',
319
- description:
320
- "CAR file containing the commit, as a block. The CAR header must include the commit block CID as the first 'root'.",
321
- maxLength: 10000,
322
- },
323
- rev: {
324
- type: 'string',
325
- description:
326
- 'The rev of the commit. This value must match that in the commit object.',
327
- },
328
- time: {
329
- type: 'string',
330
- format: 'datetime',
331
- description:
332
- 'Timestamp of when this message was originally broadcast.',
333
- },
334
- },
335
- },
336
- identity: {
337
- type: 'object',
338
- description:
339
- "Represents a change to an account's identity. Could be an updated handle, signing key, or pds hosting endpoint. Serves as a prod to all downstream services to refresh their identity cache.",
340
- required: ['seq', 'did', 'time'],
341
- properties: {
342
- seq: {
343
- type: 'integer',
344
- },
345
- did: {
346
- type: 'string',
347
- format: 'did',
348
- },
349
- time: {
350
- type: 'string',
351
- format: 'datetime',
352
- },
353
- handle: {
354
- type: 'string',
355
- format: 'handle',
356
- description:
357
- "The current handle for the account, or 'handle.invalid' if validation fails. This field is optional, might have been validated or passed-through from an upstream source. Semantics and behaviors for PDS vs Relay may evolve in the future; see atproto specs for more details.",
358
- },
359
- },
360
- },
361
- account: {
362
- type: 'object',
363
- description:
364
- "Represents a change to an account's status on a host (eg, PDS or Relay). The semantics of this event are that the status is at the host which emitted the event, not necessarily that at the currently active PDS. Eg, a Relay takedown would emit a takedown with active=false, even if the PDS is still active.",
365
- required: ['seq', 'did', 'time', 'active'],
366
- properties: {
367
- seq: {
368
- type: 'integer',
369
- },
370
- did: {
371
- type: 'string',
372
- format: 'did',
373
- },
374
- time: {
375
- type: 'string',
376
- format: 'datetime',
377
- },
378
- active: {
379
- type: 'boolean',
380
- description:
381
- 'Indicates that the account has a repository which can be fetched from the host that emitted this event.',
382
- },
383
- status: {
384
- type: 'string',
385
- description:
386
- 'If active=false, this optional field indicates a reason for why the account is not active.',
387
- knownValues: [
388
- 'takendown',
389
- 'suspended',
390
- 'deleted',
391
- 'deactivated',
392
- 'desynchronized',
393
- 'throttled',
394
- ],
395
- },
396
- },
397
- },
398
- info: {
399
- type: 'object',
400
- required: ['name'],
401
- properties: {
402
- name: {
403
- type: 'string',
404
- knownValues: ['OutdatedCursor'],
405
- },
406
- message: {
407
- type: 'string',
408
- },
409
- },
410
- },
411
- repoOp: {
412
- type: 'object',
413
- description: 'A repo operation, ie a mutation of a single record.',
414
- required: ['action', 'path', 'cid'],
415
- nullable: ['cid'],
416
- properties: {
417
- action: {
418
- type: 'string',
419
- knownValues: ['create', 'update', 'delete'],
420
- },
421
- path: {
422
- type: 'string',
423
- },
424
- cid: {
425
- type: 'cid-link',
426
- description:
427
- 'For creates and updates, the new record CID. For deletions, null.',
428
- },
429
- prev: {
430
- type: 'cid-link',
431
- description:
432
- 'For updates and deletes, the previous record CID (required for inductive firehose). For creations, field should not be defined.',
433
- },
434
- },
435
- },
436
- },
437
- }
438
-
439
- const lexicons = new Lexicons([ComAtprotoSyncSubscribeRepos])
440
-
441
- export const isValidRepoEvent = (evt: unknown) => {
442
- return lexicons.assertValidXrpcMessage<RepoEvent>(
443
- 'com.atproto.sync.subscribeRepos',
444
- evt,
445
- )
446
- }