@atproto/dev-env 0.5.16 → 0.5.18

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.
@@ -21,7 +21,7 @@ import {
21
21
  } from '@atproto/api'
22
22
  import { CidString, Client } from '@atproto/lex'
23
23
  import { BlobRef } from '@atproto/lexicon'
24
- import { AtUri, AtUriString, DidString } from '@atproto/syntax'
24
+ import { AtUri, AtUriString, DidString, HandleString } from '@atproto/syntax'
25
25
  import { TestNetworkNoAppView } from '../network-no-appview.js'
26
26
 
27
27
  // Makes it simple to create data via the XRPC client,
@@ -67,22 +67,21 @@ export class RecordRef {
67
67
  }
68
68
  }
69
69
 
70
+ export type Account = {
71
+ did: DidString
72
+ accessJwt: string
73
+ refreshJwt: string
74
+ handle: HandleString
75
+ email: string
76
+ password: string
77
+ }
78
+
70
79
  export class SeedClient<
71
80
  Network extends TestNetworkNoAppView = TestNetworkNoAppView,
72
81
  > {
73
- accounts: Record<
74
- string,
75
- {
76
- did: DidString
77
- accessJwt: string
78
- refreshJwt: string
79
- handle: string
80
- email: string
81
- password: string
82
- }
83
- >
82
+ accounts: Record<DidString, Account>
84
83
  profiles: Record<
85
- string,
84
+ DidString,
86
85
  {
87
86
  displayName: string
88
87
  description: string
@@ -91,41 +90,53 @@ export class SeedClient<
91
90
  ref: RecordRef
92
91
  }
93
92
  >
94
- follows: Record<string, Record<string, RecordRef>>
95
- blocks: Record<string, Record<string, RecordRef>>
96
- mutes: Record<string, Set<string>>
93
+ follows: Record<DidString, Record<DidString, RecordRef>>
94
+ blocks: Record<DidString, Record<DidString, RecordRef>>
95
+ mutes: Record<DidString, Set<DidString>>
97
96
  posts: Record<
98
- string,
97
+ DidString,
99
98
  { text: string; ref: RecordRef; images: ImageRef[]; quote?: RecordRef }[]
100
99
  >
101
- likes: Record<string, Record<string, AtUri>>
100
+ likes: Record<DidString, Record<string, AtUri>>
102
101
  replies: Record<
103
102
  string,
104
103
  { text: string; ref: RecordRef; images: ImageRef[] }[]
105
104
  >
106
- reposts: Record<string, RecordRef[]>
105
+ reposts: Record<DidString, RecordRef[]>
107
106
  lists: Record<
108
- string,
109
- Record<string, { ref: RecordRef; items: Record<string, RecordRef> }>
107
+ DidString,
108
+ Record<
109
+ AtUriString,
110
+ {
111
+ ref: RecordRef
112
+ items: Record<DidString, RecordRef>
113
+ }
114
+ >
110
115
  >
111
116
  feedgens: Record<
112
- string,
113
- Record<string, { ref: RecordRef; items: Record<string, RecordRef> }>
117
+ DidString,
118
+ Record<
119
+ AtUriString,
120
+ {
121
+ ref: RecordRef
122
+ items: Record<string, RecordRef>
123
+ }
124
+ >
114
125
  >
115
126
  starterpacks: Record<
116
- string,
127
+ DidString,
117
128
  Record<
118
- string,
129
+ AtUriString,
119
130
  {
120
131
  ref: RecordRef
121
132
  name: string
122
133
  list: RecordRef
123
- feeds: string[]
134
+ feeds: readonly AtUriString[]
124
135
  }
125
136
  >
126
137
  >
127
138
 
128
- verifications: Record<string, Record<string, AtUri>>
139
+ verifications: Record<DidString, Record<DidString, AtUri>>
129
140
 
130
141
  dids: Record<string, DidString>
131
142
 
@@ -153,18 +164,19 @@ export class SeedClient<
153
164
  async createAccount(
154
165
  shortName: string,
155
166
  params: {
156
- handle: string
167
+ handle: HandleString
157
168
  email: string
158
169
  password: string
159
170
  inviteCode?: string
160
171
  },
161
- ) {
172
+ ): Promise<Account> {
162
173
  const { data: account } =
163
174
  await this.agent.com.atproto.server.createAccount(params)
164
175
  const did = account.did as DidString
165
176
  this.dids[shortName] = did
166
177
  this.accounts[account.did] = {
167
- ...account,
178
+ // @NOTE type case needed until we move test to lex-sdk
179
+ ...(account as typeof account & { handle: HandleString }),
168
180
  did,
169
181
  email: params.email,
170
182
  password: params.password,
@@ -172,7 +184,7 @@ export class SeedClient<
172
184
  return this.accounts[account.did]
173
185
  }
174
186
 
175
- async updateHandle(by: string, handle: string) {
187
+ async updateHandle(by: DidString, handle: HandleString) {
176
188
  await this.agent.com.atproto.identity.updateHandle(
177
189
  { handle },
178
190
  { encoding: 'application/json', headers: this.getHeaders(by) },
@@ -180,10 +192,10 @@ export class SeedClient<
180
192
  }
181
193
 
182
194
  async createProfile(
183
- by: string,
195
+ by: DidString,
184
196
  displayName: string,
185
197
  description: string,
186
- selfLabels?: string[],
198
+ selfLabels?: readonly string[],
187
199
  joinedViaStarterPack?: RecordRef,
188
200
  overrides?: Partial<AppBskyActorProfile.Record>,
189
201
  ): Promise<{
@@ -234,7 +246,7 @@ export class SeedClient<
234
246
  return this.profiles[by]
235
247
  }
236
248
 
237
- async updateProfile(by: string, record: Record<string, unknown>) {
249
+ async updateProfile(by: DidString, record: Record<string, unknown>) {
238
250
  const res = await this.agent.com.atproto.repo.putRecord(
239
251
  {
240
252
  repo: by,
@@ -253,8 +265,8 @@ export class SeedClient<
253
265
  }
254
266
 
255
267
  async follow(
256
- from: string,
257
- to: string,
268
+ from: DidString,
269
+ to: DidString,
258
270
  overrides?: Partial<AppBskyGraphFollow.Record>,
259
271
  ) {
260
272
  const res = await this.agent.app.bsky.graph.follow.create(
@@ -271,7 +283,7 @@ export class SeedClient<
271
283
  return this.follows[from][to]
272
284
  }
273
285
 
274
- async unfollow(from: string, to: string) {
286
+ async unfollow(from: DidString, to: DidString) {
275
287
  const follow = this.follows[from][to]
276
288
  if (!follow) {
277
289
  throw new Error('follow does not exist')
@@ -284,8 +296,8 @@ export class SeedClient<
284
296
  }
285
297
 
286
298
  async block(
287
- from: string,
288
- to: string,
299
+ from: DidString,
300
+ to: DidString,
289
301
  overrides?: Partial<AppBskyGraphBlock.Record>,
290
302
  ) {
291
303
  const res = await this.agent.app.bsky.graph.block.create(
@@ -302,7 +314,7 @@ export class SeedClient<
302
314
  return this.blocks[from][to]
303
315
  }
304
316
 
305
- async unblock(from: string, to: string) {
317
+ async unblock(from: DidString, to: DidString) {
306
318
  const block = this.blocks[from][to]
307
319
  if (!block) {
308
320
  throw new Error('block does not exist')
@@ -314,7 +326,7 @@ export class SeedClient<
314
326
  delete this.blocks[from][to]
315
327
  }
316
328
 
317
- async mute(from: string, to: string) {
329
+ async mute(from: DidString, to: DidString) {
318
330
  await this.agent.app.bsky.graph.muteActor(
319
331
  {
320
332
  actor: to,
@@ -327,7 +339,7 @@ export class SeedClient<
327
339
  }
328
340
 
329
341
  async post(
330
- by: string,
342
+ by: DidString,
331
343
  text: string,
332
344
  facets?: AppBskyRichtextFacet.Main[],
333
345
  images?: ImageRef[],
@@ -373,7 +385,7 @@ export class SeedClient<
373
385
  return post
374
386
  }
375
387
 
376
- async deletePost(by: string, uri: AtUri) {
388
+ async deletePost(by: DidString, uri: AtUri) {
377
389
  await this.agent.app.bsky.feed.post.delete(
378
390
  {
379
391
  repo: by,
@@ -384,7 +396,7 @@ export class SeedClient<
384
396
  }
385
397
 
386
398
  async uploadFile(
387
- by: string,
399
+ by: DidString,
388
400
  filePath: string,
389
401
  encoding: string,
390
402
  ): Promise<ImageRef> {
@@ -397,7 +409,7 @@ export class SeedClient<
397
409
  }
398
410
 
399
411
  async like(
400
- by: string,
412
+ by: DidString,
401
413
  subject: RecordRef,
402
414
  overrides?: Partial<AppBskyFeedLike.Record>,
403
415
  ) {
@@ -416,7 +428,7 @@ export class SeedClient<
416
428
  }
417
429
 
418
430
  async reply(
419
- by: string,
431
+ by: DidString,
420
432
  root: RecordRef,
421
433
  parent: RecordRef,
422
434
  text: string,
@@ -456,7 +468,7 @@ export class SeedClient<
456
468
  }
457
469
 
458
470
  async repost(
459
- by: string,
471
+ by: DidString,
460
472
  subject: RecordRef,
461
473
  overrides?: Partial<AppBskyFeedRepost.Record>,
462
474
  ) {
@@ -476,7 +488,7 @@ export class SeedClient<
476
488
  }
477
489
 
478
490
  async createList(
479
- by: string,
491
+ by: DidString,
480
492
  name: string,
481
493
  purpose: 'mod' | 'curate' | 'reference',
482
494
  overrides?: Partial<AppBskyGraphList.Record>,
@@ -505,7 +517,7 @@ export class SeedClient<
505
517
  return ref
506
518
  }
507
519
 
508
- async createFeedGen(by: string, feedDid: string, name: string) {
520
+ async createFeedGen(by: DidString, feedDid: string, name: string) {
509
521
  const res = await this.agent.app.bsky.feed.generator.create(
510
522
  { repo: by },
511
523
  {
@@ -525,10 +537,10 @@ export class SeedClient<
525
537
  }
526
538
 
527
539
  async createStarterPack(
528
- by: string,
540
+ by: DidString,
529
541
  name: string,
530
- actors: string[],
531
- feeds?: string[],
542
+ actors: readonly DidString[],
543
+ feeds?: readonly AtUriString[],
532
544
  ) {
533
545
  const list = await this.createList(by, 'n/a', 'reference')
534
546
  for (const did of actors) {
@@ -555,7 +567,7 @@ export class SeedClient<
555
567
  return ref
556
568
  }
557
569
 
558
- async addToList(by: string, subject: string, list: RecordRef) {
570
+ async addToList(by: DidString, subject: DidString, list: RecordRef) {
559
571
  const res = await this.agent.app.bsky.graph.listitem.create(
560
572
  { repo: by },
561
573
  { subject, list: list.uriStr, createdAt: new Date().toISOString() },
@@ -569,7 +581,7 @@ export class SeedClient<
569
581
  return ref
570
582
  }
571
583
 
572
- async rmFromList(by: string, subject: string, list: RecordRef) {
584
+ async rmFromList(by: DidString, subject: DidString, list: RecordRef) {
573
585
  const foundList = (this.lists[by] ?? {})[list.uriStr] ?? {}
574
586
  if (!foundList) return
575
587
  const foundItem = foundList.items[subject]
@@ -591,7 +603,7 @@ export class SeedClient<
591
603
  | $Typed<ChatBskyConvoDefs.ConvoRef>
592
604
  | { $type: string }
593
605
  reason?: string
594
- reportedBy: string
606
+ reportedBy: DidString
595
607
  }): Promise<
596
608
  ComAtprotoModerationCreateReport.OutputSchema & {
597
609
  subject:
@@ -614,9 +626,9 @@ export class SeedClient<
614
626
  }
615
627
 
616
628
  async verify(
617
- by: string,
618
- subject: string,
619
- handle: string,
629
+ by: DidString,
630
+ subject: DidString,
631
+ handle: HandleString,
620
632
  displayName: string,
621
633
  overrides?: Partial<AppBskyGraphVerification.Record>,
622
634
  ) {
@@ -636,7 +648,7 @@ export class SeedClient<
636
648
  return this.verifications[by][subject]
637
649
  }
638
650
 
639
- async unverify(by: string, subject: string) {
651
+ async unverify(by: DidString, subject: DidString) {
640
652
  const verification = this.verifications[by]?.[subject]
641
653
  if (!verification) {
642
654
  throw new Error('verification does not exist')
@@ -649,7 +661,7 @@ export class SeedClient<
649
661
  delete this.verifications[by][subject]
650
662
  }
651
663
 
652
- getHeaders(did: string) {
664
+ getHeaders(did: DidString) {
653
665
  return SeedClient.getHeaders(this.accounts[did].accessJwt)
654
666
  }
655
667
 
@@ -54,4 +54,4 @@ const users = {
54
54
  handle: 'eve.test',
55
55
  password: 'eve-pass',
56
56
  },
57
- }
57
+ } as const
@@ -1,14 +1,15 @@
1
1
  import { AppBskyFeedPost } from '@atproto/api'
2
2
  import type { DatabaseSchema } from '@atproto/bsky'
3
+ import type { DidString, HandleString } from '@atproto/syntax'
3
4
  import { TestNetworkNoAppView } from '../network-no-appview.js'
4
5
  import { TestNetwork } from '../network.js'
5
6
  import { RecordRef, SeedClient } from './client.js'
6
7
 
7
8
  type User = {
8
9
  id: string
9
- did: string
10
+ did: DidString
10
11
  email: string
11
- handle: string
12
+ handle: HandleString
12
13
  password: string
13
14
  displayName: string
14
15
  description: string
@@ -21,7 +22,7 @@ function createUserStub(name: string): User {
21
22
  // @ts-ignore overwritten during seeding
22
23
  did: undefined,
23
24
  email: `${name}@test.com`,
24
- handle: `${name}.test`,
25
+ handle: `${name}.test` as HandleString,
25
26
  password: `${name}-pass`,
26
27
  displayName: name,
27
28
  description: `hi im ${name} label_me`,
@@ -1,4 +1,5 @@
1
1
  import { chunkArray } from '@atproto/common-web'
2
+ import type { HandleString } from '@atproto/syntax'
2
3
  import { SeedClient } from './client.js'
3
4
 
4
5
  export default async function usersBulkSeed(sc: SeedClient, max = Infinity) {
@@ -11,7 +12,7 @@ export default async function usersBulkSeed(sc: SeedClient, max = Infinity) {
11
12
  chunk.map(async (user) => {
12
13
  const { handle, displayName } = user
13
14
  await sc.createAccount(handle, {
14
- handle: handle,
15
+ handle,
15
16
  password: 'password',
16
17
  email: `${handle}@bsky.app`,
17
18
  })
@@ -24,7 +25,7 @@ export default async function usersBulkSeed(sc: SeedClient, max = Infinity) {
24
25
  return sc
25
26
  }
26
27
 
27
- const users = [
28
+ const users: { handle: HandleString; displayName: string | null }[] = [
28
29
  { handle: 'silas77.test', displayName: 'Tanya Denesik' },
29
30
  { handle: 'nicolas-krajcik10.test', displayName: null },
30
31
  { handle: 'lennie-strosin.test', displayName: null },
package/src/seed/users.ts CHANGED
@@ -61,4 +61,4 @@ const users = {
61
61
  description: undefined,
62
62
  selfLabels: undefined,
63
63
  },
64
- }
64
+ } as const
@@ -226,7 +226,7 @@ const users = {
226
226
  handle: 'handleempty.test',
227
227
  password: 'handleempty-pass',
228
228
  },
229
- }
229
+ } as const
230
230
 
231
231
  const createLabel = async (
232
232
  sc: SeedClient<TestNetwork>,