@fedify/botkit 0.3.0-dev.111 → 0.3.0-dev.112

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/dist/bot.d.ts CHANGED
@@ -3,7 +3,7 @@ Date.prototype.toTemporalInstant = toTemporalInstant;
3
3
  import { Text } from "./text.js";
4
4
  import { Session } from "./session.js";
5
5
  import { CustomEmoji, DeferredCustomEmoji } from "./emoji.js";
6
- import { AcceptEventHandler, FollowEventHandler, LikeEventHandler, MentionEventHandler, MessageEventHandler, QuoteEventHandler, ReactionEventHandler, RejectEventHandler, ReplyEventHandler, SharedMessageEventHandler, UndoneReactionEventHandler, UnfollowEventHandler, UnlikeEventHandler } from "./events.js";
6
+ import { AcceptEventHandler, FollowEventHandler, LikeEventHandler, MentionEventHandler, MessageEventHandler, QuoteEventHandler, ReactionEventHandler, RejectEventHandler, ReplyEventHandler, SharedMessageEventHandler, UndoneReactionEventHandler, UnfollowEventHandler, UnlikeEventHandler, VoteEventHandler } from "./events.js";
7
7
  import { Repository } from "./repository.js";
8
8
  import { Context, Federation, KvStore, MessageQueue } from "@fedify/fedify/federation";
9
9
  import { Application, Application as Application$1, Image, Image as Image$1, Service, Service as Service$1 } from "@fedify/fedify/vocab";
@@ -116,6 +116,20 @@ interface Bot<TContextData> {
116
116
  * @since 0.2.0
117
117
  */
118
118
  onUnreact?: UndoneReactionEventHandler<TContextData>;
119
+ /**
120
+ * An event handler for a vote in a poll. This event is only triggered when
121
+ * the bot is the author of the poll, and the vote is made by another actor.
122
+ * If the poll allows multiple selections, this event is triggered multiple
123
+ * times, once for each option selected by the actor.
124
+ *
125
+ * Note that this event can be triggered even if the voter vote an option
126
+ * multiple times or multiple options for a poll that disallows multiple
127
+ * selections. You should validate the vote in the event handler by storing
128
+ * the votes in a persistent store, and checking if the vote is valid.
129
+ * (This behavior can subject to change in the future.)
130
+ * @since 0.3.0
131
+ */
132
+ onVote?: VoteEventHandler<TContextData>;
119
133
  }
