From 17e4d4318e69648126da6d3bc9457e3298cc28fa Mon Sep 17 00:00:00 2001 From: Roz Date: Thu, 13 Aug 2026 16:20:31 +0200 Subject: [PATCH] wip: update dependency version and imports --- README.md | 19 ++++++++----------- deno.jsonc | 8 +++++--- examples/bot.tsx | 2 +- examples/core/slideshow.ts | 2 +- src/chaining/message.ts | 2 +- src/chaining/table.ts | 2 +- src/components/blocks.ts | 2 +- src/components/text.ts | 2 +- src/core/blocks.ts | 4 ++-- src/core/message.ts | 2 +- src/core/shared.ts | 13 +++---------- src/core/text.ts | 2 +- src/core/values.ts | 2 +- test/chaining.test.ts | 2 +- test/functions.test.tsx | 2 +- test/types.test.tsx | 2 +- 16 files changed, 30 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 20a5800..078baf4 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ If you prefer package-style specifiers, add optional aliases for the surfaces yo "imports": { "@grammyjs/format/core": "https://denopkg.com/roziscoding/@grammyjs/format/src/core.ts", "@grammyjs/format/components": "https://denopkg.com/roziscoding/@grammyjs/format/src/components.ts", - "@grammyjs/format/chaining": "https://denopkg.com/roziscoding/@grammyjs/format/src/chaining.ts", - }, + "@grammyjs/format/chaining": "https://denopkg.com/roziscoding/@grammyjs/format/src/chaining.ts" + } } ``` @@ -50,7 +50,7 @@ The examples below use these package-style specifiers; on Deno, either add the m This library only builds the message object. grammY already exposes the Bot API's `ctx.replyWithRichMessage`, so composing and sending stay separate — compose with any of the [APIs below](#the-three-apis), then hand the result to grammY: ```tsx -import { Bot } from "grammy"; +import { Bot } from "@grammyjs/grammy"; import { Bold, Paragraph, richMessage } from "@grammyjs/format/components"; const bot = new Bot(process.env.TELEGRAM_TOKEN!); @@ -62,8 +62,7 @@ bot.command("start", (ctx) => Hello, {ctx.from?.first_name ?? "there"}! , ), - ), -); + )); bot.start(); ``` @@ -139,14 +138,12 @@ const message = new RichMessage({ skipEntityDetection: true }) .row((row) => row .cell("Model", { header: true }) - .cell("Score", { header: true, align: "right" }), + .cell("Score", { header: true, align: "right" }) ) .rows(results, (row, result) => row .cell(result.model) - .cell(bold(result.score), { align: "right" }), - ), - ); + .cell(bold(result.score), { align: "right" }))); ``` A `RichMessage` instance `implements InputRichMessage`, so it goes straight to grammY (or any Bot API client) and serializes to the canonical value via `toJSON()`. Every functional block builder has a matching method, including media (`photo`, `video`, …) and containers (`blockQuote`, `collage`, `details`, …). Use `.add(block)` to append any pre-built block, and read the `blocks` getter for a snapshot that later mutations don't change. @@ -169,8 +166,8 @@ For Deno, add the JSX runtime import alias so the compiler can resolve `jsxImpor ```jsonc { "imports": { - "@grammyjs/format/jsx/jsx-runtime": "https://denopkg.com/roziscoding/@grammyjs/format/src/components/jsx-runtime.ts", - }, + "@grammyjs/format/jsx/jsx-runtime": "https://denopkg.com/roziscoding/@grammyjs/format/src/components/jsx-runtime.ts" + } } ``` diff --git a/deno.jsonc b/deno.jsonc index 1ad439d..6afae18 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -16,9 +16,9 @@ "imports": { "@grammyjs/format/jsx/jsx-runtime": "./src/components/jsx-runtime.ts", "@grammyjs/format/jsx/jsx-dev-runtime": "./src/components/jsx-runtime.ts", + "@grammyjs/grammy": "jsr:@grammyjs/grammy@2.0.0-beta.8", "@std/expect": "jsr:@std/expect@^1", - "@std/testing": "jsr:@std/testing@^1", - "grammy": "npm:grammy@^1.45.1" + "@std/testing": "jsr:@std/testing@^1" }, "tasks": { "check": "deno check --allow-import src/core.ts src/components.ts src/chaining.ts test/ examples/", @@ -36,5 +36,7 @@ "rules": { "exclude": ["explicit-function-return-type"] } - } + }, + // TODO: Remove this (?) + "minimumDependencyAge": { "age": 0 } } diff --git a/examples/bot.tsx b/examples/bot.tsx index 60b2fe1..1ff7c4f 100644 --- a/examples/bot.tsx +++ b/examples/bot.tsx @@ -1,4 +1,4 @@ -import { Bot } from "grammy"; +import { Bot } from "@grammyjs/grammy"; import { Bold, Divider, diff --git a/examples/core/slideshow.ts b/examples/core/slideshow.ts index 896f2cc..4057f18 100644 --- a/examples/core/slideshow.ts +++ b/examples/core/slideshow.ts @@ -1,4 +1,4 @@ -import { Bot } from "grammy"; +import { Bot } from "@grammyjs/grammy"; import { divider, photo, richMessage, slideshow } from "../../src/core.ts"; const bot = new Bot(process.env.BOT_TOKEN!); diff --git a/src/chaining/message.ts b/src/chaining/message.ts index c02cff2..d7a9a6b 100644 --- a/src/chaining/message.ts +++ b/src/chaining/message.ts @@ -41,7 +41,7 @@ import { cloneValue, type RichMessageValue, } from "../core/values.ts"; -import type { InputRichMessage } from "grammy/types"; +import type { InputRichMessage } from "@grammyjs/grammy/types"; import { TableBuilder, type TableConfigurator } from "./table.ts"; /** diff --git a/src/chaining/table.ts b/src/chaining/table.ts index 3bfd725..4671d07 100644 --- a/src/chaining/table.ts +++ b/src/chaining/table.ts @@ -12,7 +12,7 @@ import { type TableCellValue, type TableRowValue, } from "../core/values.ts"; -import type { InputRichBlockTable } from "grammy/types"; +import type { InputRichBlockTable } from "@grammyjs/grammy/types"; /** * Callback that populates a {@link TableRowBuilder}. Receives the row builder diff --git a/src/components/blocks.ts b/src/components/blocks.ts index 934a76d..ecfecce 100644 --- a/src/components/blocks.ts +++ b/src/components/blocks.ts @@ -7,7 +7,7 @@ import type { InputMediaVoiceNote, InputRichBlock, Location, -} from "grammy/types"; +} from "@grammyjs/grammy/types"; import * as Blocks from "../core/blocks.ts"; import type { RichTextInput } from "../core/text.ts"; import type { diff --git a/src/components/text.ts b/src/components/text.ts index e99d150..9a3b32a 100644 --- a/src/components/text.ts +++ b/src/components/text.ts @@ -2,7 +2,7 @@ import type { Child } from "./jsx-runtime.ts"; import * as Text from "../core/text.ts"; import type { ChildrenProps, NoChildrenProps } from "./shared.ts"; import type { RichTextValue } from "../core/values.ts"; -import type * as grammY from "grammy/types"; +import type * as grammY from "@grammyjs/grammy/types"; function richChildren(children: Child): Text.RichTextInput[] { return children === undefined ? [] : [children as Text.RichTextInput]; diff --git a/src/core/blocks.ts b/src/core/blocks.ts index 5b161da..6ad82b6 100644 --- a/src/core/blocks.ts +++ b/src/core/blocks.ts @@ -8,7 +8,7 @@ import type { InputRichBlockListItem, Location, RichBlockTableCell, -} from "grammy/types"; +} from "@grammyjs/grammy/types"; import { brand, type BlockValueOf, @@ -115,7 +115,7 @@ export interface HeadingOptions { export function heading( options: HeadingOptions, ...children: readonly RichTextInput[] -): ReturnType { +): BrandedValue { return block({ type: "heading", text: richText(children, "heading()"), diff --git a/src/core/message.ts b/src/core/message.ts index 6a16b0a..3f6e9c8 100644 --- a/src/core/message.ts +++ b/src/core/message.ts @@ -1,4 +1,4 @@ -import type { InputRichMessage } from "grammy/types"; +import type { InputRichMessage } from "@grammyjs/grammy/types"; import { brand, type RichMessageValue } from "../core/values.ts"; import { type BlockInput, blocks, splitOptions } from "./shared.ts"; diff --git a/src/core/shared.ts b/src/core/shared.ts index 6acaef8..9a52934 100644 --- a/src/core/shared.ts +++ b/src/core/shared.ts @@ -1,4 +1,4 @@ -import type { RichBlockCaption, RichText } from "grammy/types"; +import type { RichBlockCaption, RichText } from "@grammyjs/grammy/types"; import { type BlockValue, kindOf, @@ -72,17 +72,10 @@ function describe(value: unknown): string { export function richText( values: readonly unknown[], context: string, -): RichText { +): RichText | RichText[]{ const parts: RichText[] = []; for (const item of flattenInputs(values)) { - if (item == null || typeof item === "boolean") continue; - if (typeof item === "string" || typeof item === "number") { - const text = String(item); - const last = parts.at(-1); - if (typeof last === "string") parts[parts.length - 1] = last + text; - else parts.push(text); - continue; - } + if (item == null || typeof item === "boolean" || typeof item === "string" || typeof item === "number") continue; if (kindOf(item) !== "rich-text") { throw new TypeError( `${context} only accepts rich-text children, received ${ diff --git a/src/core/text.ts b/src/core/text.ts index d226284..505348c 100644 --- a/src/core/text.ts +++ b/src/core/text.ts @@ -1,4 +1,4 @@ -import type * as grammY from "grammy/types"; +import type * as grammY from "@grammyjs/grammy/types"; import { brand, type RichTextValue } from "../core/values.ts"; import { assertNoChildren, richText, type RichTextInput } from "./shared.ts"; diff --git a/src/core/values.ts b/src/core/values.ts index e4e5cf8..35c2835 100644 --- a/src/core/values.ts +++ b/src/core/values.ts @@ -4,7 +4,7 @@ import type { InputRichMessage, RichBlockTableCell, RichText, -} from "grammy/types"; +} from "@grammyjs/grammy/types"; const valueKindKey = "__telegramRichMessagesValueKind" as const; type ValueKind = diff --git a/test/chaining.test.ts b/test/chaining.test.ts index a6cb518..e608a09 100644 --- a/test/chaining.test.ts +++ b/test/chaining.test.ts @@ -6,7 +6,7 @@ import type { InputRichBlockParagraph, InputRichMessage, RichBlockTableCell, -} from "grammy/types"; +} from "@grammyjs/grammy/types"; const results = [ { model: "Aster-1", score: 98.4 }, diff --git a/test/functions.test.tsx b/test/functions.test.tsx index 626e18d..cc8f8e5 100644 --- a/test/functions.test.tsx +++ b/test/functions.test.tsx @@ -1,7 +1,7 @@ import { expect } from "@std/expect"; import { it as test } from "@std/testing/bdd"; import * as rm from "../src/core.ts"; -import type { RichText } from "grammy/types"; +import type { RichText } from "@grammyjs/grammy/types"; import { bold, italic, diff --git a/test/types.test.tsx b/test/types.test.tsx index c1bdabf..dcc4ba1 100644 --- a/test/types.test.tsx +++ b/test/types.test.tsx @@ -17,7 +17,7 @@ import type { InputRichMessage, MessageEntity, RichBlockTableCell, -} from "grammy/types"; +} from "@grammyjs/grammy/types"; import type { TableRowValue } from "../src/core.ts"; function expectType(_value: T): void {}