@fedify/botkit 0.5.0-dev.210 → 0.5.0-dev.226

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 (84) hide show
  1. package/dist/bot-group.test.d.ts +2 -0
  2. package/dist/bot-group.test.js +220 -0
  3. package/dist/bot-group.test.js.map +1 -0
  4. package/dist/bot-impl.d.ts +132 -13
  5. package/dist/bot-impl.d.ts.map +1 -1
  6. package/dist/bot-impl.js +400 -178
  7. package/dist/bot-impl.js.map +1 -1
  8. package/dist/bot-impl.test.js +214 -76
  9. package/dist/bot-impl.test.js.map +1 -1
  10. package/dist/bot.d.ts +94 -48
  11. package/dist/bot.d.ts.map +1 -1
  12. package/dist/bot.js +2 -104
  13. package/dist/bot.js.map +1 -1
  14. package/dist/bot.test.js +59 -0
  15. package/dist/bot.test.js.map +1 -1
  16. package/dist/components/FollowButton.d.ts +3 -1
  17. package/dist/components/FollowButton.d.ts.map +1 -1
  18. package/dist/components/FollowButton.js +2 -2
  19. package/dist/components/FollowButton.js.map +1 -1
  20. package/dist/components/Layout.js +1 -1
  21. package/dist/components/Layout.js.map +1 -1
  22. package/dist/components/Message.d.ts +2 -2
  23. package/dist/deno.js +3 -13
  24. package/dist/deno.js.map +1 -1
  25. package/dist/follow-impl.test.js +3 -3
  26. package/dist/follow-impl.test.js.map +1 -1
  27. package/dist/instance-impl.d.ts +158 -0
  28. package/dist/instance-impl.d.ts.map +1 -0
  29. package/dist/instance-impl.js +603 -0
  30. package/dist/instance-impl.js.map +1 -0
  31. package/dist/instance-impl.test.d.ts +2 -0
  32. package/dist/instance-impl.test.js +103 -0
  33. package/dist/instance-impl.test.js.map +1 -0
  34. package/dist/instance-multi.test.d.ts +2 -0
  35. package/dist/instance-multi.test.js +151 -0
  36. package/dist/instance-multi.test.js.map +1 -0
  37. package/dist/instance-routing.test.d.ts +2 -0
  38. package/dist/instance-routing.test.js +367 -0
  39. package/dist/instance-routing.test.js.map +1 -0
  40. package/dist/instance.d.ts +318 -0
  41. package/dist/instance.d.ts.map +1 -0
  42. package/dist/instance.js +51 -0
  43. package/dist/instance.js.map +1 -0
  44. package/dist/message-impl.d.ts.map +1 -1
  45. package/dist/message-impl.js +17 -10
  46. package/dist/message-impl.js.map +1 -1
  47. package/dist/message-impl.test.js +43 -9
  48. package/dist/message-impl.test.js.map +1 -1
  49. package/dist/mod.d.ts +5 -3
  50. package/dist/mod.js +4 -2
  51. package/dist/pages.d.ts +10 -1
  52. package/dist/pages.d.ts.map +1 -1
  53. package/dist/pages.js +112 -41
  54. package/dist/pages.js.map +1 -1
  55. package/dist/pages.test.d.ts +2 -0
  56. package/dist/pages.test.js +170 -0
  57. package/dist/pages.test.js.map +1 -0
  58. package/dist/repository.d.ts +385 -138
  59. package/dist/repository.d.ts.map +1 -1
  60. package/dist/repository.js +595 -223
  61. package/dist/repository.js.map +1 -1
  62. package/dist/repository.test.js +564 -136
  63. package/dist/repository.test.js.map +1 -1
  64. package/dist/session-impl.d.ts.map +1 -1
  65. package/dist/session-impl.js +13 -4
  66. package/dist/session-impl.js.map +1 -1
  67. package/dist/session-impl.test.d.ts.map +1 -1
  68. package/dist/session-impl.test.js +9 -9
  69. package/dist/session-impl.test.js.map +1 -1
  70. package/dist/session.d.ts +8 -3
  71. package/dist/session.d.ts.map +1 -1
  72. package/dist/text.d.ts.map +1 -1
  73. package/dist/text.js +27 -10
  74. package/dist/text.js.map +1 -1
  75. package/dist/text.test.js +37 -2
  76. package/dist/text.test.js.map +1 -1
  77. package/dist/uri.d.ts +46 -0
  78. package/dist/uri.d.ts.map +1 -0
  79. package/dist/uri.js +64 -0
  80. package/dist/uri.js.map +1 -0
  81. package/dist/uri.test.d.ts +2 -0
  82. package/dist/uri.test.js +93 -0
  83. package/dist/uri.test.js.map +1 -0
  84. package/package.json +6 -2