120
134
  /**
121
135
  * A specialized {@link Bot} tpe that doesn't require context data.
package/dist/bot.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bot.d.ts","names":[],"sources":["../src/bot.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;UAqDiB;EAAA;;;;EAKgB,SAgBZ,UAAA,EAhBE,UAgBF,CAhBa,YAgBb,CAAA;EAAG;;;EAEZ,SAOkB,UAAA,EAAA,MAAA;EAAY;;;;;;;;EAwBJ,UAAE,CAAA,MAAA,EAAA,MAAA,GAjCnB,GAiCmB,EAAA,WAAA,EAhCvB,YAgCuB,CAAA,EA/BnC,OA+BmC,CA/B3B,YA+B2B,CAAA;EAAW;;;;;EACC,UAAtC,CAAA,OAAA,EAzBQ,OAyBR,CAzBgB,YAyBhB,CAAA,CAAA,EAzBgC,OAyBhC,CAzBwC,YAyBxC,CAAA;EAAM;;;;;;;EAeiB,KAKC,CAAA,OAAA,EApCrB,OAoCqB,EAAA,WAAA,EApCC,YAoCD,CAAA,EApCgB,OAoChB,CApCwB,QAoCxB,CAAA;EAAY;;;;;;;;;;;;EAiCV,eAA7B,CAAA,mBAAA,MAAA,CAAA,CAAA,MAAA,EAtDC,QAsDD,CAtDU,MAsDV,CAtDiB,UAsDjB,EAtD6B,WAsD7B,CAAA,CAAA,CAAA,EArDN,QAqDM,CArDG,MAqDH,CArDU,UAqDV,EArDsB,mBAqDtB,CArD0C,YAqD1C,CAAA,CAAA,CAAA;EAAgB;;;EAWkB,QAAjC,CAAA,EA3DC,kBA2DD,CA3DoB,YA2DpB,CAAA;EAAoB;;AAMQ;EAMvB,UAAA,CAAA,EAlEF,oBAkEyB,CAlEJ,YAkEI,CAAA;EAAA;;;EAY5B,cAOU,CAAA,EAhFH,kBAgFG,CAhFgB,YAgFhB,CAAA;EAAO;;;EAQc,cAQ1B,CAAA,EA3FE,kBA2FF,CA3FqB,YA2FrB,CAAA;EAAO;;;EAnC2B,SAAA,CAAA,EAnDrC,mBAmDq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,CAAA,EA9NU,kBA8NV,CA9N6B,YA8N7B,CAAA;EAAY;;;AAA4C;YAxN/C,qBAAqB;;;;;cAMnB,2BAA2B;;;;;;;;;;;;;;WAe9B,iBAAiB;;;;;UAMX,sBAAA,SAA+B;;;;;;;;;8BAU3B,yBAEhB;;;;;;sBAOiB,gBAAgB;;;;;;;8BAQR,MAAM;;;;;;;iBAQnB,UAAU,QAAQ;;;;;UAMlB;;;;;;;;;;;;;;;0BAgBS,mBAAiB;;;;;;;;;;;;;qBAgBtB,cAAc;;;;kBAKjB,MAAM;;;;;mBAML,MAAM;;;;;wBAMD,eAAe,yBAAyB;;;;;;;;;;;;;;;eAiBjD;;;;;wBAMS;;;;;;mBAOL;;;;;sBAMG;;;;;;;;;;;;;mBAeH;;;;;UAMF,YAAA;;;;;;;;;;;;;;;;;;iBAwCD,wCACL,iBAAiB,gBACzB,4BAA4B,yBAAyB,IAAI"}
package/dist/bot.js CHANGED
@@ -108,6 +108,12 @@ function createBot(options) {
108
108
  },
109
109
  set onUnreact(value) {
110
110
  bot.onUnreact = value;
111
+ },
112
+ get onVote() {
113
+ return bot.onVote;
114
+ },
115
+ set onVote(value) {
116
+ bot.onVote = value;
111
117
  }
112
118
  };
113
119
  return wrapper;
package/dist/bot.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bot.js","names":["options: CreateBotOptions<TContextData>","b?","emojis: Readonly<Record<TEmojiName, CustomEmoji>>"],"sources":["../src/bot.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport type {\n Context,\n Federation,\n KvStore,\n MessageQueue,\n} from \"@fedify/fedify/federation\";\nimport type { Software } from \"@fedify/fedify/nodeinfo\";\nimport type { Application, Image, Service } from \"@fedify/fedify/vocab\";\nimport { BotImpl } from \"./bot-impl.ts\";\nimport type { CustomEmoji, DeferredCustomEmoji } from \"./emoji.ts\";\nimport type {\n AcceptEventHandler,\n FollowEventHandler,\n LikeEventHandler,\n MentionEventHandler,\n MessageEventHandler,\n QuoteEventHandler,\n ReactionEventHandler,\n RejectEventHandler,\n ReplyEventHandler,\n SharedMessageEventHandler,\n UndoneReactionEventHandler,\n UnfollowEventHandler,\n UnlikeEventHandler,\n} from \"./events.ts\";\nimport type { Repository } from \"./repository.ts\";\nimport type { Session } from \"./session.ts\";\nimport type { Text } from \"./text.ts\";\nexport {\n parseSemVer,\n type SemVer,\n type Software,\n} from \"@fedify/fedify/nodeinfo\";\nexport { Application, Image, Service } from \"@fedify/fedify/vocab\";\n\n/**\n * A bot that can interact with the ActivityPub network.\n */\nexport interface Bot<TContextData> {\n /**\n * An internal Fedify federation instance. Normally you don't need to access\n * this directly.\n */\n readonly federation: Federation<TContextData>;\n\n /**\n * The internal identifier for the bot actor. It is used for the actor URI.\n */\n readonly identifier: string;\n\n /**\n * Gets a new session to control the bot for a specific origin and context\n * data.\n * @param origin The origin of the session. Even if a URL with some path or\n * query is passed, only the origin part will be used.\n * @param contextData The context data to pass to the federation.\n * @returns The session for the origin and context data.\n */\n getSession(\n origin: string | URL,\n contextData: TContextData,\n ): Session<TContextData>;\n\n /**\n * Gets a new session to control bot for a specific Fedify context.\n * @param context The Fedify context of the session.\n * @returns The session for the Fedify context.\n */\n getSession(context: Context<TContextData>): Session<TContextData>;\n\n /**\n * The fetch API for handling HTTP requests. You can pass this to an HTTP\n * server (e.g., `Deno.serve()`, `Bun.serve()`) to handle incoming requests.\n * @param request The request to handle.\n * @param contextData The context data to pass to the federation.\n * @returns The response to the request.\n */\n fetch(request: Request, contextData: TContextData): Promise<Response>;\n\n /**\n * Defines custom emojis for the bot. The custom emojis are used for\n * rendering the bot's profile and posts. The custom emojis are defined\n * by their names, and the names are used as the keys of the emojis.\n * @param emojis The custom emojis to define. The keys are the names of\n * the emojis, and the values are the custom emoji definitions.\n * @returns The defined emojis. The keys are the names of the emojis, and\n * the values are the emoji objects, which are used for passing\n * to the {@link customEmoji} function.\n * @throws {TypeError} If any emoji name is invalid or duplicate.\n * @since 0.2.0\n */\n addCustomEmojis<TEmojiName extends string>(\n emojis: Readonly<Record<TEmojiName, CustomEmoji>>,\n ): Readonly<Record<TEmojiName, DeferredCustomEmoji<TContextData>>>;\n\n /**\n * An event handler for a follow request to the bot.\n */\n onFollow?: FollowEventHandler<TContextData>;\n\n /**\n * An event handler for an unfollow event from the bot.\n */\n onUnfollow?: UnfollowEventHandler<TContextData>;\n\n /**\n * An event handler invoked when a follow request the bot sent is accepted.\n */\n onAcceptFollow?: AcceptEventHandler<TContextData>;\n\n /**\n * An event handler invoked when a follow request the bot sent is rejected.\n */\n onRejectFollow?: RejectEventHandler<TContextData>;\n\n /**\n * An event handler for a message mentioned to the bot.\n */\n onMention?: MentionEventHandler<TContextData>;\n\n /**\n * An event handler for a reply to the bot.\n */\n onReply?: ReplyEventHandler<TContextData>;\n\n /**\n * An event handler for a quote of the bot's message.\n * @since 0.2.0\n */\n onQuote?: QuoteEventHandler<TContextData>;\n\n /**\n * An event handler for a message shown to the bot's timeline. To listen\n * to this event, your bot needs to follow others first.\n */\n onMessage?: MessageEventHandler<TContextData>;\n\n /**\n * An event handler for a message shared to the bot. To listen to this event,\n * your bot needs to follow others first.\n */\n onSharedMessage?: SharedMessageEventHandler<TContextData>;\n\n /**\n * An event handler for a like of a message.\n */\n onLike?: LikeEventHandler<TContextData>;\n\n /**\n * An event handler for an undoing of a like of a message.\n */\n onUnlike?: UnlikeEventHandler<TContextData>;\n\n /**\n * An event handler for an emoji reaction to a message.\n * @since 0.2.0\n */\n onReact?: ReactionEventHandler<TContextData>;\n\n /**\n * An event handler for an undoing of an emoji reaction to a message.\n * @since 0.2.0\n */\n onUnreact?: UndoneReactionEventHandler<TContextData>;\n}\n\n/**\n * A specialized {@link Bot} tpe that doesn't require context data.\n */\nexport interface BotWithVoidContextData extends Bot<void> {\n /**\n * Gets a new session to control the bot for a specific origin and context\n * data.\n * @param origin The origin of the session. Even if a URL with some path or\n * query is passed, only the origin part will be used.\n * @param contextData The context data to pass to the federation.\n * @returns The session for the origin and context data.\n */\n getSession(\n origin: string | URL,\n contextData: void,\n ): Session<void>;\n\n /**\n * Gets a new session to control bot for a specific Fedify context.\n * @param context The Fedify context of the session.\n * @returns The session for the Fedify context.\n */\n getSession(context: Context<void>): Session<void>;\n\n /**\n * Gets a new session to control the bot for a specific origin and context\n * data.\n * @param origin The origin of the session. Even if a URL with some path or\n * query is passed, only the origin part will be used.\n */\n getSession(origin: string | URL): Session<void>;\n\n /**\n * The fetch API for handling HTTP requests. You can pass this to an HTTP\n * server (e.g., `Deno.serve()`, `Bun.serve()`) to handle incoming requests.\n * @param request The request to handle.\n * @returns The response to the request.\n */\n fetch(request: Request): Promise<Response>;\n}\n\n/**\n * Options for creating a bot.\n */\nexport interface CreateBotOptions<TContextData> {\n /**\n * The internal identifier of the bot. Since it is used for the actor URI,\n * it *should not* be changed after the bot is federated.\n *\n * If omitted, `\"bot\"` will be used.\n * @default `\"bot\"`\n */\n readonly identifier?: string;\n\n /**\n * The type of the bot actor. It should be either `Service` or `Application`.\n *\n * If omitted, `Service` will be used.\n * @default `Service`\n */\n readonly class?: typeof Service | typeof Application;\n\n /**\n * The username of the bot. It will be a part of the fediverse handle.\n * It can be changed after the bot is federated.\n */\n readonly username: string;\n\n /**\n * The display name of the bot. It can be changed after the bot is federated.\n */\n readonly name?: string;\n\n /**\n * The description of the bot. It can be changed after the bot is federated.\n */\n readonly summary?: Text<\"block\", TContextData>;\n\n /**\n * The avatar URL of the bot. It can be changed after the bot is federated.\n */\n readonly icon?: URL | Image;\n\n /**\n * The header image URL of the bot. It can be changed after the bot is\n * federated.\n */\n readonly image?: URL | Image;\n\n /**\n * The custom properties of the bot. It can be changed after the bot is\n * federated.\n */\n readonly properties?: Record<string, Text<\"block\" | \"inline\", TContextData>>;\n\n /**\n * How to handle incoming follow requests. Note that this behavior can be\n * overridden by manually invoking {@link FollowRequest.accept} or\n * {@link FollowRequest.reject} in the {@link Bot.onFollow} event handler.\n *\n * - `\"accept\"` (default): Automatically accept all incoming follow requests.\n * - `\"reject\"`: Automatically reject all incoming follow requests.\n * - `\"manual\"`: Require manual handling of incoming follow requests.\n * @default `\"accept\"`\n */\n readonly followerPolicy?: \"accept\" | \"reject\" | \"manual\";\n\n /**\n * The underlying key-value store to use for storing data.\n */\n readonly kv: KvStore;\n\n /**\n * The underlying repository to use for storing data. If omitted,\n * {@link KvRepository} will be used.\n */\n readonly repository?: Repository;\n\n /**\n * The underlying message queue to use for handling incoming and outgoing\n * activities. If omitted, incoming activities are processed immediately,\n * and outgoing activities are sent immediately.\n */\n readonly queue?: MessageQueue;\n\n /**\n * The software information of the bot. If omitted, the NodeInfo protocol\n * will be unimplemented.\n */\n readonly software?: Software;\n\n /**\n * Whether to trust `X-Forwarded-*` headers. If your bot application is\n * behind an L7 reverse proxy, turn it on.\n *\n * Turned off by default.\n * @default `false`\n */\n readonly behindProxy?: boolean;\n\n /**\n * The options for the web pages of the bot. If omitted, the default options\n * will be used.\n */\n readonly pages?: PagesOptions;\n}\n\n/**\n * Options for the web pages of the bot.\n */\nexport interface PagesOptions {\n /**\n * The color of the theme. It will be used for the theme color of the web\n * pages. The default color is `\"green\"`.\n * @default `\"green\"`\n */\n readonly color?:\n | \"amber\"\n | \"azure\"\n | \"blue\"\n | \"cyan\"\n | \"fuchsia\"\n | \"green\"\n | \"grey\"\n | \"indigo\"\n | \"jade\"\n | \"lime\"\n | \"orange\"\n | \"pink\"\n | \"pumpkin\"\n | \"purple\"\n | \"red\"\n | \"sand\"\n | \"slate\"\n | \"violet\"\n | \"yellow\"\n | \"zinc\";\n\n /**\n * The CSS code for the bot. It will be used for the custom CSS of the web\n * pages.\n */\n readonly css?: string;\n}\n\n/**\n * Creates a {@link Bot} instance.\n * @param options The options for creating the bot.\n * @returns The created bot instance.\n */\nexport function createBot<TContextData = void>(\n options: CreateBotOptions<TContextData>,\n): TContextData extends void ? BotWithVoidContextData : Bot<TContextData> {\n const bot = new BotImpl<TContextData>(options);\n // Since `deno serve` does not recognize a class instance having fetch(),\n // we wrap a BotImpl instance with a plain object.\n // See also https://github.com/denoland/deno/issues/24062\n const wrapper = {\n impl: bot,\n get federation() {\n return bot.federation;\n },\n get identifier() {\n return bot.identifier;\n },\n getSession(a, b?) {\n // @ts-ignore: BotImpl.getSession() implements Bot.getSession()\n return bot.getSession(a, b);\n },\n fetch(request, contextData) {\n return bot.fetch(request, contextData);\n },\n addCustomEmojis<TEmojiName extends string>(\n emojis: Readonly<Record<TEmojiName, CustomEmoji>>,\n ): Readonly<Record<TEmojiName, DeferredCustomEmoji<TContextData>>> {\n return bot.addCustomEmojis(emojis);\n },\n get onFollow() {\n return bot.onFollow;\n },\n set onFollow(value) {\n bot.onFollow = value;\n },\n get onUnfollow() {\n return bot.onUnfollow;\n },\n set onUnfollow(value) {\n bot.onUnfollow = value;\n },\n get onAcceptFollow() {\n return bot.onAcceptFollow;\n },\n set onAcceptFollow(value) {\n bot.onAcceptFollow = value;\n },\n get onRejectFollow() {\n return bot.onRejectFollow;\n },\n set onRejectFollow(value) {\n bot.onRejectFollow = value;\n },\n get onMention() {\n return bot.onMention;\n },\n set onMention(value) {\n bot.onMention = value;\n },\n get onReply() {\n return bot.onReply;\n },\n set onReply(value) {\n bot.onReply = value;\n },\n get onQuote() {\n return bot.onQuote;\n },\n set onQuote(value) {\n bot.onQuote = value;\n },\n get onMessage() {\n return bot.onMessage;\n },\n set onMessage(value) {\n bot.onMessage = value;\n },\n get onSharedMessage() {\n return bot.onSharedMessage;\n },\n set onSharedMessage(value) {\n bot.onSharedMessage = value;\n },\n get onLike() {\n return bot.onLike;\n },\n set onLike(value) {\n bot.onLike = value;\n },\n get onUnlike() {\n return bot.onUnlike;\n },\n set onUnlike(value) {\n bot.onUnlike = value;\n },\n get onReact() {\n return bot.onReact;\n },\n set onReact(value) {\n bot.onReact = value;\n },\n get onUnreact() {\n return bot.onUnreact;\n },\n set onUnreact(value) {\n bot.onUnreact = value;\n },\n } satisfies Bot<TContextData> & { impl: BotImpl<TContextData> };\n // @ts-ignore: the wrapper implements BotWithVoidContextData\n return wrapper;\n}\n"],"mappings":";;;;;;;;;;;;;;AAmXA,SAAgB,UACdA,SACwE;CACxE,MAAM,MAAM,IAAI,QAAsB;CAItC,MAAM,UAAU;EACd,MAAM;EACN,IAAI,aAAa;AACf,UAAO,IAAI;EACZ;EACD,IAAI,aAAa;AACf,UAAO,IAAI;EACZ;EACD,WAAW,GAAGC,GAAI;AAEhB,UAAO,IAAI,WAAW,GAAG,EAAE;EAC5B;EACD,MAAM,SAAS,aAAa;AAC1B,UAAO,IAAI,MAAM,SAAS,YAAY;EACvC;EACD,gBACEC,QACiE;AACjE,UAAO,IAAI,gBAAgB,OAAO;EACnC;EACD,IAAI,WAAW;AACb,UAAO,IAAI;EACZ;EACD,IAAI,SAAS,OAAO;AAClB,OAAI,WAAW;EAChB;EACD,IAAI,aAAa;AACf,UAAO,IAAI;EACZ;EACD,IAAI,WAAW,OAAO;AACpB,OAAI,aAAa;EAClB;EACD,IAAI,iBAAiB;AACnB,UAAO,IAAI;EACZ;EACD,IAAI,eAAe,OAAO;AACxB,OAAI,iBAAiB;EACtB;EACD,IAAI,iBAAiB;AACnB,UAAO,IAAI;EACZ;EACD,IAAI,eAAe,OAAO;AACxB,OAAI,iBAAiB;EACtB;EACD,IAAI,YAAY;AACd,UAAO,IAAI;EACZ;EACD,IAAI,UAAU,OAAO;AACnB,OAAI,YAAY;EACjB;EACD,IAAI,UAAU;AACZ,UAAO,IAAI;EACZ;EACD,IAAI,QAAQ,OAAO;AACjB,OAAI,UAAU;EACf;EACD,IAAI,UAAU;AACZ,UAAO,IAAI;EACZ;EACD,IAAI,QAAQ,OAAO;AACjB,OAAI,UAAU;EACf;EACD,IAAI,YAAY;AACd,UAAO,IAAI;EACZ;EACD,IAAI,UAAU,OAAO;AACnB,OAAI,YAAY;EACjB;EACD,IAAI,kBAAkB;AACpB,UAAO,IAAI;EACZ;EACD,IAAI,gBAAgB,OAAO;AACzB,OAAI,kBAAkB;EACvB;EACD,IAAI,SAAS;AACX,UAAO,IAAI;EACZ;EACD,IAAI,OAAO,OAAO;AAChB,OAAI,SAAS;EACd;EACD,IAAI,WAAW;AACb,UAAO,IAAI;EACZ;EACD,IAAI,SAAS,OAAO;AAClB,OAAI,WAAW;EAChB;EACD,IAAI,UAAU;AACZ,UAAO,IAAI;EACZ;EACD,IAAI,QAAQ,OAAO;AACjB,OAAI,UAAU;EACf;EACD,IAAI,YAAY;AACd,UAAO,IAAI;EACZ;EACD,IAAI,UAAU,OAAO;AACnB,OAAI,YAAY;EACjB;CACF;AAED,QAAO;AACR"}
1
+ {"version":3,"file":"bot.js","names":["options: CreateBotOptions<TContextData>","b?","emojis: Readonly<Record<TEmojiName, CustomEmoji>>"],"sources":["../src/bot.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport type {\n Context,\n Federation,\n KvStore,\n MessageQueue,\n} from \"@fedify/fedify/federation\";\nimport type { Software } from \"@fedify/fedify/nodeinfo\";\nimport type { Application, Image, Service } from \"@fedify/fedify/vocab\";\nimport { BotImpl } from \"./bot-impl.ts\";\nimport type { CustomEmoji, DeferredCustomEmoji } from \"./emoji.ts\";\nimport type {\n AcceptEventHandler,\n FollowEventHandler,\n LikeEventHandler,\n MentionEventHandler,\n MessageEventHandler,\n QuoteEventHandler,\n ReactionEventHandler,\n RejectEventHandler,\n ReplyEventHandler,\n SharedMessageEventHandler,\n UndoneReactionEventHandler,\n UnfollowEventHandler,\n UnlikeEventHandler,\n VoteEventHandler,\n} from \"./events.ts\";\nimport type { Repository } from \"./repository.ts\";\nimport type { Session } from \"./session.ts\";\nimport type { Text } from \"./text.ts\";\nexport {\n parseSemVer,\n type SemVer,\n type Software,\n} from \"@fedify/fedify/nodeinfo\";\nexport { Application, Image, Service } from \"@fedify/fedify/vocab\";\n\n/**\n * A bot that can interact with the ActivityPub network.\n */\nexport interface Bot<TContextData> {\n /**\n * An internal Fedify federation instance. Normally you don't need to access\n * this directly.\n */\n readonly federation: Federation<TContextData>;\n\n /**\n * The internal identifier for the bot actor. It is used for the actor URI.\n */\n readonly identifier: string;\n\n /**\n * Gets a new session to control the bot for a specific origin and context\n * data.\n * @param origin The origin of the session. Even if a URL with some path or\n * query is passed, only the origin part will be used.\n * @param contextData The context data to pass to the federation.\n * @returns The session for the origin and context data.\n */\n getSession(\n origin: string | URL,\n contextData: TContextData,\n ): Session<TContextData>;\n\n /**\n * Gets a new session to control bot for a specific Fedify context.\n * @param context The Fedify context of the session.\n * @returns The session for the Fedify context.\n */\n getSession(context: Context<TContextData>): Session<TContextData>;\n\n /**\n * The fetch API for handling HTTP requests. You can pass this to an HTTP\n * server (e.g., `Deno.serve()`, `Bun.serve()`) to handle incoming requests.\n * @param request The request to handle.\n * @param contextData The context data to pass to the federation.\n * @returns The response to the request.\n */\n fetch(request: Request, contextData: TContextData): Promise<Response>;\n\n /**\n * Defines custom emojis for the bot. The custom emojis are used for\n * rendering the bot's profile and posts. The custom emojis are defined\n * by their names, and the names are used as the keys of the emojis.\n * @param emojis The custom emojis to define. The keys are the names of\n * the emojis, and the values are the custom emoji definitions.\n * @returns The defined emojis. The keys are the names of the emojis, and\n * the values are the emoji objects, which are used for passing\n * to the {@link customEmoji} function.\n * @throws {TypeError} If any emoji name is invalid or duplicate.\n * @since 0.2.0\n */\n addCustomEmojis<TEmojiName extends string>(\n emojis: Readonly<Record<TEmojiName, CustomEmoji>>,\n ): Readonly<Record<TEmojiName, DeferredCustomEmoji<TContextData>>>;\n\n /**\n * An event handler for a follow request to the bot.\n */\n onFollow?: FollowEventHandler<TContextData>;\n\n /**\n * An event handler for an unfollow event from the bot.\n */\n onUnfollow?: UnfollowEventHandler<TContextData>;\n\n /**\n * An event handler invoked when a follow request the bot sent is accepted.\n */\n onAcceptFollow?: AcceptEventHandler<TContextData>;\n\n /**\n * An event handler invoked when a follow request the bot sent is rejected.\n */\n onRejectFollow?: RejectEventHandler<TContextData>;\n\n /**\n * An event handler for a message mentioned to the bot.\n */\n onMention?: MentionEventHandler<TContextData>;\n\n /**\n * An event handler for a reply to the bot.\n */\n onReply?: ReplyEventHandler<TContextData>;\n\n /**\n * An event handler for a quote of the bot's message.\n * @since 0.2.0\n */\n onQuote?: QuoteEventHandler<TContextData>;\n\n /**\n * An event handler for a message shown to the bot's timeline. To listen\n * to this event, your bot needs to follow others first.\n */\n onMessage?: MessageEventHandler<TContextData>;\n\n /**\n * An event handler for a message shared to the bot. To listen to this event,\n * your bot needs to follow others first.\n */\n onSharedMessage?: SharedMessageEventHandler<TContextData>;\n\n /**\n * An event handler for a like of a message.\n */\n onLike?: LikeEventHandler<TContextData>;\n\n /**\n * An event handler for an undoing of a like of a message.\n */\n onUnlike?: UnlikeEventHandler<TContextData>;\n\n /**\n * An event handler for an emoji reaction to a message.\n * @since 0.2.0\n */\n onReact?: ReactionEventHandler<TContextData>;\n\n /**\n * An event handler for an undoing of an emoji reaction to a message.\n * @since 0.2.0\n */\n onUnreact?: UndoneReactionEventHandler<TContextData>;\n\n /**\n * An event handler for a vote in a poll. This event is only triggered when\n * the bot is the author of the poll, and the vote is made by another actor.\n * If the poll allows multiple selections, this event is triggered multiple\n * times, once for each option selected by the actor.\n *\n * Note that this event can be triggered even if the voter vote an option\n * multiple times or multiple options for a poll that disallows multiple\n * selections. You should validate the vote in the event handler by storing\n * the votes in a persistent store, and checking if the vote is valid.\n * (This behavior can subject to change in the future.)\n * @since 0.3.0\n */\n onVote?: VoteEventHandler<TContextData>;\n}\n\n/**\n * A specialized {@link Bot} tpe that doesn't require context data.\n */\nexport interface BotWithVoidContextData extends Bot<void> {\n /**\n * Gets a new session to control the bot for a specific origin and context\n * data.\n * @param origin The origin of the session. Even if a URL with some path or\n * query is passed, only the origin part will be used.\n * @param contextData The context data to pass to the federation.\n * @returns The session for the origin and context data.\n */\n getSession(\n origin: string | URL,\n contextData: void,\n ): Session<void>;\n\n /**\n * Gets a new session to control bot for a specific Fedify context.\n * @param context The Fedify context of the session.\n * @returns The session for the Fedify context.\n */\n getSession(context: Context<void>): Session<void>;\n\n /**\n * Gets a new session to control the bot for a specific origin and context\n * data.\n * @param origin The origin of the session. Even if a URL with some path or\n * query is passed, only the origin part will be used.\n */\n getSession(origin: string | URL): Session<void>;\n\n /**\n * The fetch API for handling HTTP requests. You can pass this to an HTTP\n * server (e.g., `Deno.serve()`, `Bun.serve()`) to handle incoming requests.\n * @param request The request to handle.\n * @returns The response to the request.\n */\n fetch(request: Request): Promise<Response>;\n}\n\n/**\n * Options for creating a bot.\n */\nexport interface CreateBotOptions<TContextData> {\n /**\n * The internal identifier of the bot. Since it is used for the actor URI,\n * it *should not* be changed after the bot is federated.\n *\n * If omitted, `\"bot\"` will be used.\n * @default `\"bot\"`\n */\n readonly identifier?: string;\n\n /**\n * The type of the bot actor. It should be either `Service` or `Application`.\n *\n * If omitted, `Service` will be used.\n * @default `Service`\n */\n readonly class?: typeof Service | typeof Application;\n\n /**\n * The username of the bot. It will be a part of the fediverse handle.\n * It can be changed after the bot is federated.\n */\n readonly username: string;\n\n /**\n * The display name of the bot. It can be changed after the bot is federated.\n */\n readonly name?: string;\n\n /**\n * The description of the bot. It can be changed after the bot is federated.\n */\n readonly summary?: Text<\"block\", TContextData>;\n\n /**\n * The avatar URL of the bot. It can be changed after the bot is federated.\n */\n readonly icon?: URL | Image;\n\n /**\n * The header image URL of the bot. It can be changed after the bot is\n * federated.\n */\n readonly image?: URL | Image;\n\n /**\n * The custom properties of the bot. It can be changed after the bot is\n * federated.\n */\n readonly properties?: Record<string, Text<\"block\" | \"inline\", TContextData>>;\n\n /**\n * How to handle incoming follow requests. Note that this behavior can be\n * overridden by manually invoking {@link FollowRequest.accept} or\n * {@link FollowRequest.reject} in the {@link Bot.onFollow} event handler.\n *\n * - `\"accept\"` (default): Automatically accept all incoming follow requests.\n * - `\"reject\"`: Automatically reject all incoming follow requests.\n * - `\"manual\"`: Require manual handling of incoming follow requests.\n * @default `\"accept\"`\n */\n readonly followerPolicy?: \"accept\" | \"reject\" | \"manual\";\n\n /**\n * The underlying key-value store to use for storing data.\n */\n readonly kv: KvStore;\n\n /**\n * The underlying repository to use for storing data. If omitted,\n * {@link KvRepository} will be used.\n */\n readonly repository?: Repository;\n\n /**\n * The underlying message queue to use for handling incoming and outgoing\n * activities. If omitted, incoming activities are processed immediately,\n * and outgoing activities are sent immediately.\n */\n readonly queue?: MessageQueue;\n\n /**\n * The software information of the bot. If omitted, the NodeInfo protocol\n * will be unimplemented.\n */\n readonly software?: Software;\n\n /**\n * Whether to trust `X-Forwarded-*` headers. If your bot application is\n * behind an L7 reverse proxy, turn it on.\n *\n * Turned off by default.\n * @default `false`\n */\n readonly behindProxy?: boolean;\n\n /**\n * The options for the web pages of the bot. If omitted, the default options\n * will be used.\n */\n readonly pages?: PagesOptions;\n}\n\n/**\n * Options for the web pages of the bot.\n */\nexport interface PagesOptions {\n /**\n * The color of the theme. It will be used for the theme color of the web\n * pages. The default color is `\"green\"`.\n * @default `\"green\"`\n */\n readonly color?:\n | \"amber\"\n | \"azure\"\n | \"blue\"\n | \"cyan\"\n | \"fuchsia\"\n | \"green\"\n | \"grey\"\n | \"indigo\"\n | \"jade\"\n | \"lime\"\n | \"orange\"\n | \"pink\"\n | \"pumpkin\"\n | \"purple\"\n | \"red\"\n | \"sand\"\n | \"slate\"\n | \"violet\"\n | \"yellow\"\n | \"zinc\";\n\n /**\n * The CSS code for the bot. It will be used for the custom CSS of the web\n * pages.\n */\n readonly css?: string;\n}\n\n/**\n * Creates a {@link Bot} instance.\n * @param options The options for creating the bot.\n * @returns The created bot instance.\n */\nexport function createBot<TContextData = void>(\n options: CreateBotOptions<TContextData>,\n): TContextData extends void ? BotWithVoidContextData : Bot<TContextData> {\n const bot = new BotImpl<TContextData>(options);\n // Since `deno serve` does not recognize a class instance having fetch(),\n // we wrap a BotImpl instance with a plain object.\n // See also https://github.com/denoland/deno/issues/24062\n const wrapper = {\n impl: bot,\n get federation() {\n return bot.federation;\n },\n get identifier() {\n return bot.identifier;\n },\n getSession(a, b?) {\n // @ts-ignore: BotImpl.getSession() implements Bot.getSession()\n return bot.getSession(a, b);\n },\n fetch(request, contextData) {\n return bot.fetch(request, contextData);\n },\n addCustomEmojis<TEmojiName extends string>(\n emojis: Readonly<Record<TEmojiName, CustomEmoji>>,\n ): Readonly<Record<TEmojiName, DeferredCustomEmoji<TContextData>>> {\n return bot.addCustomEmojis(emojis);\n },\n get onFollow() {\n return bot.onFollow;\n },\n set onFollow(value) {\n bot.onFollow = value;\n },\n get onUnfollow() {\n return bot.onUnfollow;\n },\n set onUnfollow(value) {\n bot.onUnfollow = value;\n },\n get onAcceptFollow() {\n return bot.onAcceptFollow;\n },\n set onAcceptFollow(value) {\n bot.onAcceptFollow = value;\n },\n get onRejectFollow() {\n return bot.onRejectFollow;\n },\n set onRejectFollow(value) {\n bot.onRejectFollow = value;\n },\n get onMention() {\n return bot.onMention;\n },\n set onMention(value) {\n bot.onMention = value;\n },\n get onReply() {\n return bot.onReply;\n },\n set onReply(value) {\n bot.onReply = value;\n },\n get onQuote() {\n return bot.onQuote;\n },\n set onQuote(value) {\n bot.onQuote = value;\n },\n get onMessage() {\n return bot.onMessage;\n },\n set onMessage(value) {\n bot.onMessage = value;\n },\n get onSharedMessage() {\n return bot.onSharedMessage;\n },\n set onSharedMessage(value) {\n bot.onSharedMessage = value;\n },\n get onLike() {\n return bot.onLike;\n },\n set onLike(value) {\n bot.onLike = value;\n },\n get onUnlike() {\n return bot.onUnlike;\n },\n set onUnlike(value) {\n bot.onUnlike = value;\n },\n get onReact() {\n return bot.onReact;\n },\n set onReact(value) {\n bot.onReact = value;\n },\n get onUnreact() {\n return bot.onUnreact;\n },\n set onUnreact(value) {\n bot.onUnreact = value;\n },\n get onVote() {\n return bot.onVote;\n },\n set onVote(value) {\n bot.onVote = value;\n },\n } satisfies Bot<TContextData> & { impl: BotImpl<TContextData> };\n // @ts-ignore: the wrapper implements BotWithVoidContextData\n return wrapper;\n}\n"],"mappings":";;;;;;;;;;;;;;AAmYA,SAAgB,UACdA,SACwE;CACxE,MAAM,MAAM,IAAI,QAAsB;CAItC,MAAM,UAAU;EACd,MAAM;EACN,IAAI,aAAa;AACf,UAAO,IAAI;EACZ;EACD,IAAI,aAAa;AACf,UAAO,IAAI;EACZ;EACD,WAAW,GAAGC,GAAI;AAEhB,UAAO,IAAI,WAAW,GAAG,EAAE;EAC5B;EACD,MAAM,SAAS,aAAa;AAC1B,UAAO,IAAI,MAAM,SAAS,YAAY;EACvC;EACD,gBACEC,QACiE;AACjE,UAAO,IAAI,gBAAgB,OAAO;EACnC;EACD,IAAI,WAAW;AACb,UAAO,IAAI;EACZ;EACD,IAAI,SAAS,OAAO;AAClB,OAAI,WAAW;EAChB;EACD,IAAI,aAAa;AACf,UAAO,IAAI;EACZ;EACD,IAAI,WAAW,OAAO;AACpB,OAAI,aAAa;EAClB;EACD,IAAI,iBAAiB;AACnB,UAAO,IAAI;EACZ;EACD,IAAI,eAAe,OAAO;AACxB,OAAI,iBAAiB;EACtB;EACD,IAAI,iBAAiB;AACnB,UAAO,IAAI;EACZ;EACD,IAAI,eAAe,OAAO;AACxB,OAAI,iBAAiB;EACtB;EACD,IAAI,YAAY;AACd,UAAO,IAAI;EACZ;EACD,IAAI,UAAU,OAAO;AACnB,OAAI,YAAY;EACjB;EACD,IAAI,UAAU;AACZ,UAAO,IAAI;EACZ;EACD,IAAI,QAAQ,OAAO;AACjB,OAAI,UAAU;EACf;EACD,IAAI,UAAU;AACZ,UAAO,IAAI;EACZ;EACD,IAAI,QAAQ,OAAO;AACjB,OAAI,UAAU;EACf;EACD,IAAI,YAAY;AACd,UAAO,IAAI;EACZ;EACD,IAAI,UAAU,OAAO;AACnB,OAAI,YAAY;EACjB;EACD,IAAI,kBAAkB;AACpB,UAAO,IAAI;EACZ;EACD,IAAI,gBAAgB,OAAO;AACzB,OAAI,kBAAkB;EACvB;EACD,IAAI,SAAS;AACX,UAAO,IAAI;EACZ;EACD,IAAI,OAAO,OAAO;AAChB,OAAI,SAAS;EACd;EACD,IAAI,WAAW;AACb,UAAO,IAAI;EACZ;EACD,IAAI,SAAS,OAAO;AAClB,OAAI,WAAW;EAChB;EACD,IAAI,UAAU;AACZ,UAAO,IAAI;EACZ;EACD,IAAI,QAAQ,OAAO;AACjB,OAAI,UAAU;EACf;EACD,IAAI,YAAY;AACd,UAAO,IAAI;EACZ;EACD,IAAI,UAAU,OAAO;AACnB,OAAI,YAAY;EACjB;EACD,IAAI,SAAS;AACX,UAAO,IAAI;EACZ;EACD,IAAI,OAAO,OAAO;AAChB,OAAI,SAAS;EACd;CACF;AAED,QAAO;AACR"}
package/dist/deno.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  //#region deno.json
6
6
  var name = "@fedify/botkit";
