Skip to content

Commit 1b9cba8

Browse files
committed
Twoslash
1 parent d98ac46 commit 1b9cba8

21 files changed

+1332
-240
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"srvx",
7171
"Tailscale",
7272
"tsdown",
73+
"twoslash",
7374
"unfollow",
7475
"unfollowed",
7576
"unfollowing",

CHANGES.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,22 @@ Version 0.3.0
66

77
To be released.
88

9-
- Added `MemoryCachedRepository` class.
9+
- BotKit now supports Node.js alongside of Deno. The minimum required
10+
version of Node.js is 22.0.0.
11+
12+
- Added `@fedify/botkit/repository` module that provides repository
13+
implementations for BotKit.
14+
15+
- Added `RepositoryGetMessagesOptions` interface.
16+
- Added `RepositoryGetFollowersOptions` interface.
17+
- Added `Uuid` type.
18+
- Added `KvKey` type.
19+
- Added `KvStore` type.
20+
- Added `KvStoreRepositoryPrefixes` interface.
21+
- Added `Announce` class.
22+
- Added `Create` class.
23+
- Added `MemoryCachedRepository` class.
24+
1025
- Upgraded Fedify to 1.6.1.
1126

1227

deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"./follow": "./src/follow.ts",
1515
"./message": "./src/message.ts",
1616
"./reaction": "./src/reaction.ts",
17+
"./repository": "./src/repository.ts",
1718
"./session": "./src/session.ts",
1819
"./text": "./src/text.ts"
1920
},

deno.lock

Lines changed: 0 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/.vitepress/config.mts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
12
import deflist from "markdown-it-deflist";
23
import footnote from "markdown-it-footnote";
34
import { jsrRef } from "markdown-it-jsr-ref";
45
import process from "node:process";
6+
import { ModuleKind, ModuleResolutionKind } from "typescript";
57
import { defineConfig } from "vitepress";
68
import {
79
groupIconMdPlugin,
@@ -153,6 +155,18 @@ export default defineConfig({
153155
ignoreDeadLinks: true,
154156

155157
markdown: {
158+
codeTransformers: [
159+
transformerTwoslash({
160+
twoslashOptions: {
161+
compilerOptions: {
162+
lib: ["dom", "dom.iterable", "esnext"],
163+
types: ["dom", "dom.iterable", "esnext", "@types/deno", "node"],
164+
moduleResolution: ModuleResolutionKind.Bundler,
165+
module: ModuleKind.ESNext,
166+
},
167+
},
168+
}),
169+
],
156170
config(md) {
157171
md.use(deflist);
158172
md.use(footnote);

docs/.vitepress/theme/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// https://vitepress.dev/guide/custom-theme
2+
import TwoslashFloatingVue from "@shikijs/vitepress-twoslash/client";
3+
import "@shikijs/vitepress-twoslash/style.css";
24
import "virtual:group-icons.css";
3-
import type { Theme } from "vitepress";
5+
import type { EnhanceAppContext, Theme } from "vitepress";
46
import DefaultTheme from "vitepress/theme";
57
import { h } from "vue";
68
import "./style.css";
@@ -12,7 +14,7 @@ export default {
1214
// https://vitepress.dev/guide/extending-default-theme#layout-slots
1315
});
1416
},
15-
enhanceApp({ app, router, siteData }) {
16-
// ...
17+
enhanceApp({ app, router, siteData }: EnhanceAppContext) {
18+
app.use(TwoslashFloatingVue);
1719
},
1820
} satisfies Theme;

docs/concepts/bot.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ Instantiation
1919

2020
You can instantiate a `Bot` instance by calling the `createBot()` function:
2121

22-
~~~~ typescript
23-
import { createBot } from "@fedify/bot";
22+
~~~~ typescript twoslash
23+
import { createBot } from "@fedify/botkit";
2424
import { MemoryKvStore } from "@fedify/fedify";
2525

2626
const bot = createBot<void>({
2727
username: "my_bot",
28-
kv: new MemoryKvStore(kv),
28+
kv: new MemoryKvStore(),
2929
});
3030
~~~~
3131

@@ -155,7 +155,8 @@ about the bot like the website URL, the source code repository URL, etc. here.
155155
Note that the property names should be human-readable and property values are of
156156
the `Text` type (see also the [*Text* chapter](./text.md)):
157157

158-
~~~~ typescript
158+
~~~~ typescript twoslash
159+
// @noErrors: 2345
159160
import { createBot, link, mention } from "@fedify/botkit";
160161

161162
const bot = createBot<void>({
@@ -239,7 +240,8 @@ It consists of the following properties:
239240
: The version of the bot software. It should be a `SemVer` object.
240241
You can create a `SemVer` object using the `parseSemVer()` function:
241242

242-
~~~~ typescript
243+
~~~~ typescript twoslash
244+
// @noErrors: 2345
243245
import { createBot, parseSemVer } from "@fedify/botkit";
244246

245247
const bot = createBot<void>({
@@ -332,8 +334,9 @@ or [srvx] on Node.js.
332334
For example, if you have a `Bot` object named `bot`, and `export` it as
333335
a default export:
334336

335-
~~~~ typescript [bot.ts]
336-
import { createBot } from "@fedify/bot";
337+
~~~~ typescript [bot.ts] twoslash
338+
// @noErrors: 2345
339+
import { createBot } from "@fedify/botkit";
337340

338341
const bot = createBot<void>({
339342
// Omitted other options for brevity
@@ -386,14 +389,18 @@ yarn add srvx
386389

387390
Then, import [`serve()`] function from `srvx` module:
388391

389-
~~~~ typescript [bot.ts]
392+
~~~~ typescript [bot.ts] twoslash
390393
import { serve } from "srvx";
391394
~~~~
392395

393396
Finally, you can run the bot using the [`serve()`] function at the end of
394397
the *bot.ts* file:
395398

396-
~~~~ typescript [bot.ts]
399+
~~~~ typescript [bot.ts] twoslash
400+
import type { Bot } from "@fedify/botkit";
401+
import { serve } from "srvx";
402+
const bot = {} as unknown as Bot<void>;
403+
// ---cut-before---
397404
const server = serve({
398405
...bot,
399406
port: 8000,
@@ -426,8 +433,11 @@ It is recommended to have an environment variable to control
426433
the [`behindProxy`](#createbotoptions-behindproxy) option so that you can
427434
easily switch between local development and production:
428435

429-
~~~~ typescript [bot.ts] {3-4,8}
430-
import { createBot } from "@fedify/bot";
436+
::: code-group
437+
438+
~~~~ typescript [Deno] {3-4,8} twoslash
439+
// @noErrors: 2345
440+
import { createBot } from "@fedify/botkit";
431441

432442
const BEHIND_PROXY =
433443
Deno.env.get("BEHIND_PROXY")?.trim()?.toLowerCase() === "true";
@@ -438,6 +448,21 @@ const bot = createBot<void>({
438448
});
439449
~~~~
440450

451+
~~~~ typescript [Node.js] {3-4,8} twoslash
452+
// @noErrors: 2345
453+
import { createBot } from "@fedify/botkit";
454+
455+
const BEHIND_PROXY =
456+
process.env.BEHIND_PROXY?.trim()?.toLowerCase() === "true";
457+
458+
const bot = createBot<void>({
459+
// Omitted other options for brevity
460+
behindProxy: BEHIND_PROXY,
461+
});
462+
~~~~
463+
464+
:::
465+
441466
Then, you can use the following command to run the bot with the `BEHIND_PROXY`
442467
environment variable set to `true`:
443468

0 commit comments

Comments
 (0)