@@ -11,28 +11,41 @@ import { Actor, Announce, Announce as Announce$1, Create, Create as Create$1, Fo
11
11
  type Uuid = ReturnType<typeof crypto.randomUUID>;
12
12
  /**
13
13
  * A repository for storing bot data.
14
+ *
15
+ * Since BotKit 0.5.0, a single repository can store data for multiple bot
16
+ * actors hosted on the same instance. Every method takes the identifier of
17
+ * the bot actor that owns the data as its first parameter, and data belonging
18
+ * to different identifiers are completely isolated from each other.
19
+ *
20
+ * If you deal with a single bot actor, you can use
21
+ * the {@link Repository.forIdentifier} method to get
22
+ * an {@link ActorScopedRepository} view which binds the identifier once.
14
23
  * @since 0.3.0
15
24
  */
16
25
  interface Repository {
17
26
  /**
18
- * Sets the key pairs of the bot actor.
27
+ * Sets the key pairs of a bot actor.
28
+ * @param identifier The identifier of the bot actor that owns the key pairs.
19
29
  * @param keyPairs The key pairs to set.
20
30
  */
21
- setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>;
31
+ setKeyPairs(identifier: string, keyPairs: CryptoKeyPair[]): Promise<void>;
22
32
  /**
23
- * Gets the key pairs of the bot actor.
33
+ * Gets the key pairs of a bot actor.
34
+ * @param identifier The identifier of the bot actor that owns the key pairs.
24
35
  * @returns The key pairs of the bot actor. If the key pairs do not exist,
25
36
  * `undefined` will be returned.
26
37
  */
27
- getKeyPairs(): Promise<CryptoKeyPair[] | undefined>;
38
+ getKeyPairs(identifier: string): Promise<CryptoKeyPair[] | undefined>;
28
39
  /**
29
40
  * Adds a message to the repository.
41
+ * @param identifier The identifier of the bot actor that owns the message.
30
42
  * @param id The UUID of the message.
31
43
  * @param activity The activity to add.
32
44
  */
33
- addMessage(id: Uuid, activity: Create$1 | Announce$1): Promise<void>;
45
+ addMessage(identifier: string, id: Uuid, activity: Create$1 | Announce$1): Promise<void>;
34
46
  /**
35
47
  * Updates a message in the repository.
48
+ * @param identifier The identifier of the bot actor that owns the message.
36
49
  * @param id The UUID of the message.
37
50
  * @param updater The function to update the message. The function will be
38
51
  * called with the existing message, and the return value will
@@ -44,6 +57,243 @@ interface Repository {
44
57
  * @returns `true` if the message was updated, `false` if the message does not
45
58
  * exist.
46
59
  */
60
+ updateMessage(identifier: string, id: Uuid, updater: (existing: Create$1 | Announce$1) => Create$1 | Announce$1 | undefined | Promise<Create$1 | Announce$1 | undefined>): Promise<boolean>;
61
+ /**
62
+ * Removes a message from the repository.
63
+ * @param identifier The identifier of the bot actor that owns the message.
64
+ * @param id The UUID of the message to remove.
65
+ * @returns The removed activity. If the message does not exist, `undefined`
66
+ * will be returned.
67
+ */
68
+ removeMessage(identifier: string, id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
69
+ /**
70
+ * Gets messages from the repository.
71
+ * @param identifier The identifier of the bot actor that owns the messages.
72
+ * @param options The options for getting messages.
73
+ * @returns An async iterable of message activities.
74
+ */
75
+ getMessages(identifier: string, options?: RepositoryGetMessagesOptions): AsyncIterable<Create$1 | Announce$1>;
76
+ /**
77
+ * Gets a message from the repository.
78
+ * @param identifier The identifier of the bot actor that owns the message.
79
+ * @param id The UUID of the message to get.
80
+ * @returns The message activity, or `undefined` if the message does not
81
+ * exist.
82
+ */
83
+ getMessage(identifier: string, id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
84
+ /**
85
+ * Counts the number of messages in the repository.
86
+ * @param identifier The identifier of the bot actor that owns the messages.
87
+ * @returns The number of messages in the repository.
88
+ */
89
+ countMessages(identifier: string): Promise<number>;
90
+ /**
91
+ * Adds a follower to the repository.
92
+ * @param identifier The identifier of the bot actor that is followed.
93
+ * @param followId The URL of the follow request.
94
+ * @param follower The actor who follows the bot.
95
+ */
96
+ addFollower(identifier: string, followId: URL, follower: Actor): Promise<void>;
97
+ /**
98
+ * Removes a follower from the repository.
99
+ * @param identifier The identifier of the bot actor that is followed.
100
+ * @param followId The URL of the follow request.
101
+ * @param followerId The ID of the actor to remove.
102
+ * @returns The removed actor. If the follower does not exist or the follow
103
+ * request is not about the follower, `undefined` will be returned.
104
+ */
105
+ removeFollower(identifier: string, followId: URL, followerId: URL): Promise<Actor | undefined>;
106
+ /**
107
+ * Checks if the repository has a follower.
108
+ * @param identifier The identifier of the bot actor that is followed.
109
+ * @param followerId The ID of the follower to check.
110
+ * @returns `true` if the repository has the follower, `false` otherwise.
111
+ */
112
+ hasFollower(identifier: string, followerId: URL): Promise<boolean>;
113
+ /**
114
+ * Gets followers from the repository.
115
+ * @param identifier The identifier of the bot actor that is followed.
116
+ * @param options The options for getting followers.
117
+ * @returns An async iterable of actors who follow the bot.
118
+ */
119
+ getFollowers(identifier: string, options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>;
120
+ /**
121
+ * Counts the number of followers in the repository.
122
+ * @param identifier The identifier of the bot actor that is followed.
123
+ * @returns The number of followers in the repository.
124
+ */
125
+ countFollowers(identifier: string): Promise<number>;
126
+ /**
127
+ * Adds a sent follow request to the repository.
128
+ * @param identifier The identifier of the bot actor that sent the follow
129
+ * request.
130
+ * @param id The UUID of the follow request.
131
+ * @param follow The follow activity to add.
132
+ */
133
+ addSentFollow(identifier: string, id: Uuid, follow: Follow): Promise<void>;
134
+ /**
135
+ * Removes a sent follow request from the repository.
136
+ * @param identifier The identifier of the bot actor that sent the follow
137
+ * request.
138
+ * @param id The UUID of the follow request to remove.
139
+ * @returns The removed follow activity. If the follow request does not
140
+ * exist, `undefined` will be returned.
141
+ */
142
+ removeSentFollow(identifier: string, id: Uuid): Promise<Follow | undefined>;
143
+ /**
144
+ * Gets a sent follow request from the repository.
145
+ * @param identifier The identifier of the bot actor that sent the follow
146
+ * request.
147
+ * @param id The UUID of the follow request to get.
148
+ * @returns The `Follow` activity, or `undefined` if the follow request does
149
+ * not exist.
150
+ */
151
+ getSentFollow(identifier: string, id: Uuid): Promise<Follow | undefined>;
152
+ /**
153
+ * Adds a followee to the repository.
154
+ * @param identifier The identifier of the bot actor that follows
155
+ * the followee.
156
+ * @param followeeId The ID of the followee to add.
157
+ * @param follow The follow activity to add.
158
+ */
159
+ addFollowee(identifier: string, followeeId: URL, follow: Follow): Promise<void>;
160
+ /**
161
+ * Removes a followee from the repository.
162
+ * @param identifier The identifier of the bot actor that follows
163
+ * the followee.
164
+ * @param followeeId The ID of the followee to remove.
165
+ * @returns The `Follow` activity that was removed. If the followee does not
166
+ * exist, `undefined` will be returned.
167
+ */
168
+ removeFollowee(identifier: string, followeeId: URL): Promise<Follow | undefined>;
169
+ /**
170
+ * Gets a followee from the repository.
171
+ * @param identifier The identifier of the bot actor that follows
172
+ * the followee.
173
+ * @param followeeId The ID of the followee to get.
174
+ * @returns The `Follow` activity, or `undefined` if the followee does not
175
+ * exist.
176
+ */
177
+ getFollowee(identifier: string, followeeId: URL): Promise<Follow | undefined>;
178
+ /**
179
+ * Finds the identifiers of the bot actors that follow the given actor.
180
+ * This is the reverse lookup of {@link Repository.getFollowee}: it answers
181
+ * the question “which bots on this instance follow this remote actor?”,
182
+ * which is used for routing incoming activities from followed actors to
183
+ * the right bots.
184
+ * @param followeeId The ID of the followee to look up.
185
+ * @returns An async iterable of the identifiers of the bot actors that
186
+ * follow the given actor. If no bots follow the actor, an empty
187
+ * iterable will be returned.
188
+ * @since 0.5.0
189
+ */
190
+ findFollowedBots(followeeId: URL): AsyncIterable<string>;
191
+ /**
192
+ * Records a vote in a poll. If the same voter had already voted for the
193
+ * same option in a poll, the vote will be silently ignored.
194
+ * @param identifier The identifier of the bot actor that owns the poll.
195
+ * @param messageId The UUID of the poll message to vote on.
196
+ * @param voterId The ID of the voter. It should be a URL of the actor who is
197
+ * voting.
198
+ * @param option The option that the voter is voting for. It should be one of
199
+ * the options in the poll. If the poll allows multiple
200
+ * selections, this should be a single option that the voter is
201
+ * voting for, which is one of multiple calls to this method.
202
+ * @since 0.3.0
203
+ */
204
+ vote(identifier: string, messageId: Uuid, voterId: URL, option: string): Promise<void>;
205
+ /**
206
+ * Counts the number of voters in a poll. Even if the poll allows multiple
207
+ * selections, each voter is counted only once.
208
+ * @param identifier The identifier of the bot actor that owns the poll.
209
+ * @param messageId The UUID of the poll message to count voters for.
210
+ * @returns The number of voters in the poll. If the poll does not exist,
211
+ * 0 will be returned.
212
+ * @since 0.3.0
213
+ */
214
+ countVoters(identifier: string, messageId: Uuid): Promise<number>;
215
+ /**
216
+ * Counts the votes for each option in a poll. If the poll allows multiple
217
+ * selections, each option is counted separately, and the same voter can
218
+ * vote for multiple options.
219
+ * @param identifier The identifier of the bot actor that owns the poll.
220
+ * @param messageId The UUID of the poll message to count votes for.
221
+ * @returns A record where the keys are the options and the values are
222
+ * the number of votes for each option. If the poll does not exist,
223
+ * an empty record will be returned. Some options may not be
224
+ * present in the record if no votes were cast for them.
225
+ * @since 0.3.0
226
+ */
227
+ countVotes(identifier: string, messageId: Uuid): Promise<Readonly<Record<string, number>>>;
228
+ /**
229
+ * Returns a view of this repository which is scoped to the given bot actor
230
+ * identifier. The returned view exposes the same operations without
231
+ * the `identifier` parameter.
232
+ * @param identifier The identifier of the bot actor to scope the view to.
233
+ * @returns The scoped repository view.
234
+ * @since 0.5.0
235
+ */
236
+ forIdentifier(identifier: string): ActorScopedRepository;
237
+ /**
238
+ * Migrates data stored by BotKit 0.4 or earlier, which was not scoped by
239
+ * bot actor identifiers, so that it belongs to the given identifier.
240
+ * Implementations should make this operation idempotent: calling it again
241
+ * after a successful migration should be a no-op.
242
+ *
243
+ * This method is optional; repositories which have no legacy data format
244
+ * do not need to implement it.
245
+ * @param identifier The identifier of the bot actor that adopts the legacy
246
+ * data.
247
+ * @since 0.5.0
248
+ */
249
+ migrate?(identifier: string): Promise<void>;
250
+ }
251
+ /**
252
+ * A view of a {@link Repository} which is scoped to a single bot actor
253
+ * identifier. It exposes the same operations as {@link Repository} without
254
+ * the `identifier` parameter, which is bound at construction time.
255
+ * @since 0.5.0
256
+ */
257
+ declare class ActorScopedRepository {
258
+ /**
259
+ * The underlying repository.
260
+ */
261
+ readonly repository: Repository;
262
+ /**
263
+ * The identifier of the bot actor this view is scoped to.
264
+ */
265
+ readonly identifier: string;
266
+ /**
267
+ * Creates a new scoped repository view.
268
+ * @param repository The underlying repository.
269
+ * @param identifier The identifier of the bot actor to scope the view to.
270
+ */
271
+ constructor(repository: Repository, identifier: string);
272
+ /**
273
+ * Sets the key pairs of the bot actor.
274
+ * @param keyPairs The key pairs to set.
275
+ */
276
+ setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>;
277
+ /**
278
+ * Gets the key pairs of the bot actor.
279
+ * @returns The key pairs of the bot actor. If the key pairs do not exist,
280
+ * `undefined` will be returned.
281
+ */
282
+ getKeyPairs(): Promise<CryptoKeyPair[] | undefined>;
283
+ /**
284
+ * Adds a message to the repository.
285
+ * @param id The UUID of the message.
286
+ * @param activity The activity to add.
287
+ */
288
+ addMessage(id: Uuid, activity: Create$1 | Announce$1): Promise<void>;
289
+ /**
290
+ * Updates a message in the repository.
291
+ * @param id The UUID of the message.
292
+ * @param updater The function to update the message. See also
293
+ * {@link Repository.updateMessage}.
294
+ * @returns `true` if the message was updated, `false` if the message does not
295
+ * exist.
296
+ */
47
297
  updateMessage(id: Uuid, updater: (existing: Create$1 | Announce$1) => Create$1 | Announce$1 | undefined | Promise<Create$1 | Announce$1 | undefined>): Promise<boolean>;
48
298
  /**
49
299
  * Removes a message from the repository.
@@ -145,13 +395,8 @@ interface Repository {
145
395
  * Records a vote in a poll. If the same voter had already voted for the
146
396
  * same option in a poll, the vote will be silently ignored.
147
397
  * @param messageId The UUID of the poll message to vote on.
148
- * @param voterId The ID of the voter. It should be a URL of the actor who is
149
- * voting.
150
- * @param option The option that the voter is voting for. It should be one of
151
- * the options in the poll. If the poll allows multiple
152
- * selections, this should be a single option that the voter is
153
- * voting for, which is one of multiple calls to this method.
154
- * @since 0.3.0
398
+ * @param voterId The ID of the voter.
399
+ * @param option The option that the voter is voting for.
155
400
  */
156
401
  vote(messageId: Uuid, voterId: URL, option: string): Promise<void>;
157
402
  /**
@@ -160,19 +405,14 @@ interface Repository {
160
405
  * @param messageId The UUID of the poll message to count voters for.
161
406
  * @returns The number of voters in the poll. If the poll does not exist,
162
407
  * 0 will be returned.
163
- * @since 0.3.0
164
408
  */
165
409
  countVoters(messageId: Uuid): Promise<number>;
166
410
  /**
167
- * Counts the votes for each option in a poll. If the poll allows multiple
168
- * selections, each option is counted separately, and the same voter can
169
- * vote for multiple options.
411
+ * Counts the votes for each option in a poll.
170
412
  * @param messageId The UUID of the poll message to count votes for.
171
413
  * @returns A record where the keys are the options and the values are
172
- * the number of votes for each option. If the poll does not exist,
173
- * an empty record will be returned. Some options may not be
174
- * present in the record if no votes were cast for them.
175
- * @since 0.3.0
414
+ * the number of votes for each option. See also
415
+ * {@link Repository.countVotes}.
176
416
  */
177
417
  countVotes(messageId: Uuid): Promise<Readonly<Record<string, number>>>;
178
418
  }
@@ -218,116 +458,110 @@ interface RepositoryGetFollowersOptions {
218
458
  readonly limit?: number;
219
459
  }
220
460
  /**
221
- * The prefixes for key-value store keys used by the bot.
222
- * @since 0.3.0
461
+ * Options for creating a {@link KvRepository}.
462
+ * @since 0.5.0
223
463
  */
224
- interface KvStoreRepositoryPrefixes {
225
- /**
226
- * The key prefix used for storing the key pairs of the bot actor.
227
- * @default `["_botkit", "keyPairs"]`
228
- */
229
- readonly keyPairs: KvKey$1;
464
+ interface KvRepositoryOptions {
230
465
  /**
231
- * The key prefix used for storing published messages.
232
- * @default `["_botkit", "messages"]`
466
+ * The key prefix under which all BotKit data is stored. Data belonging to
467
+ * a bot actor is stored under `[...prefix, "bots", identifier, ...]`, and
468
+ * instance-wide indices are stored under `[...prefix, "index", ...]`.
469
+ * @default `["_botkit"]`
233
470
  */
234
- readonly messages: KvKey$1;
235
- /**
236
- * The key prefix used for storing followers.
237
- * @default `["_botkit", "followers"]`
238
- */
239
- readonly followers: KvKey$1;
240
- /**
241
- * The key prefix used for storing incoming follow requests.
242
- * @default `["_botkit", "followRequests"]`
243
- */
244
- readonly followRequests: KvKey$1;
245
- /**
246
- * The key prefix used for storing followees.
247
- * @default `["_botkit", "followees"]`
248
- */
249
- readonly followees: KvKey$1;
250
- /**
251
- * The key prefix used for storing outgoing follow requests.
252
- * @default `["_botkit", "follows"]`
253
- */
254
- readonly follows: KvKey$1;
255
- /**
256
- * The key prefix used for storing poll votes.
257
- * @default `["_botkit", "polls"]`
258
- * @since 0.3.0
259
- */
260
- readonly polls: KvKey$1;
471
+ readonly prefix?: KvKey$1;
261
472
  }
262
473
  /**
263
474
  * A repository for storing bot data using a key-value store.
264
475
  */
265
476
  declare class KvRepository implements Repository {
477
+ #private;
266
478
  readonly kv: KvStore$1;
267
- readonly prefixes: KvStoreRepositoryPrefixes;
479
+ /**
480
+ * The key prefix under which all BotKit data is stored.
481
+ * @since 0.5.0
482
+ */
483
+ readonly prefix: KvKey$1;
268
484
  /**
269
485
  * Creates a new key-value store repository.
270
486
  * @param kv The key-value store to use.
271
- * @param prefixes The prefixes for key-value store keys.
272
- */
273
- constructor(kv: KvStore$1, prefixes?: KvStoreRepositoryPrefixes);
274
- setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>;
275
- getKeyPairs(): Promise<CryptoKeyPair[] | undefined>;
276
- addMessage(id: Uuid, activity: Create$1 | Announce$1): Promise<void>;
277
- updateMessage(id: Uuid, updater: (existing: Create$1 | Announce$1) => Create$1 | Announce$1 | undefined | Promise<Create$1 | Announce$1 | undefined>): Promise<boolean>;
278
- removeMessage(id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
279
- getMessages(options?: RepositoryGetMessagesOptions): AsyncIterable<Create$1 | Announce$1>;
280
- getMessage(id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
281
- countMessages(): Promise<number>;
282
- addFollower(followRequestId: URL, follower: Actor): Promise<void>;
283
- removeFollower(followRequestId: URL, actorId: URL): Promise<Actor | undefined>;
284
- hasFollower(followerId: URL): Promise<boolean>;
285
- getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>;
286
- countFollowers(): Promise<number>;
287
- addSentFollow(id: Uuid, follow: Follow): Promise<void>;
288
- removeSentFollow(id: Uuid): Promise<Follow | undefined>;
289
- getSentFollow(id: Uuid): Promise<Follow | undefined>;
290
- addFollowee(followeeId: URL, follow: Follow): Promise<void>;
291
- removeFollowee(followeeId: URL): Promise<Follow | undefined>;
292
- getFollowee(followeeId: URL): Promise<Follow | undefined>;
293
- vote(messageId: Uuid, voterId: URL, option: string): Promise<void>;
294
- countVoters(messageId: Uuid): Promise<number>;
295
- countVotes(messageId: Uuid): Promise<Readonly<Record<string, number>>>;
487
+ * @param options The options for the repository.
488
+ */
489
+ constructor(kv: KvStore$1, options?: KvRepositoryOptions);
490
+ /**
491
+ * Migrates data stored by BotKit 0.4 or earlier, which was not scoped by
492
+ * bot actor identifiers, so that it belongs to the given identifier.
493
+ *
494
+ * The legacy data can be adopted by exactly one identifier. The adopter
495
+ * is claimed atomically (through a compare-and-set operation when the
496
+ * underlying store supports one) before anything is copied, so that
497
+ * reusing the repository for another bot, even concurrently, does not
498
+ * adopt the same rows again. Legacy keys are copied, not moved, and
499
+ * the completion is recorded last, so a partially failed run is simply
500
+ * retried by the adopter on the next call without data loss. Followees
501
+ * are also entered into the reverse lookup index used by
502
+ * {@link KvRepository.findFollowedBots}.
503
+ *
504
+ * Calling this method again after a successful migration is a no-op.
505
+ * @param identifier The identifier of the bot actor that adopts the legacy
506
+ * data.
507
+ * @since 0.5.0
508
+ */
509
+ migrate(identifier: string): Promise<void>;
510
+ setKeyPairs(identifier: string, keyPairs: CryptoKeyPair[]): Promise<void>;
511
+ getKeyPairs(identifier: string): Promise<CryptoKeyPair[] | undefined>;
512
+ addMessage(identifier: string, id: Uuid, activity: Create$1 | Announce$1): Promise<void>;
513
+ updateMessage(identifier: string, id: Uuid, updater: (existing: Create$1 | Announce$1) => Create$1 | Announce$1 | undefined | Promise<Create$1 | Announce$1 | undefined>): Promise<boolean>;
514
+ removeMessage(identifier: string, id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
515
+ getMessages(identifier: string, options?: RepositoryGetMessagesOptions): AsyncIterable<Create$1 | Announce$1>;
516
+ getMessage(identifier: string, id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
517
+ countMessages(identifier: string): Promise<number>;
518
+ addFollower(identifier: string, followRequestId: URL, follower: Actor): Promise<void>;
519
+ removeFollower(identifier: string, followRequestId: URL, actorId: URL): Promise<Actor | undefined>;
520
+ hasFollower(identifier: string, followerId: URL): Promise<boolean>;
521
+ getFollowers(identifier: string, options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>;
522
+ countFollowers(identifier: string): Promise<number>;
523
+ addSentFollow(identifier: string, id: Uuid, follow: Follow): Promise<void>;
524
+ removeSentFollow(identifier: string, id: Uuid): Promise<Follow | undefined>;
525
+ getSentFollow(identifier: string, id: Uuid): Promise<Follow | undefined>;
526
+ addFollowee(identifier: string, followeeId: URL, follow: Follow): Promise<void>;
527
+ removeFollowee(identifier: string, followeeId: URL): Promise<Follow | undefined>;
528
+ getFollowee(identifier: string, followeeId: URL): Promise<Follow | undefined>;
529
+ findFollowedBots(followeeId: URL): AsyncIterable<string>;
530
+ vote(identifier: string, messageId: Uuid, voterId: URL, option: string): Promise<void>;
531
+ countVoters(identifier: string, messageId: Uuid): Promise<number>;
532
+ countVotes(identifier: string, messageId: Uuid): Promise<Readonly<Record<string, number>>>;
533
+ forIdentifier(identifier: string): ActorScopedRepository;
296
534
  }
297
535
  /**
298
536
  * A repository for storing bot data in memory. This repository is not
299
537
  * persistent and is only suitable for testing or development.
300
538
  */
301
539
  declare class MemoryRepository implements Repository {
302
- keyPairs?: CryptoKeyPair[];
303
- messages: Map<Uuid, Create$1 | Announce$1>;
304
- followers: Map<string, Actor>;
305
- followRequests: Record<string, string>;
306
- sentFollows: Record<string, Follow>;
307
- followees: Record<string, Follow>;
308
- polls: Record<Uuid, Record<string, Set<string>>>;
309
- setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>;
310
- getKeyPairs(): Promise<CryptoKeyPair[] | undefined>;
311
- addMessage(id: Uuid, activity: Create$1 | Announce$1): Promise<void>;
312
- updateMessage(id: Uuid, updater: (existing: Create$1 | Announce$1) => Create$1 | Announce$1 | undefined | Promise<Create$1 | Announce$1 | undefined>): Promise<boolean>;
313
- removeMessage(id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
314
- getMessages(options?: RepositoryGetMessagesOptions): AsyncIterable<Create$1 | Announce$1>;
315
- getMessage(id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
316
- countMessages(): Promise<number>;
317
- addFollower(followId: URL, follower: Actor): Promise<void>;
318
- removeFollower(followId: URL, followerId: URL): Promise<Actor | undefined>;
319
- hasFollower(followerId: URL): Promise<boolean>;
320
- getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>;
321
- countFollowers(): Promise<number>;
322
- addSentFollow(id: Uuid, follow: Follow): Promise<void>;
323
- removeSentFollow(id: Uuid): Promise<Follow | undefined>;
324
- getSentFollow(id: Uuid): Promise<Follow | undefined>;
325
- addFollowee(followeeId: URL, follow: Follow): Promise<void>;
326
- removeFollowee(followeeId: URL): Promise<Follow | undefined>;
327
- getFollowee(followeeId: URL): Promise<Follow | undefined>;
328
- vote(messageId: Uuid, voterId: URL, option: string): Promise<void>;
329
- countVoters(messageId: Uuid): Promise<number>;
330
- countVotes(messageId: Uuid): Promise<Readonly<Record<string, number>>>;
540
+ #private;
541
+ setKeyPairs(identifier: string, keyPairs: CryptoKeyPair[]): Promise<void>;
542
+ getKeyPairs(identifier: string): Promise<CryptoKeyPair[] | undefined>;
543
+ addMessage(identifier: string, id: Uuid, activity: Create$1 | Announce$1): Promise<void>;
544
+ updateMessage(identifier: string, id: Uuid, updater: (existing: Create$1 | Announce$1) => Create$1 | Announce$1 | undefined | Promise<Create$1 | Announce$1 | undefined>): Promise<boolean>;
545
+ removeMessage(identifier: string, id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
546
+ getMessages(identifier: string, options?: RepositoryGetMessagesOptions): AsyncIterable<Create$1 | Announce$1>;
547
+ getMessage(identifier: string, id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
548
+ countMessages(identifier: string): Promise<number>;
549
+ addFollower(identifier: string, followId: URL, follower: Actor): Promise<void>;
550
+ removeFollower(identifier: string, followId: URL, followerId: URL): Promise<Actor | undefined>;
551
+ hasFollower(identifier: string, followerId: URL): Promise<boolean>;
552
+ getFollowers(identifier: string, options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>;
553
+ countFollowers(identifier: string): Promise<number>;
554
+ addSentFollow(identifier: string, id: Uuid, follow: Follow): Promise<void>;
555
+ removeSentFollow(identifier: string, id: Uuid): Promise<Follow | undefined>;
556
+ getSentFollow(identifier: string, id: Uuid): Promise<Follow | undefined>;
557
+ addFollowee(identifier: string, followeeId: URL, follow: Follow): Promise<void>;
558
+ removeFollowee(identifier: string, followeeId: URL): Promise<Follow | undefined>;
559
+ getFollowee(identifier: string, followeeId: URL): Promise<Follow | undefined>;
560
+ findFollowedBots(followeeId: URL): AsyncIterable<string>;
561
+ vote(identifier: string, messageId: Uuid, voterId: URL, option: string): Promise<void>;
562
+ countVoters(identifier: string, messageId: Uuid): Promise<number>;
563
+ countVotes(identifier: string, messageId: Uuid): Promise<Readonly<Record<string, number>>>;
564
+ forIdentifier(identifier: string): ActorScopedRepository;
331
565
  }
332
566
  /**
333
567
  * A repository decorator that adds an in-memory cache layer on top of another
@@ -335,9 +569,10 @@ declare class MemoryRepository implements Repository {
335
569
  * of accesses to the underlying persistent storage, but it increases memory
336
570
  * usage. The cache is not persistent and will be lost when the process exits.
337
571
  *
338
- * Note: List operations like `getMessages` and `getFollowers`, and count
339
- * operations like `countMessages` and `countFollowers` are not cached and
340
- * always delegate to the underlying repository.
572
+ * Note: List operations like `getMessages` and `getFollowers`, count
573
+ * operations like `countMessages` and `countFollowers`, and reverse lookups
574
+ * like `findFollowedBots` are not cached and always delegate to the
575
+ * underlying repository.
341
576
  * @since 0.3.0
342
577
  */
343
578
  declare class MemoryCachedRepository implements Repository {
@@ -350,30 +585,42 @@ declare class MemoryCachedRepository implements Repository {
350
585
  * If not provided, a new one will be created internally.
351
586
  */
352
587
  constructor(underlying: Repository, cache?: MemoryRepository);
353
- setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>;
354
- getKeyPairs(): Promise<CryptoKeyPair[] | undefined>;
355
- addMessage(id: Uuid, activity: Create$1 | Announce$1): Promise<void>;
356
- updateMessage(id: Uuid, updater: (existing: Create$1 | Announce$1) => Create$1 | Announce$1 | undefined | Promise<Create$1 | Announce$1 | undefined>): Promise<boolean>;
357
- removeMessage(id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
358
- getMessages(options?: RepositoryGetMessagesOptions): AsyncIterable<Create$1 | Announce$1>;
359
- getMessage(id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
360
- countMessages(): Promise<number>;
361
- addFollower(followId: URL, follower: Actor): Promise<void>;
362
- removeFollower(followId: URL, followerId: URL): Promise<Actor | undefined>;
363
- hasFollower(followerId: URL): Promise<boolean>;
364
- getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>;
365
- countFollowers(): Promise<number>;
366
- addSentFollow(id: Uuid, follow: Follow): Promise<void>;
367
- removeSentFollow(id: Uuid): Promise<Follow | undefined>;
368
- getSentFollow(id: Uuid): Promise<Follow | undefined>;
369
- addFollowee(followeeId: URL, follow: Follow): Promise<void>;
370
- removeFollowee(followeeId: URL): Promise<Follow | undefined>;
371
- getFollowee(followeeId: URL): Promise<Follow | undefined>;
372
- vote(messageId: Uuid, voterId: URL, option: string): Promise<void>;
373
- countVoters(messageId: Uuid): Promise<number>;
374
- countVotes(messageId: Uuid): Promise<Readonly<Record<string, number>>>;
588
+ setKeyPairs(identifier: string, keyPairs: CryptoKeyPair[]): Promise<void>;
589
+ getKeyPairs(identifier: string): Promise<CryptoKeyPair[] | undefined>;
590
+ addMessage(identifier: string, id: Uuid, activity: Create$1 | Announce$1): Promise<void>;
591
+ updateMessage(identifier: string, id: Uuid, updater: (existing: Create$1 | Announce$1) => Create$1 | Announce$1 | undefined | Promise<Create$1 | Announce$1 | undefined>): Promise<boolean>;
592
+ removeMessage(identifier: string, id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
593
+ getMessages(identifier: string, options?: RepositoryGetMessagesOptions): AsyncIterable<Create$1 | Announce$1>;
594
+ getMessage(identifier: string, id: Uuid): Promise<Create$1 | Announce$1 | undefined>;
595
+ countMessages(identifier: string): Promise<number>;
596
+ addFollower(identifier: string, followId: URL, follower: Actor): Promise<void>;
597
+ removeFollower(identifier: string, followId: URL, followerId: URL): Promise<Actor | undefined>;
598
+ hasFollower(identifier: string, followerId: URL): Promise<boolean>;
599
+ getFollowers(identifier: string, options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>;
600
+ countFollowers(identifier: string): Promise<number>;
601
+ addSentFollow(identifier: string, id: Uuid, follow: Follow): Promise<void>;
602
+ removeSentFollow(identifier: string, id: Uuid): Promise<Follow | undefined>;
603
+ getSentFollow(identifier: string, id: Uuid): Promise<Follow | undefined>;
604
+ addFollowee(identifier: string, followeeId: URL, follow: Follow): Promise<void>;
605
+ removeFollowee(identifier: string, followeeId: URL): Promise<Follow | undefined>;
606
+ getFollowee(identifier: string, followeeId: URL): Promise<Follow | undefined>;
607
+ findFollowedBots(followeeId: URL): AsyncIterable<string>;
608
+ vote(identifier: string, messageId: Uuid, voterId: URL, option: string): Promise<void>;
609
+ countVoters(identifier: string, messageId: Uuid): Promise<number>;
610
+ countVotes(identifier: string, messageId: Uuid): Promise<Readonly<Record<string, number>>>;
611
+ forIdentifier(identifier: string): ActorScopedRepository;
612
+ /**
613
+ * Migrates data stored by BotKit 0.4 or earlier in the underlying
614
+ * repository, so that it belongs to the given identifier. The cache is
615
+ * not involved: it starts empty and only ever holds values read after
616
+ * the migration.
617
+ * @param identifier The identifier of the bot actor that adopts the
618
+ * legacy data.
619
+ * @since 0.5.0
620
+ */
621
+ migrate(identifier: string): Promise<void>;
375
622
  }
376
623
  //# sourceMappingURL=repository.d.ts.map
377
624
  //#endregion
378
- export { Announce, Create, KvKey, KvRepository, KvStore, KvStoreRepositoryPrefixes, MemoryCachedRepository, MemoryRepository, Repository, RepositoryGetFollowersOptions, RepositoryGetMessagesOptions, Uuid };
625
+ export { ActorScopedRepository, Announce, Create, KvKey, KvRepository, KvRepositoryOptions, KvStore, MemoryCachedRepository, MemoryRepository, Repository, RepositoryGetFollowersOptions, RepositoryGetMessagesOptions, Uuid };
379
626
  //# sourceMappingURL=repository.d.ts.map