7
- var version = "0.3.0-dev.111+1b9cba8a";
7
+ var version = "0.3.0-dev.112+8f983226";
8
8
  var license = "AGPL-3.0-only";
9
9
  var unstable = ["kv", "temporal"];
10
10
  var exports = {
@@ -14,13 +14,14 @@ var exports = {
14
14
  "./events": "./src/events.ts",
15
15
  "./follow": "./src/follow.ts",
16
16
  "./message": "./src/message.ts",
17
+ "./poll": "./src/poll.ts",
17
18
  "./reaction": "./src/reaction.ts",
18
19
  "./repository": "./src/repository.ts",
19
20
  "./session": "./src/session.ts",
20
21
  "./text": "./src/text.ts"
21
22
  };
22
23
  var imports = {
23
- "@fedify/fedify": "jsr:@fedify/fedify@^1.6.1",
24
+ "@fedify/fedify": "jsr:@fedify/fedify@^1.7.1",
24
25
  "@fedify/markdown-it-hashtag": "jsr:@fedify/markdown-it-hashtag@^0.3.0",
25
26
  "@fedify/markdown-it-mention": "jsr:@fedify/markdown-it-mention@^0.3.0",
26
27
  "@logtape/logtape": "jsr:@logtape/logtape@^1.0.0",
@@ -51,7 +52,12 @@ var fmt = { "exclude": [
51
52
  var tasks = {
52
53
  "check": "deno check src/ && deno lint && deno fmt --check && deno publish --dry-run --allow-dirty && deno run scripts/check_versions.ts",
53
54
  "test": "deno test --allow-env=NODE_V8_COVERAGE,JEST_WORKER_ID --allow-net=hollo.social --parallel",
54
- "test-all": "deno task check && deno task test",
55
+ "test:node": "pnpm install && pnpm test",
56
+ "test-all": { "dependencies": [
57
+ "check",
58
+ "test",
59
+ "test:node"
60
+ ] },
55
61
  "coverage": "deno task test --coverage --clean && deno coverage --html",
56
62
  "hooks:install": "deno run --allow-read=deno.json,.git/hooks/ --allow-write=.git/hooks/ jsr:@hongminhee/deno-task-hooks",
57
63
  "hooks:pre-commit": "deno task check"
package/dist/deno.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"deno.js","names":[],"sources":["../deno.json"],"sourcesContent":["{\n \"name\": \"@fedify/botkit\",\n \"version\": \"0.3.0-dev.111+1b9cba8a\",\n \"license\": \"AGPL-3.0-only\",\n \"unstable\": [\n \"kv\",\n \"temporal\"\n ],\n \"exports\": {\n \".\": \"./src/mod.ts\",\n \"./bot\": \"./src/bot.ts\",\n \"./emoji\": \"./src/emoji.ts\",\n \"./events\": \"./src/events.ts\",\n \"./follow\": \"./src/follow.ts\",\n \"./message\": \"./src/message.ts\",\n \"./reaction\": \"./src/reaction.ts\",\n \"./repository\": \"./src/repository.ts\",\n \"./session\": \"./src/session.ts\",\n \"./text\": \"./src/text.ts\"\n },\n \"imports\": {\n \"@fedify/fedify\": \"jsr:@fedify/fedify@^1.6.1\",\n \"@fedify/markdown-it-hashtag\": \"jsr:@fedify/markdown-it-hashtag@^0.3.0\",\n \"@fedify/markdown-it-mention\": \"jsr:@fedify/markdown-it-mention@^0.3.0\",\n \"@logtape/logtape\": \"jsr:@logtape/logtape@^1.0.0\",\n \"@phensley/language-tag\": \"npm:@phensley/language-tag@^1.12.2\",\n \"hono\": \"jsr:@hono/hono@^4.8.2\",\n \"html-entities\": \"npm:html-entities@^2.6.0\",\n \"markdown-it\": \"npm:markdown-it@^14.1.0\",\n \"mime-db\": \"npm:mime-db@^1.54.0\",\n \"tsdown\": \"npm:tsdown@^0.12.8\",\n \"uuid\": \"npm:uuid@^11.1.0\",\n \"x-forwarded-fetch\": \"jsr:@hongminhee/x-forwarded-fetch@^0.2.0\",\n \"xss\": \"npm:xss@^1.0.15\"\n },\n \"nodeModulesDir\": \"none\",\n \"exclude\": [\n \".github\",\n \".vscode\",\n \"dist\",\n \"docs\",\n \"src/css\"\n ],\n \"fmt\": {\n \"exclude\": [\n \"*.md\",\n \"*.yaml\",\n \"*.yml\",\n \"src/static/*.ts\"\n ]\n },\n \"tasks\": {\n \"check\": \"deno check src/ && deno lint && deno fmt --check && deno publish --dry-run --allow-dirty && deno run scripts/check_versions.ts\",\n \"test\": \"deno test --allow-env=NODE_V8_COVERAGE,JEST_WORKER_ID --allow-net=hollo.social --parallel\",\n \"test-all\": \"deno task check && deno task test\",\n \"coverage\": \"deno task test --coverage --clean && deno coverage --html\",\n \"hooks:install\": \"deno run --allow-read=deno.json,.git/hooks/ --allow-write=.git/hooks/ jsr:@hongminhee/deno-task-hooks\",\n \"hooks:pre-commit\": \"deno task check\"\n }\n}\n"],"mappings":";;;;;WACU;cACG;cACA;eACC,CACV,MACA,UACD;cACU;CACT,KAAK;CACL,SAAS;CACT,WAAW;CACX,YAAY;CACZ,YAAY;CACZ,aAAa;CACb,cAAc;CACd,gBAAgB;CAChB,aAAa;CACb,UAAU;AACX;cACU;CACT,kBAAkB;CAClB,+BAA+B;CAC/B,+BAA+B;CAC/B,oBAAoB;CACpB,0BAA0B;CAC1B,QAAQ;CACR,iBAAiB;CACjB,eAAe;CACf,WAAW;CACX,UAAU;CACV,QAAQ;CACR,qBAAqB;CACrB,OAAO;AACR;qBACiB;cACP;CACT;CACA;CACA;CACA;CACA;AACD;UACM,EACL,WAAW;CACT;CACA;CACA;CACA;AACD,EACF;YACQ;CACP,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,YAAY;CACZ,iBAAiB;CACjB,oBAAoB;AACrB;mBA1DH;;;;;;;;;;;AA2DC"}
1
+ {"version":3,"file":"deno.js","names":[],"sources":["../deno.json"],"sourcesContent":["{\n \"name\": \"@fedify/botkit\",\n \"version\": \"0.3.0-dev.112+8f983226\",\n \"license\": \"AGPL-3.0-only\",\n \"unstable\": [\n \"kv\",\n \"temporal\"\n ],\n \"exports\": {\n \".\": \"./src/mod.ts\",\n \"./bot\": \"./src/bot.ts\",\n \"./emoji\": \"./src/emoji.ts\",\n \"./events\": \"./src/events.ts\",\n \"./follow\": \"./src/follow.ts\",\n \"./message\": \"./src/message.ts\",\n \"./poll\": \"./src/poll.ts\",\n \"./reaction\": \"./src/reaction.ts\",\n \"./repository\": \"./src/repository.ts\",\n \"./session\": \"./src/session.ts\",\n \"./text\": \"./src/text.ts\"\n },\n \"imports\": {\n \"@fedify/fedify\": \"jsr:@fedify/fedify@^1.7.1\",\n \"@fedify/markdown-it-hashtag\": \"jsr:@fedify/markdown-it-hashtag@^0.3.0\",\n \"@fedify/markdown-it-mention\": \"jsr:@fedify/markdown-it-mention@^0.3.0\",\n \"@logtape/logtape\": \"jsr:@logtape/logtape@^1.0.0\",\n \"@phensley/language-tag\": \"npm:@phensley/language-tag@^1.12.2\",\n \"hono\": \"jsr:@hono/hono@^4.8.2\",\n \"html-entities\": \"npm:html-entities@^2.6.0\",\n \"markdown-it\": \"npm:markdown-it@^14.1.0\",\n \"mime-db\": \"npm:mime-db@^1.54.0\",\n \"tsdown\": \"npm:tsdown@^0.12.8\",\n \"uuid\": \"npm:uuid@^11.1.0\",\n \"x-forwarded-fetch\": \"jsr:@hongminhee/x-forwarded-fetch@^0.2.0\",\n \"xss\": \"npm:xss@^1.0.15\"\n },\n \"nodeModulesDir\": \"none\",\n \"exclude\": [\n \".github\",\n \".vscode\",\n \"dist\",\n \"docs\",\n \"src/css\"\n ],\n \"fmt\": {\n \"exclude\": [\n \"*.md\",\n \"*.yaml\",\n \"*.yml\",\n \"src/static/*.ts\"\n ]\n },\n \"tasks\": {\n \"check\": \"deno check src/ && deno lint && deno fmt --check && deno publish --dry-run --allow-dirty && deno run scripts/check_versions.ts\",\n \"test\": \"deno test --allow-env=NODE_V8_COVERAGE,JEST_WORKER_ID --allow-net=hollo.social --parallel\",\n \"test:node\": \"pnpm install && pnpm test\",\n \"test-all\": {\n \"dependencies\": [\n \"check\",\n \"test\",\n \"test:node\"\n ]\n },\n \"coverage\": \"deno task test --coverage --clean && deno coverage --html\",\n \"hooks:install\": \"deno run --allow-read=deno.json,.git/hooks/ --allow-write=.git/hooks/ jsr:@hongminhee/deno-task-hooks\",\n \"hooks:pre-commit\": \"deno task check\"\n }\n}\n"],"mappings":";;;;;WACU;cACG;cACA;eACC,CACV,MACA,UACD;cACU;CACT,KAAK;CACL,SAAS;CACT,WAAW;CACX,YAAY;CACZ,YAAY;CACZ,aAAa;CACb,UAAU;CACV,cAAc;CACd,gBAAgB;CAChB,aAAa;CACb,UAAU;AACX;cACU;CACT,kBAAkB;CAClB,+BAA+B;CAC/B,+BAA+B;CAC/B,oBAAoB;CACpB,0BAA0B;CAC1B,QAAQ;CACR,iBAAiB;CACjB,eAAe;CACf,WAAW;CACX,UAAU;CACV,QAAQ;CACR,qBAAqB;CACrB,OAAO;AACR;qBACiB;cACP;CACT;CACA;CACA;CACA;CACA;AACD;UACM,EACL,WAAW;CACT;CACA;CACA;CACA;AACD,EACF;YACQ;CACP,SAAS;CACT,QAAQ;CACR,aAAa;CACb,YAAY,EACV,gBAAgB;EACd;EACA;EACA;CACD,EACF;CACD,YAAY;CACZ,iBAAiB;CACjB,oBAAoB;AACrB;mBAlEH;;;;;;;;;;;AAmEC"}
package/dist/events.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
2
2
  Date.prototype.toTemporalInstant = toTemporalInstant;
3
3
  import { Like, Reaction } from "./reaction.js";
4
4
  import { Message, MessageClass, SharedMessage } from "./message.js";
5
+ import { Vote } from "./poll.js";
5
6
  import { Session } from "./session.js";
6
7
  import { FollowRequest } from "./follow.js";
7
8
  import { Actor } from "@fedify/fedify/vocab";
@@ -103,8 +104,19 @@ type ReactionEventHandler<TContextData> = (session: Session<TContextData>, react
103
104
  * @since 0.2.0
104
105
  */
105
106
  type UndoneReactionEventHandler<TContextData> = (session: Session<TContextData>, reaction: Reaction<TContextData>) => void | Promise<void>;
107
+ /**
108
+ * An event handler for a vote in a poll. This event is only triggered when
109
+ * the bot is the author of the poll, and the vote is made by another actor.
110
+ * Note that if the poll allows multiple selections, this event is triggered
111
+ * multiple times, once for each option selected by the actor.
112
+ * @typeParam TContextData The type of the context data.
113
+ * @param session The session of the bot.
114
+ * @param vote The vote made by another actor in the poll.
115
+ * @since 0.3.0
116
+ */
117
+ type VoteEventHandler<TContextData> = (session: Session<TContextData>, vote: Vote<TContextData>) => void | Promise<void>;
106
118
  //# sourceMappingURL=events.d.ts.map
107
119
 
108
120
  //#endregion
109
- export { AcceptEventHandler, FollowEventHandler, LikeEventHandler, MentionEventHandler, MessageEventHandler, QuoteEventHandler, ReactionEventHandler, RejectEventHandler, ReplyEventHandler, SharedMessageEventHandler, UndoneReactionEventHandler, UnfollowEventHandler, UnlikeEventHandler };
121
+ export { AcceptEventHandler, FollowEventHandler, LikeEventHandler, MentionEventHandler, MessageEventHandler, QuoteEventHandler, ReactionEventHandler, RejectEventHandler, ReplyEventHandler, SharedMessageEventHandler, UndoneReactionEventHandler, UnfollowEventHandler, UnlikeEventHandler, VoteEventHandler };
110
122
  //# sourceMappingURL=events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","names":[],"sources":["../src/events.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;AA2BY,KAAA,kBAAkB,CAAA,YAAA,CAAA,GAAA,CAAA,OAAA,EACnB,OADmB,CACX,YADW,CAAA,EAAA,aAAA,EAEb,aAFa,EAAA,GAAA,IAAA,GAGlB,OAHkB,CAAA,IAAA,CAAA;;;;;;AAGX;AAQP,KAAA,oBAAoB,CAAA,YAAA,CAAA,GAAA,CAAA,OAAA,EACrB,OADqB,CACb,YADa,CAAA,EAAA,QAAA,EAEpB,KAFoB,EAAA,GAAA,IAAA,GAGpB,OAHoB,CAAA,IAAA,CAAA;;;;;;AAGb;AAQP,KAAA,kBAAkB,CAAA,YAAA,CAAA,GAAA,CAAA,OAAA,EACnB,OADmB,CACX,YADW,CAAA,EAAA,QAAA,EAElB,KAFkB,EAAA,GAAA,IAAA,GAGlB,OAHkB,CAAA,IAAA,CAAA;;;;;;AAGX;AAQP,KAAA,kBAAkB,CAAA,YAAA,CAAA,GAAA,CAAA,OAAA,EACnB,OADmB,CACX,YADW,CAAA,EAAA,QAAA,EAElB,KAFkB,EAAA,GAAA,IAAA,GAGlB,OAHkB,CAAA,IAAA,CAAA;;;;;;AAGX;AAQP,KAAA,mBAAmB,CAAA,YAAA,CAAA,GAAA,CAAA,OAAA,EACpB,OADoB,CACZ,YADY,CAAA,EAAA,OAAA,EAEpB,OAFoB,CAEZ,YAFY,EAEE,YAFF,CAAA,EAAA,GAAA,IAAA,GAGnB,OA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B,CAYT,YAZS,CAAA,EAAA,IAAA,EAapB,IAboB,CAaf,YAbe,CAAA,EAAA,GAAA,IAAA,GAchB,OAdgB,CAAA,IAAA,CAAA;;;;;;;AAGT;AAQP,KAYA,oBAZkB,CAAA,YAAA,CAAA,GAAA,CAAA,OAAA,EAanB,OAbmB,CAaX,YAbW,CAAA,EAAA,QAAA,EAclB,QAdkB,CAcT,YAdS,CAAA,EAAA,GAAA,IAAA,GAelB,OAfkB,CAAA,IAAA,CAAA;;;;;;;AAGX;AASP,KAYA,0BAZoB,CAAA,YAAA,CAAA,GAAA,CAAA,OAAA,EAarB,OAbqB,CAab,YAba,CAAA,EAAA,QAAA,EAcpB,QAdoB,CAcX,YAdW,CAAA,EAAA,GAAA,IAAA,GAepB,OAfoB,CAAA,IAAA,CAAA;;;;;;;AAGb;AASnB;;;AACW,KAcC,gBAdD,CAAA,YAAA,CAAA,GAAA,CAAA,OAAA,EAeA,OAfA,CAeQ,YAfR,CAAA,EAAA,IAAA,EAgBH,IAhBG,CAgBE,YAhBF,CAAA,EAAA,GAAA,IAAA,GAiBC,OAjBD,CAAA,IAAA,CAAA"}
package/dist/mod.d.ts CHANGED
@@ -3,11 +3,12 @@ Date.prototype.toTemporalInstant = toTemporalInstant;
3
3
  import { AuthorizedLike, AuthorizedReaction, EmojiReact, Like, RawLike, Reaction } from "./reaction.js";
4
4
  import { Text, customEmoji, em, hashtag, link, mention, plainText, strong, text } from "./text.js";
5
5
  import { Actor, Article, Audio, AuthorizedMessage, AuthorizedSharedMessage, ChatMessage, Document, Hashtag, LanguageTag, Message, MessageClass, MessageShareOptions, MessageVisibility, Note, Question, SharedMessage, Video, isActor, parseLanguageTag } from "./message.js";
6
+ import { Poll, Vote } from "./poll.js";
6
7
  import { Session, SessionGetOutboxOptions, SessionPublishOptions, SessionPublishOptionsWithClass } from "./session.js";
7
8
  import { CustomEmoji, DeferredCustomEmoji, Emoji, emoji, isEmoji } from "./emoji.js";
8
9
  import { FollowRequest } from "./follow.js";
9
- import { AcceptEventHandler, FollowEventHandler, LikeEventHandler, MentionEventHandler, MessageEventHandler, QuoteEventHandler, ReactionEventHandler, RejectEventHandler, ReplyEventHandler, SharedMessageEventHandler, UndoneReactionEventHandler, UnfollowEventHandler, UnlikeEventHandler } from "./events.js";
10
+ import { AcceptEventHandler, FollowEventHandler, LikeEventHandler, MentionEventHandler, MessageEventHandler, QuoteEventHandler, ReactionEventHandler, RejectEventHandler, ReplyEventHandler, SharedMessageEventHandler, UndoneReactionEventHandler, UnfollowEventHandler, UnlikeEventHandler, VoteEventHandler } from "./events.js";
10
11
  import { Announce, Create, KvRepository, MemoryCachedRepository, MemoryRepository, Repository } from "./repository.js";
11
12
  import { Application, Bot, BotWithVoidContextData, CreateBotOptions, Image, PagesOptions, SemVer, Service, Software, createBot, parseSemVer } from "./bot.js";
12
13
  import { InProcessMessageQueue, InProcessMessageQueueOptions, MemoryKvStore, ParallelMessageQueue } from "@fedify/fedify/federation";
13
- export { AcceptEventHandler, Actor, Announce, Application, Article, Audio, AuthorizedLike, AuthorizedMessage, AuthorizedReaction, AuthorizedSharedMessage, Bot, BotWithVoidContextData, ChatMessage, Create, CreateBotOptions, CustomEmoji, DeferredCustomEmoji, Document, Emoji, EmojiReact, FollowEventHandler, FollowRequest, Hashtag, Image, InProcessMessageQueue, InProcessMessageQueueOptions, KvRepository, LanguageTag, Like, LikeEventHandler, MemoryCachedRepository, MemoryKvStore, MemoryRepository, MentionEventHandler, Message, MessageClass, MessageEventHandler, MessageShareOptions, MessageVisibility, Note, PagesOptions, ParallelMessageQueue, Question, QuoteEventHandler, RawLike, Reaction, ReactionEventHandler, RejectEventHandler, ReplyEventHandler, Repository, SemVer, Service, Session, SessionGetOutboxOptions, SessionPublishOptions, SessionPublishOptionsWithClass, SharedMessage, SharedMessageEventHandler, Software, Text, UndoneReactionEventHandler, UnfollowEventHandler, UnlikeEventHandler, Video, createBot, customEmoji, em, emoji, hashtag, isActor, isEmoji, link, mention, parseLanguageTag, parseSemVer, plainText, strong, text };
14
+ export { AcceptEventHandler, Actor, Announce, Application, Article, Audio, AuthorizedLike, AuthorizedMessage, AuthorizedReaction, AuthorizedSharedMessage, Bot, BotWithVoidContextData, ChatMessage, Create, CreateBotOptions, CustomEmoji, DeferredCustomEmoji, Document, Emoji, EmojiReact, FollowEventHandler, FollowRequest, Hashtag, Image, InProcessMessageQueue, InProcessMessageQueueOptions, KvRepository, LanguageTag, Like, LikeEventHandler, MemoryCachedRepository, MemoryKvStore, MemoryRepository, MentionEventHandler, Message, MessageClass, MessageEventHandler, MessageShareOptions, MessageVisibility, Note, PagesOptions, ParallelMessageQueue, Poll, Question, QuoteEventHandler, RawLike, Reaction, ReactionEventHandler, RejectEventHandler, ReplyEventHandler, Repository, SemVer, Service, Session, SessionGetOutboxOptions, SessionPublishOptions, SessionPublishOptionsWithClass, SharedMessage, SharedMessageEventHandler, Software, Text, UndoneReactionEventHandler, UnfollowEventHandler, UnlikeEventHandler, Video, Vote, VoteEventHandler, createBot, customEmoji, em, emoji, hashtag, isActor, isEmoji, link, mention, parseLanguageTag, parseSemVer, plainText, strong, text };
package/dist/mod.js CHANGED
@@ -4,9 +4,9 @@
4
4
 
5
5
  import { emoji, isEmoji } from "./emoji.js";
6
6
  import { Announce, Create, KvRepository, MemoryCachedRepository, MemoryRepository } from "./repository.js";
7
+ import { Article, Audio, ChatMessage, Document, Hashtag, LanguageTag, Note, Question, Video, isActor, parseLanguageTag } from "./message.js";
7
8
  import { Application, Image, Service, createBot, parseSemVer } from "./bot.js";
8
9
  import { customEmoji, em, hashtag, link, mention, plainText, strong, text } from "./text.js";
9
- import { Article, Audio, ChatMessage, Document, Hashtag, LanguageTag, Note, Question, Video, isActor, parseLanguageTag } from "./message.js";
10
10
  import { EmojiReact, RawLike } from "./reaction.js";
11
11
  import { InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue } from "@fedify/fedify/federation";
12
12
 
package/dist/poll.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
2
+ Date.prototype.toTemporalInstant = toTemporalInstant;
3
+ import { Message } from "./message.js";
4
+ import { Actor, Note, Question } from "@fedify/fedify/vocab";
5
+
6
+ //#region src/poll.d.ts
7
+ /**
8
+ * An interface representing a poll.
9
+ * @since 0.3.0
10
+ */
11
+ interface Poll {
12
+ /**
13
+ * Whether the poll allows multiple selections.
14
+ */
15
+ readonly multiple: boolean;
16
+ /**
17
+ * The options of the poll. Each option is a string. **Every option must be
18
+ * unique, and must not be empty.**
19
+ */
20
+ readonly options: readonly string[];
21
+ /**
22
+ * The time when the poll ends.
23
+ */
24
+ readonly endTime: Temporal.Instant;
25
+ }
26
+ /**
27
+ * An interface representing a vote in a poll. Note that if the poll allows
28
+ * multiple selections, the options are represented as multiple {@link Vote}
29
+ * objects, each with a single option.
30
+ * @typeParam TContextData The type of the context data.
31
+ * @since 0.3.0
32
+ */
33
+ interface Vote<TContextData> {
34
+ /**
35
+ * The underlying raw note object.
36
+ */
37
+ readonly raw: Note;
38
+ /**
39
+ * The actor who voted.
40
+ */
41
+ readonly actor: Actor;
42
+ /**
43
+ * The question to which the poll belongs.
44
+ */
45
+ readonly message: Message<Question, TContextData>;
46
+ /**
47
+ * The poll to which the vote belongs.
48
+ */
49
+ readonly poll: Poll;
50
+ /**
51
+ * The options selected by the actor. Note that this is a string even
52
+ * if the poll allows multiple selections. If the poll allows multiple
53
+ * selections, the options are represented as multiple {@link Vote} objects.
54
+ */
55
+ readonly option: string;
56
+ }
57
+ //# sourceMappingURL=poll.d.ts.map
58
+ //#endregion
59
+ export { Poll, Vote };
60
+ //# sourceMappingURL=poll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poll.d.ts","names":[],"sources":["../src/poll.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;UAsBiB,IAAA;;AAAjB;AAyBA;EAAqB,SAAA,QAAA,EAAA,OAAA;EAAA;;;;EAc6B,SAA9B,OAAA,EAAA,SAAA,MAAA,EAAA;EAAO;AAKN;;oBA7BD,QAAA,CAAS;;;;;;;;;UAUZ;;;;gBAID;;;;kBAKE;;;;oBAKE,QAAQ,UAAU;;;;iBAKrB"}
package/dist/poll.js ADDED
@@ -0,0 +1,4 @@
1
+
2
+ import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
3
+ Date.prototype.toTemporalInstant = toTemporalInstant;
4
+
@@ -1 +1 @@
1
- {"version":3,"file":"repository.js","names":["kv: KvStore","prefixes?: KvStoreRepositoryPrefixes","keyPairs: CryptoKeyPair[]","pairs: KeyPair[]","pair: KeyPair","id: Uuid","activity: Create | Announce","messageKey: KvKey","lockKey: KvKey","listKey: KvKey","updater: (\n existing: Create | Announce,\n ) => Create | Announce | undefined | Promise<Create | Announce | undefined>","kvKey: KvKey","Create","Announce","options: RepositoryGetMessagesOptions","activity: Activity","followRequestId: URL","follower: Actor","followerKey: KvKey","followRequestKey: KvKey","actorId: URL","follower: Object","followerId: URL","options: RepositoryGetFollowersOptions","actor: Object","follow: Follow","followeeId: URL","uuid: string","followId: URL","underlying: Repository","cache?: MemoryRepository","options?: RepositoryGetMessagesOptions","options?: RepositoryGetFollowersOptions"],"sources":["../src/repository.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport type { KvKey, KvStore } from \"@fedify/fedify/federation\";\nimport { exportJwk, importJwk } from \"@fedify/fedify/sig\";\nimport {\n Activity,\n type Actor,\n Announce,\n Create,\n Follow,\n isActor,\n Object,\n} from \"@fedify/fedify/vocab\";\nexport type { KvKey, KvStore } from \"@fedify/fedify/federation\";\nexport { Announce, Create } from \"@fedify/fedify/vocab\";\n\n/**\n * A UUID (universally unique identifier).\n * @since 0.3.0\n */\nexport type Uuid = ReturnType<typeof crypto.randomUUID>;\n\n/**\n * A repository for storing bot data.\n * @since 0.3.0\n */\nexport interface Repository {\n /**\n * Sets the key pairs of the bot actor.\n * @param keyPairs The key pairs to set.\n */\n setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>;\n\n /**\n * Gets the key pairs of the bot actor.\n * @returns The key pairs of the bot actor. If the key pairs do not exist,\n * `undefined` will be returned.\n */\n getKeyPairs(): Promise<CryptoKeyPair[] | undefined>;\n\n /**\n * Adds a message to the repository.\n * @param id The UUID of the message.\n * @param activity The activity to add.\n */\n addMessage(id: Uuid, activity: Create | Announce): Promise<void>;\n\n /**\n * Updates a message in the repository.\n * @param id The UUID of the message.\n * @param updater The function to update the message. The function will be\n * called with the existing message, and the return value will\n * be the new message. If the function returns a promise, the\n * promise will be awaited. If the function returns either\n * `undefined` or a promise that resolves to `undefined`,\n * the message will not be updated. If the message does not\n * exist, the updater will not be called.\n * @returns `true` if the message was updated, `false` if the message does not\n * exist.\n */\n updateMessage(\n id: Uuid,\n updater: (\n existing: Create | Announce,\n ) => Create | Announce | undefined | Promise<Create | Announce | undefined>,\n ): Promise<boolean>;\n\n /**\n * Removes a message from the repository.\n * @param id The UUID of the message to remove.\n * @returns The removed activity. If the message does not exist, `undefined`\n * will be returned.\n */\n removeMessage(id: Uuid): Promise<Create | Announce | undefined>;\n\n /**\n * Gets messages from the repository.\n * @param options The options for getting messages.\n * @returns An async iterable of message activities.\n */\n getMessages(\n options?: RepositoryGetMessagesOptions,\n ): AsyncIterable<Create | Announce>;\n\n /**\n * Gets a message from the repository.\n * @param id The UUID of the message to get.\n * @returns The message activity, or `undefined` if the message does not\n * exist.\n */\n getMessage(id: Uuid): Promise<Create | Announce | undefined>;\n\n /**\n * Counts the number of messages in the repository.\n * @returns The number of messages in the repository.\n */\n countMessages(): Promise<number>;\n\n /**\n * Adds a follower to the repository.\n * @param followId The URL of the follow request.\n * @param follower The actor who follows the bot.\n */\n addFollower(followId: URL, follower: Actor): Promise<void>;\n\n /**\n * Removes a follower from the repository.\n * @param followId The URL of the follow request.\n * @param followerId The ID of the actor to remove.\n * @returns The removed actor. If the follower does not exist or the follow\n * request is not about the follower, `undefined` will be returned.\n */\n removeFollower(followId: URL, followerId: URL): Promise<Actor | undefined>;\n\n /**\n * Checks if the repository has a follower.\n * @param followerId The ID of the follower to check.\n * @returns `true` if the repository has the follower, `false` otherwise.\n */\n hasFollower(followerId: URL): Promise<boolean>;\n\n /**\n * Gets followers from the repository.\n * @param options The options for getting followers.\n * @returns An async iterable of actors who follow the bot.\n */\n getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>;\n\n /**\n * Counts the number of followers in the repository.\n * @returns The number of followers in the repository.\n */\n countFollowers(): Promise<number>;\n\n /**\n * Adds a sent follow request to the repository.\n * @param id The UUID of the follow request.\n * @param follow The follow activity to add.\n */\n addSentFollow(id: Uuid, follow: Follow): Promise<void>;\n\n /**\n * Removes a sent follow request from the repository.\n * @param id The UUID of the follow request to remove.\n * @returns The removed follow activity. If the follow request does not\n * exist, `undefined` will be returned.\n */\n removeSentFollow(id: Uuid): Promise<Follow | undefined>;\n\n /**\n * Gets a sent follow request from the repository.\n * @param id The UUID of the follow request to get.\n * @returns The `Follow` activity, or `undefined` if the follow request does\n * not exist.\n */\n getSentFollow(id: Uuid): Promise<Follow | undefined>;\n\n /**\n * Adds a followee to the repository.\n * @param followeeId The ID of the followee to add.\n * @param follow The follow activity to add.\n */\n addFollowee(followeeId: URL, follow: Follow): Promise<void>;\n\n /**\n * Removes a followee from the repository.\n * @param followeeId The ID of the followee to remove.\n * @returns The `Follow` activity that was removed. If the followee does not\n * exist, `undefined` will be returned.\n */\n removeFollowee(followeeId: URL): Promise<Follow | undefined>;\n\n /**\n * Gets a followee from the repository.\n * @param followeeId The ID of the followee to get.\n * @returns The `Follow` activity, or `undefined` if the followee does not\n * exist.\n */\n getFollowee(followeeId: URL): Promise<Follow | undefined>;\n}\n\n/**\n * Options for getting messages from the repository.\n * @since 0.3.0\n */\nexport interface RepositoryGetMessagesOptions {\n /**\n * The order of the messages. If omitted, `\"newest\"` will be used.\n * @default `\"newest\"`\n */\n readonly order?: \"oldest\" | \"newest\";\n\n /**\n * The timestamp to get messages created at or before this time.\n * If omitted, no limit will be applied.\n */\n readonly until?: Temporal.Instant;\n\n /**\n * The timestamp to get messages created at or after this time.\n * If omitted, no limit will be applied.\n */\n readonly since?: Temporal.Instant;\n\n /**\n * The maximum number of messages to get. If omitted, no limit will be\n * applied.\n */\n readonly limit?: number;\n}\n\n/**\n * Options for getting followers from the repository.\n * @since 0.3.0\n */\nexport interface RepositoryGetFollowersOptions {\n /**\n * The offset of the followers to get. If omitted, 0 will be used.\n * @default `0`\n */\n readonly offset?: number;\n\n /**\n * The limit of the followers to get. If omitted, no limit will be applied.\n */\n readonly limit?: number;\n}\n\n/**\n * The prefixes for key-value store keys used by the bot.\n * @since 0.3.0\n */\nexport interface KvStoreRepositoryPrefixes {\n /**\n * The key prefix used for storing the key pairs of the bot actor.\n * @default `[\"_botkit\", \"keyPairs\"]`\n */\n readonly keyPairs: KvKey;\n\n /**\n * The key prefix used for storing published messages.\n * @default `[\"_botkit\", \"messages\"]`\n */\n readonly messages: KvKey;\n\n /**\n * The key prefix used for storing followers.\n * @default `[\"_botkit\", \"followers\"]`\n */\n readonly followers: KvKey;\n\n /**\n * The key prefix used for storing incoming follow requests.\n * @default `[\"_botkit\", \"followRequests\"]`\n */\n readonly followRequests: KvKey;\n\n /**\n * The key prefix used for storing followees.\n * @default `[\"_botkit\", \"followees\"]`\n */\n readonly followees: KvKey;\n\n /**\n * The key prefix used for storing outgoing follow requests.\n * @default `[\"_botkit\", \"follows\"]`\n */\n readonly follows: KvKey;\n}\n\n/**\n * A repository for storing bot data using a key-value store.\n */\nexport class KvRepository implements Repository {\n readonly kv: KvStore;\n readonly prefixes: KvStoreRepositoryPrefixes;\n\n /**\n * Creates a new key-value store repository.\n * @param kv The key-value store to use.\n * @param prefixes The prefixes for key-value store keys.\n */\n constructor(kv: KvStore, prefixes?: KvStoreRepositoryPrefixes) {\n this.kv = kv;\n this.prefixes = {\n keyPairs: [\"_botkit\", \"keyPairs\"],\n messages: [\"_botkit\", \"messages\"],\n followers: [\"_botkit\", \"followers\"],\n followRequests: [\"_botkit\", \"followRequests\"],\n followees: [\"_botkit\", \"followees\"],\n follows: [\"_botkit\", \"follows\"],\n ...prefixes ?? {},\n };\n }\n\n async setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void> {\n const pairs: KeyPair[] = [];\n for (const keyPair of keyPairs) {\n const pair: KeyPair = {\n private: await exportJwk(keyPair.privateKey),\n public: await exportJwk(keyPair.publicKey),\n };\n pairs.push(pair);\n }\n await this.kv.set(this.prefixes.keyPairs, pairs);\n }\n\n async getKeyPairs(): Promise<CryptoKeyPair[] | undefined> {\n const keyPairs = await this.kv.get<KeyPair[]>(this.prefixes.keyPairs);\n if (keyPairs == null) return undefined;\n const promises = keyPairs.map(async (pair) => ({\n privateKey: await importJwk(pair.private, \"private\"),\n publicKey: await importJwk(pair.public, \"public\"),\n }));\n return await Promise.all(promises);\n }\n\n async addMessage(id: Uuid, activity: Create | Announce): Promise<void> {\n const messageKey: KvKey = [...this.prefixes.messages, id];\n await this.kv.set(\n messageKey,\n await activity.toJsonLd({ format: \"compact\" }),\n );\n const lockKey: KvKey = [...this.prefixes.messages, \"lock\"];\n const listKey: KvKey = this.prefixes.messages;\n do {\n await this.kv.set(lockKey, id);\n const set = new Set(await this.kv.get<string[]>(listKey) ?? []);\n set.add(id);\n const list = [...set];\n list.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);\n await this.kv.set(listKey, list);\n } while (await this.kv.get(lockKey) !== id);\n }\n\n async updateMessage(\n id: Uuid,\n updater: (\n existing: Create | Announce,\n ) => Create | Announce | undefined | Promise<Create | Announce | undefined>,\n ): Promise<boolean> {\n const kvKey: KvKey = [...this.prefixes.messages, id];\n const createJson = await this.kv.get(kvKey);\n if (createJson == null) return false;\n const activity = await Activity.fromJsonLd(createJson);\n if (!(activity instanceof Create || activity instanceof Announce)) {\n return false;\n }\n const newActivity = await updater(activity);\n if (newActivity == null) return false;\n await this.kv.set(\n kvKey,\n await newActivity.toJsonLd({ format: \"compact\" }),\n );\n return true;\n }\n\n async removeMessage(id: Uuid): Promise<Create | Announce | undefined> {\n const listKey: KvKey = this.prefixes.messages;\n const lockKey: KvKey = [...listKey, \"lock\"];\n const lockId = `${id}:delete`;\n do {\n await this.kv.set(lockKey, lockId);\n const set = new Set(await this.kv.get<string[]>(listKey) ?? []);\n set.delete(id);\n const list = [...set];\n list.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);\n await this.kv.set(listKey, list);\n } while (await this.kv.get(lockKey) !== lockId);\n const messageKey: KvKey = [...listKey, id];\n const activityJson = await this.kv.get(messageKey);\n if (activityJson == null) return;\n await this.kv.delete(messageKey);\n const activity = await Activity.fromJsonLd(activityJson);\n if (activity instanceof Create || activity instanceof Announce) {\n return activity;\n }\n return undefined;\n }\n\n async *getMessages(\n options: RepositoryGetMessagesOptions = {},\n ): AsyncIterable<Create | Announce> {\n const { order, until, since, limit } = options;\n const untilTs = until == null ? null : until.epochMilliseconds;\n const sinceTs = since == null ? null : since.epochMilliseconds;\n let messageIds = await this.kv.get<string[]>(this.prefixes.messages) ?? [];\n if (sinceTs != null) {\n const offset = messageIds.findIndex((id) =>\n extractTimestamp(id) >= sinceTs\n );\n messageIds = messageIds.slice(offset);\n }\n if (untilTs != null) {\n const offset = messageIds.findLastIndex((id) =>\n extractTimestamp(id) <= untilTs\n );\n messageIds = messageIds.slice(0, offset + 1);\n }\n if (order == null || order === \"newest\") {\n messageIds = messageIds.toReversed();\n }\n if (limit != null) {\n messageIds = messageIds.slice(0, limit);\n }\n for (const id of messageIds) {\n const messageJson = await this.kv.get([...this.prefixes.messages, id]);\n if (messageJson == null) continue;\n try {\n const activity = await Activity.fromJsonLd(messageJson);\n if (activity instanceof Create || activity instanceof Announce) {\n yield activity;\n }\n } catch {\n continue;\n }\n }\n }\n\n async getMessage(id: Uuid): Promise<Create | Announce | undefined> {\n const json = await this.kv.get([...this.prefixes.messages, id]);\n if (json == null) return undefined;\n let activity: Activity;\n try {\n activity = await Activity.fromJsonLd(json);\n } catch (e) {\n if (e instanceof TypeError) return undefined;\n throw e;\n }\n if (activity instanceof Create || activity instanceof Announce) {\n return activity;\n }\n return undefined;\n }\n\n async countMessages(): Promise<number> {\n const messageIds = await this.kv.get<string[]>(this.prefixes.messages) ??\n [];\n return messageIds.length;\n }\n\n async addFollower(followRequestId: URL, follower: Actor): Promise<void> {\n if (follower.id == null) {\n throw new TypeError(\"The follower ID is missing.\");\n }\n const followerKey: KvKey = [...this.prefixes.followers, follower.id.href];\n await this.kv.set(\n followerKey,\n await follower.toJsonLd({ format: \"compact\" }),\n );\n const lockKey: KvKey = [...this.prefixes.followers, \"lock\"];\n const listKey: KvKey = this.prefixes.followers;\n do {\n await this.kv.set(lockKey, follower.id.href);\n const list = await this.kv.get<string[]>(listKey) ?? [];\n if (!list.includes(follower.id.href)) list.push(follower.id.href);\n await this.kv.set(listKey, list);\n } while (await this.kv.get(lockKey) !== follower.id.href);\n const followRequestKey: KvKey = [\n ...this.prefixes.followRequests,\n followRequestId.href,\n ];\n await this.kv.set(followRequestKey, follower.id.href);\n }\n\n async removeFollower(\n followRequestId: URL,\n actorId: URL,\n ): Promise<Actor | undefined> {\n const followRequestKey: KvKey = [\n ...this.prefixes.followRequests,\n followRequestId.href,\n ];\n const followerId = await this.kv.get<string>(followRequestKey);\n if (followerId == null) return undefined;\n const followerKey: KvKey = [...this.prefixes.followers, followerId];\n if (followerId !== actorId.href) return undefined;\n const followerJson = await this.kv.get(followerKey);\n if (followerJson == null) return undefined;\n let follower: Object;\n try {\n follower = await Object.fromJsonLd(followerJson);\n } catch {\n return undefined;\n }\n if (!isActor(follower)) return undefined;\n const lockKey: KvKey = [...this.prefixes.followers, \"lock\"];\n const listKey: KvKey = this.prefixes.followers;\n do {\n await this.kv.set(lockKey, followerId);\n let list = await this.kv.get<string[]>(listKey) ?? [];\n list = list.filter((id) => id !== followerId);\n await this.kv.set(listKey, list);\n } while (await this.kv.get(lockKey) !== followerId);\n await this.kv.delete(followerKey);\n await this.kv.delete(followRequestKey);\n return follower;\n }\n\n async hasFollower(followerId: URL): Promise<boolean> {\n return await this.kv.get<unknown>([\n ...this.prefixes.followers,\n followerId.href,\n ]) != null;\n }\n\n async *getFollowers(\n options: RepositoryGetFollowersOptions = {},\n ): AsyncIterable<Actor> {\n const { offset = 0, limit } = options;\n let followerIds = await this.kv.get<string[]>(this.prefixes.followers) ??\n [];\n followerIds = followerIds.slice(offset);\n if (limit != null) {\n followerIds = followerIds.slice(0, limit);\n }\n for (const id of followerIds) {\n const json = await this.kv.get([...this.prefixes.followers, id]);\n let actor: Object;\n try {\n actor = await Object.fromJsonLd(json);\n } catch (e) {\n if (e instanceof TypeError) continue;\n throw e;\n }\n if (isActor(actor)) yield actor;\n }\n }\n\n async countFollowers(): Promise<number> {\n const followerIds = await this.kv.get<string[]>(this.prefixes.followers) ??\n [];\n return followerIds.length;\n }\n\n async addSentFollow(id: Uuid, follow: Follow): Promise<void> {\n await this.kv.set(\n [...this.prefixes.follows, id],\n await follow.toJsonLd({ format: \"compact\" }),\n );\n }\n\n async removeSentFollow(id: Uuid): Promise<Follow | undefined> {\n const follow = await this.getSentFollow(id);\n if (follow == null) return undefined;\n await this.kv.delete([...this.prefixes.follows, id]);\n return follow;\n }\n\n async getSentFollow(id: Uuid): Promise<Follow | undefined> {\n const followJson = await this.kv.get([...this.prefixes.follows, id]);\n if (followJson == null) return undefined;\n try {\n return await Follow.fromJsonLd(followJson);\n } catch {\n return undefined;\n }\n }\n\n async addFollowee(followeeId: URL, follow: Follow): Promise<void> {\n await this.kv.set(\n [...this.prefixes.followees, followeeId.href],\n await follow.toJsonLd({ format: \"compact\" }),\n );\n }\n\n async removeFollowee(followeeId: URL): Promise<Follow | undefined> {\n const follow = await this.getFollowee(followeeId);\n if (follow == null) return undefined;\n await this.kv.delete([...this.prefixes.followees, followeeId.href]);\n return follow;\n }\n\n async getFollowee(followeeId: URL): Promise<Follow | undefined> {\n const json = await this.kv.get([\n ...this.prefixes.followees,\n followeeId.href,\n ]);\n if (json == null) return undefined;\n try {\n return await Follow.fromJsonLd(json);\n } catch {\n return undefined;\n }\n }\n}\n\ninterface KeyPair {\n private: JsonWebKey;\n public: JsonWebKey;\n}\n\n/**\n * Extracts the timestamp from a UUIDv7.\n * @param uuid The UUIDv7 string to extract the timestamp from.\n * @return The timestamp in milliseconds since the Unix epoch.\n * @internal\n */\nfunction extractTimestamp(uuid: string): number {\n // UUIDv7 format: xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx\n // The timestamp is in the first 6 bytes (48 bits) of the UUID.\n if (uuid.length !== 36 || uuid[14] !== \"7\") {\n throw new TypeError(\"Invalid UUIDv7 format.\");\n }\n const timestampHex = uuid.slice(0, 8) + uuid.slice(9, 13);\n return parseInt(timestampHex, 16);\n}\n\n/**\n * A repository for storing bot data in memory. This repository is not\n * persistent and is only suitable for testing or development.\n */\nexport class MemoryRepository implements Repository {\n keyPairs?: CryptoKeyPair[];\n messages: Map<Uuid, Create | Announce> = new Map();\n followers: Map<string, Actor> = new Map();\n followRequests: Record<string, string> = {};\n sentFollows: Record<string, Follow> = {};\n followees: Record<string, Follow> = {};\n\n setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void> {\n this.keyPairs = keyPairs;\n return Promise.resolve();\n }\n\n getKeyPairs(): Promise<CryptoKeyPair[] | undefined> {\n return Promise.resolve(this.keyPairs);\n }\n\n addMessage(id: Uuid, activity: Create | Announce): Promise<void> {\n this.messages.set(id, activity);\n return Promise.resolve();\n }\n\n async updateMessage(\n id: Uuid,\n updater: (\n existing: Create | Announce,\n ) => Create | Announce | undefined | Promise<Create | Announce | undefined>,\n ): Promise<boolean> {\n const existing = this.messages.get(id);\n if (existing == null) return false;\n const newActivity = await updater(existing);\n if (newActivity == null) return false;\n this.messages.set(id, newActivity);\n return true;\n }\n\n removeMessage(id: Uuid): Promise<Create | Announce | undefined> {\n const activity = this.messages.get(id);\n this.messages.delete(id);\n return Promise.resolve(activity);\n }\n\n async *getMessages(\n options: RepositoryGetMessagesOptions = {},\n ): AsyncIterable<Create | Announce> {\n const { order, until, since, limit } = options;\n let messages = [...this.messages.values()];\n if (since != null) {\n messages = messages.filter((message) =>\n message.published != null &&\n Temporal.Instant.compare(message.published, since) >= 0\n );\n }\n if (until != null) {\n messages = messages.filter((message) =>\n message.published != null &&\n Temporal.Instant.compare(message.published, until) <= 0\n );\n }\n if (order === \"oldest\") {\n messages.sort((a, b) =>\n (a.published?.epochMilliseconds ?? 0) -\n (b.published?.epochMilliseconds ?? 0)\n );\n } else {\n messages.sort((a, b) =>\n (b.published?.epochMilliseconds ?? 0) -\n (a.published?.epochMilliseconds ?? 0)\n );\n }\n if (limit != null) {\n messages.slice(0, limit);\n }\n for (const message of messages) yield message;\n }\n\n getMessage(id: Uuid): Promise<Create | Announce | undefined> {\n return Promise.resolve(this.messages.get(id));\n }\n\n countMessages(): Promise<number> {\n return Promise.resolve(this.messages.size);\n }\n\n addFollower(followId: URL, follower: Actor): Promise<void> {\n if (follower.id == null) {\n throw new TypeError(\"The follower ID is missing.\");\n }\n this.followers.set(follower.id.href, follower);\n this.followRequests[followId.href] = follower.id.href;\n return Promise.resolve();\n }\n\n removeFollower(followId: URL, followerId: URL): Promise<Actor | undefined> {\n const existing = this.followRequests[followId.href];\n if (existing == null || existing !== followerId.href) {\n return Promise.resolve(undefined);\n }\n delete this.followRequests[followId.href];\n const follower = this.followers.get(followerId.href);\n this.followers.delete(followerId.href);\n return Promise.resolve(follower);\n }\n\n hasFollower(followerId: URL): Promise<boolean> {\n return Promise.resolve(this.followers.has(followerId.href));\n }\n\n async *getFollowers(\n options: RepositoryGetFollowersOptions = {},\n ): AsyncIterable<Actor> {\n const { offset = 0, limit } = options;\n let followers = [...this.followers.values()];\n followers.sort((a, b) => b.id!.href.localeCompare(a.id!.href) ?? 0);\n if (offset > 0) {\n followers = followers.slice(offset);\n }\n if (limit != null) {\n followers = followers.slice(0, limit);\n }\n for (const follower of followers) {\n yield follower;\n }\n }\n\n countFollowers(): Promise<number> {\n return Promise.resolve(this.followers.size);\n }\n\n addSentFollow(id: Uuid, follow: Follow): Promise<void> {\n this.sentFollows[id] = follow;\n return Promise.resolve();\n }\n\n removeSentFollow(id: Uuid): Promise<Follow | undefined> {\n const follow = this.sentFollows[id];\n delete this.sentFollows[id];\n return Promise.resolve(follow);\n }\n\n getSentFollow(id: Uuid): Promise<Follow | undefined> {\n return Promise.resolve(this.sentFollows[id]);\n }\n\n addFollowee(followeeId: URL, follow: Follow): Promise<void> {\n this.followees[followeeId.href] = follow;\n return Promise.resolve();\n }\n\n removeFollowee(followeeId: URL): Promise<Follow | undefined> {\n const follow = this.followees[followeeId.href];\n delete this.followees[followeeId.href];\n return Promise.resolve(follow);\n }\n\n getFollowee(followeeId: URL): Promise<Follow | undefined> {\n return Promise.resolve(this.followees[followeeId.href]);\n }\n}\n\n/**\n * A repository decorator that adds an in-memory cache layer on top of another\n * repository. This is useful for improving performance by reducing the number\n * of accesses to the underlying persistent storage, but it increases memory\n * usage. The cache is not persistent and will be lost when the process exits.\n *\n * Note: List operations like `getMessages` and `getFollowers`, and count\n * operations like `countMessages` and `countFollowers` are not cached and\n * always delegate to the underlying repository.\n * @since 0.3.0\n */\nexport class MemoryCachedRepository implements Repository {\n private underlying: Repository;\n private cache: MemoryRepository;\n\n /**\n * Creates a new memory-cached repository.\n * @param underlying The underlying repository to cache.\n * @param cache An optional `MemoryRepository` instance to use as the cache.\n * If not provided, a new one will be created internally.\n */\n constructor(underlying: Repository, cache?: MemoryRepository) {\n this.underlying = underlying;\n this.cache = cache ?? new MemoryRepository();\n }\n\n async setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void> {\n await this.underlying.setKeyPairs(keyPairs);\n await this.cache.setKeyPairs(keyPairs);\n }\n\n async getKeyPairs(): Promise<CryptoKeyPair[] | undefined> {\n let keyPairs = await this.cache.getKeyPairs();\n if (keyPairs === undefined) {\n keyPairs = await this.underlying.getKeyPairs();\n if (keyPairs !== undefined) await this.cache.setKeyPairs(keyPairs);\n }\n return keyPairs;\n }\n\n async addMessage(id: Uuid, activity: Create | Announce): Promise<void> {\n await this.underlying.addMessage(id, activity);\n await this.cache.addMessage(id, activity);\n }\n\n async updateMessage(\n id: Uuid,\n updater: (\n existing: Create | Announce,\n ) => Create | Announce | undefined | Promise<Create | Announce | undefined>,\n ): Promise<boolean> {\n // Apply update to underlying first\n const updated = await this.underlying.updateMessage(id, updater);\n if (updated) {\n // If successful, fetch the updated message and update the cache\n const updatedMessage = await this.underlying.getMessage(id);\n if (updatedMessage) {\n await this.cache.addMessage(id, updatedMessage); // Use addMessage which acts like set\n } else {\n // Should not happen if updateMessage returned true, but handle defensively\n await this.cache.removeMessage(id);\n }\n }\n return updated;\n }\n\n async removeMessage(id: Uuid): Promise<Create | Announce | undefined> {\n const removedActivity = await this.underlying.removeMessage(id);\n if (removedActivity !== undefined) {\n await this.cache.removeMessage(id);\n }\n return removedActivity;\n }\n\n // getMessages is not cached due to complexity with options\n getMessages(\n options?: RepositoryGetMessagesOptions,\n ): AsyncIterable<Create | Announce> {\n return this.underlying.getMessages(options);\n }\n\n async getMessage(id: Uuid): Promise<Create | Announce | undefined> {\n let message = await this.cache.getMessage(id);\n if (message === undefined) {\n message = await this.underlying.getMessage(id);\n if (message !== undefined) {\n await this.cache.addMessage(id, message); // Use addMessage which acts like set\n }\n }\n return message;\n }\n\n // countMessages is not cached\n countMessages(): Promise<number> {\n return this.underlying.countMessages();\n }\n\n async addFollower(followId: URL, follower: Actor): Promise<void> {\n await this.underlying.addFollower(followId, follower);\n await this.cache.addFollower(followId, follower);\n }\n\n async removeFollower(\n followId: URL,\n followerId: URL,\n ): Promise<Actor | undefined> {\n const removedFollower = await this.underlying.removeFollower(\n followId,\n followerId,\n );\n if (removedFollower !== undefined) {\n await this.cache.removeFollower(followId, followerId);\n }\n return removedFollower;\n }\n\n async hasFollower(followerId: URL): Promise<boolean> {\n // Check cache first for potentially faster response\n if (await this.cache.hasFollower(followerId)) {\n return true;\n }\n // If not in cache, check underlying and update cache if found\n const exists = await this.underlying.hasFollower(followerId);\n // Note: We don't automatically add to cache here, as we don't have the Actor object\n // It will be cached if addFollower is called or if getFollowers iterates over it (though getFollowers isn't cached)\n return exists;\n }\n\n // getFollowers is not cached due to complexity with options\n getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor> {\n // We could potentially cache followers as they are iterated,\n // but for simplicity, delegate directly for now.\n return this.underlying.getFollowers(options);\n }\n\n // countFollowers is not cached\n countFollowers(): Promise<number> {\n return this.underlying.countFollowers();\n }\n\n async addSentFollow(id: Uuid, follow: Follow): Promise<void> {\n await this.underlying.addSentFollow(id, follow);\n await this.cache.addSentFollow(id, follow);\n }\n\n async removeSentFollow(id: Uuid): Promise<Follow | undefined> {\n const removedFollow = await this.underlying.removeSentFollow(id);\n if (removedFollow !== undefined) {\n await this.cache.removeSentFollow(id);\n }\n return removedFollow;\n }\n\n async getSentFollow(id: Uuid): Promise<Follow | undefined> {\n let follow = await this.cache.getSentFollow(id);\n if (follow === undefined) {\n follow = await this.underlying.getSentFollow(id);\n if (follow !== undefined) {\n await this.cache.addSentFollow(id, follow);\n }\n }\n return follow;\n }\n\n async addFollowee(followeeId: URL, follow: Follow): Promise<void> {\n await this.underlying.addFollowee(followeeId, follow);\n await this.cache.addFollowee(followeeId, follow);\n }\n\n async removeFollowee(followeeId: URL): Promise<Follow | undefined> {\n const removedFollow = await this.underlying.removeFollowee(followeeId);\n if (removedFollow !== undefined) {\n await this.cache.removeFollowee(followeeId);\n }\n return removedFollow;\n }\n\n async getFollowee(followeeId: URL): Promise<Follow | undefined> {\n let follow = await this.cache.getFollowee(followeeId);\n if (follow === undefined) {\n follow = await this.underlying.getFollowee(followeeId);\n if (follow !== undefined) {\n await this.cache.addFollowee(followeeId, follow);\n }\n }\n return follow;\n }\n}\n"],"mappings":";;;;;;;;;;;AA8RA,IAAa,eAAb,MAAgD;CAC9C,AAAS;CACT,AAAS;;;;;;CAOT,YAAYA,IAAaC,UAAsC;AAC7D,OAAK,KAAK;AACV,OAAK,WAAW;GACd,UAAU,CAAC,WAAW,UAAW;GACjC,UAAU,CAAC,WAAW,UAAW;GACjC,WAAW,CAAC,WAAW,WAAY;GACnC,gBAAgB,CAAC,WAAW,gBAAiB;GAC7C,WAAW,CAAC,WAAW,WAAY;GACnC,SAAS,CAAC,WAAW,SAAU;GAC/B,GAAG,YAAY,CAAE;EAClB;CACF;CAED,MAAM,YAAYC,UAA0C;EAC1D,MAAMC,QAAmB,CAAE;AAC3B,OAAK,MAAM,WAAW,UAAU;GAC9B,MAAMC,OAAgB;IACpB,SAAS,MAAM,UAAU,QAAQ,WAAW;IAC5C,QAAQ,MAAM,UAAU,QAAQ,UAAU;GAC3C;AACD,SAAM,KAAK,KAAK;EACjB;AACD,QAAM,KAAK,GAAG,IAAI,KAAK,SAAS,UAAU,MAAM;CACjD;CAED,MAAM,cAAoD;EACxD,MAAM,WAAW,MAAM,KAAK,GAAG,IAAe,KAAK,SAAS,SAAS;AACrE,MAAI,YAAY,KAAM;EACtB,MAAM,WAAW,SAAS,IAAI,OAAO,UAAU;GAC7C,YAAY,MAAM,UAAU,KAAK,SAAS,UAAU;GACpD,WAAW,MAAM,UAAU,KAAK,QAAQ,SAAS;EAClD,GAAE;AACH,SAAO,MAAM,QAAQ,IAAI,SAAS;CACnC;CAED,MAAM,WAAWC,IAAUC,UAA4C;EACrE,MAAMC,aAAoB,CAAC,GAAG,KAAK,SAAS,UAAU,EAA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YAAiBD,QAA+B;AAChE,QAAM,KAAK,WAAW,YAAY,YAAY,OAAO;AACrD,QAAM,KAAK,MAAM,YAAY,YAAY,OAAO;CACjD;CAED,MAAM,eAAeC,YAA8C;EACjE,MAAM,gBAAgB,MAAM,KAAK,WAAW,eAAe,WAAW;AACtE,MAAI,yBACF,OAAM,KAAK,MAAM,eAAe,WAAW;AAE7C,SAAO;CACR;CAED,MAAM,YAAYA,YAA8C;EAC9D,IAAI,SAAS,MAAM,KAAK,MAAM,YAAY,WAAW;AACrD,MAAI,mBAAsB;AACxB,YAAS,MAAM,KAAK,WAAW,YAAY,WAAW;AACtD,OAAI,kBACF,OAAM,KAAK,MAAM,YAAY,YAAY,OAAO;EAEnD;AACD,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"repository.js","names":["kv: KvStore","prefixes?: KvStoreRepositoryPrefixes","keyPairs: CryptoKeyPair[]","pairs: KeyPair[]","pair: KeyPair","id: Uuid","activity: Create | Announce","messageKey: KvKey","lockKey: KvKey","listKey: KvKey","updater: (\n existing: Create | Announce,\n ) => Create | Announce | undefined | Promise<Create | Announce | undefined>","kvKey: KvKey","Create","Announce","options: RepositoryGetMessagesOptions","activity: Activity","followRequestId: URL","follower: Actor","followerKey: KvKey","followRequestKey: KvKey","actorId: URL","follower: Object","followerId: URL","options: RepositoryGetFollowersOptions","actor: Object","follow: Follow","followeeId: URL","uuid: string","followId: URL","underlying: Repository","cache?: MemoryRepository","options?: RepositoryGetMessagesOptions","options?: RepositoryGetFollowersOptions"],"sources":["../src/repository.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport type { KvKey, KvStore } from \"@fedify/fedify/federation\";\nimport { exportJwk, importJwk } from \"@fedify/fedify/sig\";\nimport {\n Activity,\n type Actor,\n Announce,\n Create,\n Follow,\n isActor,\n Object,\n} from \"@fedify/fedify/vocab\";\nexport type { KvKey, KvStore } from \"@fedify/fedify/federation\";\nexport { Announce, Create } from \"@fedify/fedify/vocab\";\n\n/**\n * A UUID (universally unique identifier).\n * @since 0.3.0\n */\nexport type Uuid = ReturnType<typeof crypto.randomUUID>;\n\n/**\n * A repository for storing bot data.\n * @since 0.3.0\n */\nexport interface Repository {\n /**\n * Sets the key pairs of the bot actor.\n * @param keyPairs The key pairs to set.\n */\n setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>;\n\n /**\n * Gets the key pairs of the bot actor.\n * @returns The key pairs of the bot actor. If the key pairs do not exist,\n * `undefined` will be returned.\n */\n getKeyPairs(): Promise<CryptoKeyPair[] | undefined>;\n\n /**\n * Adds a message to the repository.\n * @param id The UUID of the message.\n * @param activity The activity to add.\n */\n addMessage(id: Uuid, activity: Create | Announce): Promise<void>;\n\n /**\n * Updates a message in the repository.\n * @param id The UUID of the message.\n * @param updater The function to update the message. The function will be\n * called with the existing message, and the return value will\n * be the new message. If the function returns a promise, the\n * promise will be awaited. If the function returns either\n * `undefined` or a promise that resolves to `undefined`,\n * the message will not be updated. If the message does not\n * exist, the updater will not be called.\n * @returns `true` if the message was updated, `false` if the message does not\n * exist.\n */\n updateMessage(\n id: Uuid,\n updater: (\n existing: Create | Announce,\n ) => Create | Announce | undefined | Promise<Create | Announce | undefined>,\n ): Promise<boolean>;\n\n /**\n * Removes a message from the repository.\n * @param id The UUID of the message to remove.\n * @returns The removed activity. If the message does not exist, `undefined`\n * will be returned.\n */\n removeMessage(id: Uuid): Promise<Create | Announce | undefined>;\n\n /**\n * Gets messages from the repository.\n * @param options The options for getting messages.\n * @returns An async iterable of message activities.\n */\n getMessages(\n options?: RepositoryGetMessagesOptions,\n ): AsyncIterable<Create | Announce>;\n\n /**\n * Gets a message from the repository.\n * @param id The UUID of the message to get.\n * @returns The message activity, or `undefined` if the message does not\n * exist.\n */\n getMessage(id: Uuid): Promise<Create | Announce | undefined>;\n\n /**\n * Counts the number of messages in the repository.\n * @returns The number of messages in the repository.\n */\n countMessages(): Promise<number>;\n\n /**\n * Adds a follower to the repository.\n * @param followId The URL of the follow request.\n * @param follower The actor who follows the bot.\n */\n addFollower(followId: URL, follower: Actor): Promise<void>;\n\n /**\n * Removes a follower from the repository.\n * @param followId The URL of the follow request.\n * @param followerId The ID of the actor to remove.\n * @returns The removed actor. If the follower does not exist or the follow\n * request is not about the follower, `undefined` will be returned.\n */\n removeFollower(followId: URL, followerId: URL): Promise<Actor | undefined>;\n\n /**\n * Checks if the repository has a follower.\n * @param followerId The ID of the follower to check.\n * @returns `true` if the repository has the follower, `false` otherwise.\n */\n hasFollower(followerId: URL): Promise<boolean>;\n\n /**\n * Gets followers from the repository.\n * @param options The options for getting followers.\n * @returns An async iterable of actors who follow the bot.\n */\n getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>;\n\n /**\n * Counts the number of followers in the repository.\n * @returns The number of followers in the repository.\n */\n countFollowers(): Promise<number>;\n\n /**\n * Adds a sent follow request to the repository.\n * @param id The UUID of the follow request.\n * @param follow The follow activity to add.\n */\n addSentFollow(id: Uuid, follow: Follow): Promise<void>;\n\n /**\n * Removes a sent follow request from the repository.\n * @param id The UUID of the follow request to remove.\n * @returns The removed follow activity. If the follow request does not\n * exist, `undefined` will be returned.\n */\n removeSentFollow(id: Uuid): Promise<Follow | undefined>;\n\n /**\n * Gets a sent follow request from the repository.\n * @param id The UUID of the follow request to get.\n * @returns The `Follow` activity, or `undefined` if the follow request does\n * not exist.\n */\n getSentFollow(id: Uuid): Promise<Follow | undefined>;\n\n /**\n * Adds a followee to the repository.\n * @param followeeId The ID of the followee to add.\n * @param follow The follow activity to add.\n */\n addFollowee(followeeId: URL, follow: Follow): Promise<void>;\n\n /**\n * Removes a followee from the repository.\n * @param followeeId The ID of the followee to remove.\n * @returns The `Follow` activity that was removed. If the followee does not\n * exist, `undefined` will be returned.\n */\n removeFollowee(followeeId: URL): Promise<Follow | undefined>;\n\n /**\n * Gets a followee from the repository.\n * @param followeeId The ID of the followee to get.\n * @returns The `Follow` activity, or `undefined` if the followee does not\n * exist.\n */\n getFollowee(followeeId: URL): Promise<Follow | undefined>;\n}\n\n/**\n * Options for getting messages from the repository.\n * @since 0.3.0\n */\nexport interface RepositoryGetMessagesOptions {\n /**\n * The order of the messages. If omitted, `\"newest\"` will be used.\n * @default `\"newest\"`\n */\n readonly order?: \"oldest\" | \"newest\";\n\n /**\n * The timestamp to get messages created at or before this time.\n * If omitted, no limit will be applied.\n */\n readonly until?: Temporal.Instant;\n\n /**\n * The timestamp to get messages created at or after this time.\n * If omitted, no limit will be applied.\n */\n readonly since?: Temporal.Instant;\n\n /**\n * The maximum number of messages to get. If omitted, no limit will be\n * applied.\n */\n readonly limit?: number;\n}\n\n/**\n * Options for getting followers from the repository.\n * @since 0.3.0\n */\nexport interface RepositoryGetFollowersOptions {\n /**\n * The offset of the followers to get. If omitted, 0 will be used.\n * @default `0`\n */\n readonly offset?: number;\n\n /**\n * The limit of the followers to get. If omitted, no limit will be applied.\n */\n readonly limit?: number;\n}\n\n/**\n * The prefixes for key-value store keys used by the bot.\n * @since 0.3.0\n */\nexport interface KvStoreRepositoryPrefixes {\n /**\n * The key prefix used for storing the key pairs of the bot actor.\n * @default `[\"_botkit\", \"keyPairs\"]`\n */\n readonly keyPairs: KvKey;\n\n /**\n * The key prefix used for storing published messages.\n * @default `[\"_botkit\", \"messages\"]`\n */\n readonly messages: KvKey;\n\n /**\n * The key prefix used for storing followers.\n * @default `[\"_botkit\", \"followers\"]`\n */\n readonly followers: KvKey;\n\n /**\n * The key prefix used for storing incoming follow requests.\n * @default `[\"_botkit\", \"followRequests\"]`\n */\n readonly followRequests: KvKey;\n\n /**\n * The key prefix used for storing followees.\n * @default `[\"_botkit\", \"followees\"]`\n */\n readonly followees: KvKey;\n\n /**\n * The key prefix used for storing outgoing follow requests.\n * @default `[\"_botkit\", \"follows\"]`\n */\n readonly follows: KvKey;\n}\n\n/**\n * A repository for storing bot data using a key-value store.\n */\nexport class KvRepository implements Repository {\n readonly kv: KvStore;\n readonly prefixes: KvStoreRepositoryPrefixes;\n\n /**\n * Creates a new key-value store repository.\n * @param kv The key-value store to use.\n * @param prefixes The prefixes for key-value store keys.\n */\n constructor(kv: KvStore, prefixes?: KvStoreRepositoryPrefixes) {\n this.kv = kv;\n this.prefixes = {\n keyPairs: [\"_botkit\", \"keyPairs\"],\n messages: [\"_botkit\", \"messages\"],\n followers: [\"_botkit\", \"followers\"],\n followRequests: [\"_botkit\", \"followRequests\"],\n followees: [\"_botkit\", \"followees\"],\n follows: [\"_botkit\", \"follows\"],\n ...prefixes ?? {},\n };\n }\n\n async setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void> {\n const pairs: KeyPair[] = [];\n for (const keyPair of keyPairs) {\n const pair: KeyPair = {\n private: await exportJwk(keyPair.privateKey),\n public: await exportJwk(keyPair.publicKey),\n };\n pairs.push(pair);\n }\n await this.kv.set(this.prefixes.keyPairs, pairs);\n }\n\n async getKeyPairs(): Promise<CryptoKeyPair[] | undefined> {\n const keyPairs = await this.kv.get<KeyPair[]>(this.prefixes.keyPairs);\n if (keyPairs == null) return undefined;\n const promises = keyPairs.map(async (pair) => ({\n privateKey: await importJwk(pair.private, \"private\"),\n publicKey: await importJwk(pair.public, \"public\"),\n }));\n return await Promise.all(promises);\n }\n\n async addMessage(id: Uuid, activity: Create | Announce): Promise<void> {\n const messageKey: KvKey = [...this.prefixes.messages, id];\n await this.kv.set(\n messageKey,\n await activity.toJsonLd({ format: \"compact\" }),\n );\n const lockKey: KvKey = [...this.prefixes.messages, \"lock\"];\n const listKey: KvKey = this.prefixes.messages;\n do {\n await this.kv.set(lockKey, id);\n const set = new Set(await this.kv.get<string[]>(listKey) ?? []);\n set.add(id);\n const list = [...set];\n list.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);\n await this.kv.set(listKey, list);\n } while (await this.kv.get(lockKey) !== id);\n }\n\n async updateMessage(\n id: Uuid,\n updater: (\n existing: Create | Announce,\n ) => Create | Announce | undefined | Promise<Create | Announce | undefined>,\n ): Promise<boolean> {\n const kvKey: KvKey = [...this.prefixes.messages, id];\n const createJson = await this.kv.get(kvKey);\n if (createJson == null) return false;\n const activity = await Activity.fromJsonLd(createJson);\n if (!(activity instanceof Create || activity instanceof Announce)) {\n return false;\n }\n const newActivity = await updater(activity);\n if (newActivity == null) return false;\n await this.kv.set(\n kvKey,\n await newActivity.toJsonLd({ format: \"compact\" }),\n );\n return true;\n }\n\n async removeMessage(id: Uuid): Promise<Create | Announce | undefined> {\n const listKey: KvKey = this.prefixes.messages;\n const lockKey: KvKey = [...listKey, \"lock\"];\n const lockId = `${id}:delete`;\n do {\n await this.kv.set(lockKey, lockId);\n const set = new Set(await this.kv.get<string[]>(listKey) ?? []);\n set.delete(id);\n const list = [...set];\n list.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);\n await this.kv.set(listKey, list);\n } while (await this.kv.get(lockKey) !== lockId);\n const messageKey: KvKey = [...listKey, id];\n const activityJson = await this.kv.get(messageKey);\n if (activityJson == null) return;\n await this.kv.delete(messageKey);\n const activity = await Activity.fromJsonLd(activityJson);\n if (activity instanceof Create || activity instanceof Announce) {\n return activity;\n }\n return undefined;\n }\n\n async *getMessages(\n options: RepositoryGetMessagesOptions = {},\n ): AsyncIterable<Create | Announce> {\n const { order, until, since, limit } = options;\n const untilTs = until == null ? null : until.epochMilliseconds;\n const sinceTs = since == null ? null : since.epochMilliseconds;\n let messageIds = await this.kv.get<string[]>(this.prefixes.messages) ?? [];\n if (sinceTs != null) {\n const offset = messageIds.findIndex((id) =>\n extractTimestamp(id) >= sinceTs\n );\n messageIds = messageIds.slice(offset);\n }\n if (untilTs != null) {\n const offset = messageIds.findLastIndex((id) =>\n extractTimestamp(id) <= untilTs\n );\n messageIds = messageIds.slice(0, offset + 1);\n }\n if (order == null || order === \"newest\") {\n messageIds = messageIds.toReversed();\n }\n if (limit != null) {\n messageIds = messageIds.slice(0, limit);\n }\n for (const id of messageIds) {\n const messageJson = await this.kv.get([...this.prefixes.messages, id]);\n if (messageJson == null) continue;\n try {\n const activity = await Activity.fromJsonLd(messageJson);\n if (activity instanceof Create || activity instanceof Announce) {\n yield activity;\n }\n } catch {\n continue;\n }\n }\n }\n\n async getMessage(id: Uuid): Promise<Create | Announce | undefined> {\n const json = await this.kv.get([...this.prefixes.messages, id]);\n if (json == null) return undefined;\n let activity: Activity;\n try {\n activity = await Activity.fromJsonLd(json);\n } catch (e) {\n if (e instanceof TypeError) return undefined;\n throw e;\n }\n if (activity instanceof Create || activity instanceof Announce) {\n return activity;\n }\n return undefined;\n }\n\n async countMessages(): Promise<number> {\n const messageIds = await this.kv.get<string[]>(this.prefixes.messages) ??\n [];\n return messageIds.length;\n }\n\n async addFollower(followRequestId: URL, follower: Actor): Promise<void> {\n if (follower.id == null) {\n throw new TypeError(\"The follower ID is missing.\");\n }\n const followerKey: KvKey = [...this.prefixes.followers, follower.id.href];\n await this.kv.set(\n followerKey,\n await follower.toJsonLd({ format: \"compact\" }),\n );\n const lockKey: KvKey = [...this.prefixes.followers, \"lock\"];\n const listKey: KvKey = this.prefixes.followers;\n do {\n await this.kv.set(lockKey, follower.id.href);\n const list = await this.kv.get<string[]>(listKey) ?? [];\n if (!list.includes(follower.id.href)) list.push(follower.id.href);\n await this.kv.set(listKey, list);\n } while (await this.kv.get(lockKey) !== follower.id.href);\n const followRequestKey: KvKey = [\n ...this.prefixes.followRequests,\n followRequestId.href,\n ];\n await this.kv.set(followRequestKey, follower.id.href);\n }\n\n async removeFollower(\n followRequestId: URL,\n actorId: URL,\n ): Promise<Actor | undefined> {\n const followRequestKey: KvKey = [\n ...this.prefixes.followRequests,\n followRequestId.href,\n ];\n const followerId = await this.kv.get<string>(followRequestKey);\n if (followerId == null) return undefined;\n const followerKey: KvKey = [...this.prefixes.followers, followerId];\n if (followerId !== actorId.href) return undefined;\n const followerJson = await this.kv.get(followerKey);\n if (followerJson == null) return undefined;\n let follower: Object;\n try {\n follower = await Object.fromJsonLd(followerJson);\n } catch {\n return undefined;\n }\n if (!isActor(follower)) return undefined;\n const lockKey: KvKey = [...this.prefixes.followers, \"lock\"];\n const listKey: KvKey = this.prefixes.followers;\n do {\n await this.kv.set(lockKey, followerId);\n let list = await this.kv.get<string[]>(listKey) ?? [];\n list = list.filter((id) => id !== followerId);\n await this.kv.set(listKey, list);\n } while (await this.kv.get(lockKey) !== followerId);\n await this.kv.delete(followerKey);\n await this.kv.delete(followRequestKey);\n return follower;\n }\n\n async hasFollower(followerId: URL): Promise<boolean> {\n return await this.kv.get<unknown>([\n ...this.prefixes.followers,\n followerId.href,\n ]) != null;\n }\n\n async *getFollowers(\n options: RepositoryGetFollowersOptions = {},\n ): AsyncIterable<Actor> {\n const { offset = 0, limit } = options;\n let followerIds = await this.kv.get<string[]>(this.prefixes.followers) ??\n [];\n followerIds = followerIds.slice(offset);\n if (limit != null) {\n followerIds = followerIds.slice(0, limit);\n }\n for (const id of followerIds) {\n const json = await this.kv.get([...this.prefixes.followers, id]);\n let actor: Object;\n try {\n actor = await Object.fromJsonLd(json);\n } catch (e) {\n if (e instanceof TypeError) continue;\n throw e;\n }\n if (isActor(actor)) yield actor;\n }\n }\n\n async countFollowers(): Promise<number> {\n const followerIds = await this.kv.get<string[]>(this.prefixes.followers) ??\n [];\n return followerIds.length;\n }\n\n async addSentFollow(id: Uuid, follow: Follow): Promise<void> {\n await this.kv.set(\n [...this.prefixes.follows, id],\n await follow.toJsonLd({ format: \"compact\" }),\n );\n }\n\n async removeSentFollow(id: Uuid): Promise<Follow | undefined> {\n const follow = await this.getSentFollow(id);\n if (follow == null) return undefined;\n await this.kv.delete([...this.prefixes.follows, id]);\n return follow;\n }\n\n async getSentFollow(id: Uuid): Promise<Follow | undefined> {\n const followJson = await this.kv.get([...this.prefixes.follows, id]);\n if (followJson == null) return undefined;\n try {\n return await Follow.fromJsonLd(followJson);\n } catch {\n return undefined;\n }\n }\n\n async addFollowee(followeeId: URL, follow: Follow): Promise<void> {\n await this.kv.set(\n [...this.prefixes.followees, followeeId.href],\n await follow.toJsonLd({ format: \"compact\" }),\n );\n }\n\n async removeFollowee(followeeId: URL): Promise<Follow | undefined> {\n const follow = await this.getFollowee(followeeId);\n if (follow == null) return undefined;\n await this.kv.delete([...this.prefixes.followees, followeeId.href]);\n return follow;\n }\n\n async getFollowee(followeeId: URL): Promise<Follow | undefined> {\n const json = await this.kv.get([\n ...this.prefixes.followees,\n followeeId.href,\n ]);\n if (json == null) return undefined;\n try {\n return await Follow.fromJsonLd(json);\n } catch {\n return undefined;\n }\n }\n}\n\ninterface KeyPair {\n private: JsonWebKey;\n public: JsonWebKey;\n}\n\n/**\n * Extracts the timestamp from a UUIDv7.\n * @param uuid The UUIDv7 string to extract the timestamp from.\n * @return The timestamp in milliseconds since the Unix epoch.\n * @internal\n */\nfunction extractTimestamp(uuid: string): number {\n // UUIDv7 format: xxxxxxxx-xxxx-7xxx-xxxx-xxxxxxxxxxxx\n // The timestamp is in the first 6 bytes (48 bits) of the UUID.\n if (uuid.length !== 36 || uuid[14] !== \"7\") {\n throw new TypeError(\"Invalid UUIDv7 format.\");\n }\n const timestampHex = uuid.slice(0, 8) + uuid.slice(9, 13);\n return parseInt(timestampHex, 16);\n}\n\n/**\n * A repository for storing bot data in memory. This repository is not\n * persistent and is only suitable for testing or development.\n */\nexport class MemoryRepository implements Repository {\n keyPairs?: CryptoKeyPair[];\n messages: Map<Uuid, Create | Announce> = new Map();\n followers: Map<string, Actor> = new Map();\n followRequests: Record<string, string> = {};\n sentFollows: Record<string, Follow> = {};\n followees: Record<string, Follow> = {};\n\n setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void> {\n this.keyPairs = keyPairs;\n return Promise.resolve();\n }\n\n getKeyPairs(): Promise<CryptoKeyPair[] | undefined> {\n return Promise.resolve(this.keyPairs);\n }\n\n addMessage(id: Uuid, activity: Create | Announce): Promise<void> {\n this.messages.set(id, activity);\n return Promise.resolve();\n }\n\n async updateMessage(\n id: Uuid,\n updater: (\n existing: Create | Announce,\n ) => Create | Announce | undefined | Promise<Create | Announce | undefined>,\n ): Promise<boolean> {\n const existing = this.messages.get(id);\n if (existing == null) return false;\n const newActivity = await updater(existing);\n if (newActivity == null) return false;\n this.messages.set(id, newActivity);\n return true;\n }\n\n removeMessage(id: Uuid): Promise<Create | Announce | undefined> {\n const activity = this.messages.get(id);\n this.messages.delete(id);\n return Promise.resolve(activity);\n }\n\n async *getMessages(\n options: RepositoryGetMessagesOptions = {},\n ): AsyncIterable<Create | Announce> {\n const { order, until, since, limit } = options;\n let messages = [...this.messages.values()];\n if (since != null) {\n messages = messages.filter((message) =>\n message.published != null &&\n Temporal.Instant.compare(message.published, since) >= 0\n );\n }\n if (until != null) {\n messages = messages.filter((message) =>\n message.published != null &&\n Temporal.Instant.compare(message.published, until) <= 0\n );\n }\n if (order === \"oldest\") {\n messages.sort((a, b) =>\n (a.published?.epochMilliseconds ?? 0) -\n (b.published?.epochMilliseconds ?? 0)\n );\n } else {\n messages.sort((a, b) =>\n (b.published?.epochMilliseconds ?? 0) -\n (a.published?.epochMilliseconds ?? 0)\n );\n }\n if (limit != null) {\n messages.slice(0, limit);\n }\n for (const message of messages) yield message;\n }\n\n getMessage(id: Uuid): Promise<Create | Announce | undefined> {\n return Promise.resolve(this.messages.get(id));\n }\n\n countMessages(): Promise<number> {\n return Promise.resolve(this.messages.size);\n }\n\n addFollower(followId: URL, follower: Actor): Promise<void> {\n if (follower.id == null) {\n throw new TypeError(\"The follower ID is missing.\");\n }\n this.followers.set(follower.id.href, follower);\n this.followRequests[followId.href] = follower.id.href;\n return Promise.resolve();\n }\n\n removeFollower(followId: URL, followerId: URL): Promise<Actor | undefined> {\n const existing = this.followRequests[followId.href];\n if (existing == null || existing !== followerId.href) {\n return Promise.resolve(undefined);\n }\n delete this.followRequests[followId.href];\n const follower = this.followers.get(followerId.href);\n this.followers.delete(followerId.href);\n return Promise.resolve(follower);\n }\n\n hasFollower(followerId: URL): Promise<boolean> {\n return Promise.resolve(this.followers.has(followerId.href));\n }\n\n async *getFollowers(\n options: RepositoryGetFollowersOptions = {},\n ): AsyncIterable<Actor> {\n const { offset = 0, limit } = options;\n let followers = [...this.followers.values()];\n followers.sort((a, b) => b.id!.href.localeCompare(a.id!.href) ?? 0);\n if (offset > 0) {\n followers = followers.slice(offset);\n }\n if (limit != null) {\n followers = followers.slice(0, limit);\n }\n for (const follower of followers) {\n yield follower;\n }\n }\n\n countFollowers(): Promise<number> {\n return Promise.resolve(this.followers.size);\n }\n\n addSentFollow(id: Uuid, follow: Follow): Promise<void> {\n this.sentFollows[id] = follow;\n return Promise.resolve();\n }\n\n removeSentFollow(id: Uuid): Promise<Follow | undefined> {\n const follow = this.sentFollows[id];\n delete this.sentFollows[id];\n return Promise.resolve(follow);\n }\n\n getSentFollow(id: Uuid): Promise<Follow | undefined> {\n return Promise.resolve(this.sentFollows[id]);\n }\n\n addFollowee(followeeId: URL, follow: Follow): Promise<void> {\n this.followees[followeeId.href] = follow;\n return Promise.resolve();\n }\n\n removeFollowee(followeeId: URL): Promise<Follow | undefined> {\n const follow = this.followees[followeeId.href];\n delete this.followees[followeeId.href];\n return Promise.resolve(follow);\n }\n\n getFollowee(followeeId: URL): Promise<Follow | undefined> {\n return Promise.resolve(this.followees[followeeId.href]);\n }\n}\n\n/**\n * A repository decorator that adds an in-memory cache layer on top of another\n * repository. This is useful for improving performance by reducing the number\n * of accesses to the underlying persistent storage, but it increases memory\n * usage. The cache is not persistent and will be lost when the process exits.\n *\n * Note: List operations like `getMessages` and `getFollowers`, and count\n * operations like `countMessages` and `countFollowers` are not cached and\n * always delegate to the underlying repository.\n * @since 0.3.0\n */\nexport class MemoryCachedRepository implements Repository {\n private underlying: Repository;\n private cache: MemoryRepository;\n\n /**\n * Creates a new memory-cached repository.\n * @param underlying The underlying repository to cache.\n * @param cache An optional `MemoryRepository` instance to use as the cache.\n * If not provided, a new one will be created internally.\n */\n constructor(underlying: Repository, cache?: MemoryRepository) {\n this.underlying = underlying;\n this.cache = cache ?? new MemoryRepository();\n }\n\n async setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void> {\n await this.underlying.setKeyPairs(keyPairs);\n await this.cache.setKeyPairs(keyPairs);\n }\n\n async getKeyPairs(): Promise<CryptoKeyPair[] | undefined> {\n let keyPairs = await this.cache.getKeyPairs();\n if (keyPairs === undefined) {\n keyPairs = await this.underlying.getKeyPairs();\n if (keyPairs !== undefined) await this.cache.setKeyPairs(keyPairs);\n }\n return keyPairs;\n }\n\n async addMessage(id: Uuid, activity: Create | Announce): Promise<void> {\n await this.underlying.addMessage(id, activity);\n await this.cache.addMessage(id, activity);\n }\n\n async updateMessage(\n id: Uuid,\n updater: (\n existing: Create | Announce,\n ) => Create | Announce | undefined | Promise<Create | Announce | undefined>,\n ): Promise<boolean> {\n // Apply update to underlying first\n const updated = await this.underlying.updateMessage(id, updater);\n if (updated) {\n // If successful, fetch the updated message and update the cache\n const updatedMessage = await this.underlying.getMessage(id);\n if (updatedMessage) {\n await this.cache.addMessage(id, updatedMessage); // Use addMessage which acts like set\n } else {\n // Should not happen if updateMessage returned true, but handle defensively\n await this.cache.removeMessage(id);\n }\n }\n return updated;\n }\n\n async removeMessage(id: Uuid): Promise<Create | Announce | undefined> {\n const removedActivity = await this.underlying.removeMessage(id);\n if (removedActivity !== undefined) {\n await this.cache.removeMessage(id);\n }\n return removedActivity;\n }\n\n // getMessages is not cached due to complexity with options\n getMessages(\n options?: RepositoryGetMessagesOptions,\n ): AsyncIterable<Create | Announce> {\n return this.underlying.getMessages(options);\n }\n\n async getMessage(id: Uuid): Promise<Create | Announce | undefined> {\n let message = await this.cache.getMessage(id);\n if (message === undefined) {\n message = await this.underlying.getMessage(id);\n if (message !== undefined) {\n await this.cache.addMessage(id, message); // Use addMessage which acts like set\n }\n }\n return message;\n }\n\n // countMessages is not cached\n countMessages(): Promise<number> {\n return this.underlying.countMessages();\n }\n\n async addFollower(followId: URL, follower: Actor): Promise<void> {\n await this.underlying.addFollower(followId, follower);\n await this.cache.addFollower(followId, follower);\n }\n\n async removeFollower(\n followId: URL,\n followerId: URL,\n ): Promise<Actor | undefined> {\n const removedFollower = await this.underlying.removeFollower(\n followId,\n followerId,\n );\n if (removedFollower !== undefined) {\n await this.cache.removeFollower(followId, followerId);\n }\n return removedFollower;\n }\n\n async hasFollower(followerId: URL): Promise<boolean> {\n // Check cache first for potentially faster response\n if (await this.cache.hasFollower(followerId)) {\n return true;\n }\n // If not in cache, check underlying and update cache if found\n const exists = await this.underlying.hasFollower(followerId);\n // Note: We don't automatically add to cache here, as we don't have the Actor object\n // It will be cached if addFollower is called or if getFollowers iterates over it (though getFollowers isn't cached)\n return exists;\n }\n\n // getFollowers is not cached due to complexity with options\n getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor> {\n // We could potentially cache followers as they are iterated,\n // but for simplicity, delegate directly for now.\n return this.underlying.getFollowers(options);\n }\n\n // countFollowers is not cached\n countFollowers(): Promise<number> {\n return this.underlying.countFollowers();\n }\n\n async addSentFollow(id: Uuid, follow: Follow): Promise<void> {\n await this.underlying.addSentFollow(id, follow);\n await this.cache.addSentFollow(id, follow);\n }\n\n async removeSentFollow(id: Uuid): Promise<Follow | undefined> {\n const removedFollow = await this.underlying.removeSentFollow(id);\n if (removedFollow !== undefined) {\n await this.cache.removeSentFollow(id);\n }\n return removedFollow;\n }\n\n async getSentFollow(id: Uuid): Promise<Follow | undefined> {\n let follow = await this.cache.getSentFollow(id);\n if (follow === undefined) {\n follow = await this.underlying.getSentFollow(id);\n if (follow !== undefined) {\n await this.cache.addSentFollow(id, follow);\n }\n }\n return follow;\n }\n\n async addFollowee(followeeId: URL, follow: Follow): Promise<void> {\n await this.underlying.addFollowee(followeeId, follow);\n await this.cache.addFollowee(followeeId, follow);\n }\n\n async removeFollowee(followeeId: URL): Promise<Follow | undefined> {\n const removedFollow = await this.underlying.removeFollowee(followeeId);\n if (removedFollow !== undefined) {\n await this.cache.removeFollowee(followeeId);\n }\n return removedFollow;\n }\n\n async getFollowee(followeeId: URL): Promise<Follow | undefined> {\n let follow = await this.cache.getFollowee(followeeId);\n if (follow === undefined) {\n follow = await this.underlying.getFollowee(followeeId);\n if (follow !== undefined) {\n await this.cache.addFollowee(followeeId, follow);\n }\n }\n return follow;\n }\n}\n"],"mappings":";;;;;;;;;;;AA8RA,IAAa,eAAb,MAAgD;CAC9C,AAAS;CACT,AAAS;;;;;;CAOT,YAAYA,IAAaC,UAAsC;AAC7D,OAAK,KAAK;AACV,OAAK,WAAW;GACd,UAAU,CAAC,WAAW,UAAW;GACjC,UAAU,CAAC,WAAW,UAAW;GACjC,WAAW,CAAC,WAAW,WAAY;GACnC,gBAAgB,CAAC,WAAW,gBAAiB;GAC7C,WAAW,CAAC,WAAW,WAAY;GACnC,SAAS,CAAC,WAAW,SAAU;GAC/B,GAAG,YAAY,CAAE;EAClB;CACF;CAED,MAAM,YAAYC,UAA0C;EAC1D,MAAMC,QAAmB,CAAE;AAC3B,OAAK,MAAM,WAAW,UAAU;GAC9B,MAAMC,OAAgB;IACpB,SAAS,MAAM,UAAU,QAAQ,WAAW;IAC5C,QAAQ,MAAM,UAAU,QAAQ,UAAU;GAC3C;AACD,SAAM,KAAK,KAAK;EACjB;AACD,QAAM,KAAK,GAAG,IAAI,KAAK,SAAS,UAAU,MAAM;CACjD;CAED,MAAM,cAAoD;EACxD,MAAM,WAAW,MAAM,KAAK,GAAG,IAAe,KAAK,SAAS,SAAS;AACrE,MAAI,YAAY,KAAM;EACtB,MAAM,WAAW,SAAS,IAAI,OAAO,UAAU;GAC7C,YAAY,MAAM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