[0],
...forbiddenChildren(children),
);
}
@@ -275,9 +240,9 @@ export function Animation(
& { media: InputMediaAnimation }
& CaptionProps
& NoChildrenProps,
-) {
- return animation(
- options as AnimationOptions,
+): BlockValueOf<"animation"> {
+ return Blocks.animation(
+ options as Blocks.AnimationOptions,
...forbiddenChildren(children),
);
}
@@ -291,8 +256,8 @@ export function Audio(
& { media: InputMediaAudio }
& CaptionProps
& NoChildrenProps,
-) {
- return audio(options as AudioOptions, ...forbiddenChildren(children));
+): BlockValueOf<"audio"> {
+ return Blocks.audio(options as Blocks.AudioOptions, ...forbiddenChildren(children));
}
/**
* TSX component for a photo block. The TSX form of {@link photo}.
@@ -304,8 +269,8 @@ export function Photo(
& { media: InputMediaPhoto }
& CaptionProps
& NoChildrenProps,
-) {
- return photo(options as PhotoOptions, ...forbiddenChildren(children));
+): BlockValueOf<"photo"> {
+ return Blocks.photo(options as Blocks.PhotoOptions, ...forbiddenChildren(children));
}
/**
* TSX component for a video block. The TSX form of {@link video}.
@@ -317,8 +282,8 @@ export function Video(
& { media: InputMediaVideo }
& CaptionProps
& NoChildrenProps,
-) {
- return video(options as VideoOptions, ...forbiddenChildren(children));
+): BlockValueOf<"video"> {
+ return Blocks.video(options as Blocks.VideoOptions, ...forbiddenChildren(children));
}
/**
* TSX component for a voice note block. The TSX form of {@link voiceNote}.
@@ -330,9 +295,9 @@ export function VoiceNote(
& { media: InputMediaVoiceNote }
& CaptionProps
& NoChildrenProps,
-) {
- return voiceNote(
- options as VoiceNoteOptions,
+): BlockValueOf<"voice_note"> {
+ return Blocks.voiceNote(
+ options as Blocks.VoiceNoteOptions,
...forbiddenChildren(children),
);
}
@@ -341,6 +306,6 @@ export function VoiceNote(
* TSX component for a temporary thinking block. The TSX form of
* {@link thinking}.
*/
-export function Thinking({ children }: ChildrenProps) {
- return thinking(...richChildren(children));
+export function Thinking({ children }: ChildrenProps): BlockValueOf<"thinking"> {
+ return Blocks.thinking(...richChildren(children));
}
diff --git a/src/components/jsx-runtime.ts b/src/components/jsx-runtime.ts
index b17bbfd..056839b 100644
--- a/src/components/jsx-runtime.ts
+++ b/src/components/jsx-runtime.ts
@@ -78,7 +78,7 @@ export type Component> = (props: P) => Element;
/**
* Marker symbol used for JSX fragments (`<>...>`).
*/
-export const Fragment = Symbol.for("grammy-rich-messages.fragment");
+export const Fragment = Symbol.for("@grammyjs/format.fragment");
/**
* JSX factory the TypeScript compiler calls for each element. It is
diff --git a/src/components/message.ts b/src/components/message.ts
index 1e7774b..8ae2898 100644
--- a/src/components/message.ts
+++ b/src/components/message.ts
@@ -11,7 +11,7 @@ import type { ElementChild } from "./jsx-runtime.ts";
* `InputRichMessage` ready to send. This is the components entrypoint's
* root, which also accepts `JSX.Element` children and validates the
* composition at runtime, unlike the strict functional root in
- * `grammy-rich-messages/core`.
+ * `@grammyjs/format/core`.
*
* @param children Block elements and JSX children to compose into the message
*/
@@ -23,7 +23,7 @@ export function richMessage(
* `InputRichMessage` ready to send, applying the given message options.
* This is the components entrypoint's root, which also accepts
* `JSX.Element` children and validates the composition at runtime, unlike
- * the strict functional root in `grammy-rich-messages/core`.
+ * the strict functional root in `@grammyjs/format/core`.
*
* @param options Message-level options applied to the composed message
* @param children Block elements and JSX children to compose into the message
diff --git a/src/components/text.ts b/src/components/text.ts
index 350cc28..e99d150 100644
--- a/src/components/text.ts
+++ b/src/components/text.ts
@@ -1,38 +1,11 @@
import type { Child } from "./jsx-runtime.ts";
-import {
- anchorLink,
- bankCard,
- bold,
- botCommand,
- cashtag,
- code,
- customEmoji,
- dateTime,
- type DateTimeOptions,
- email,
- hashtag,
- inlineMath,
- italic,
- link,
- marked,
- mention,
- phone,
- reference,
- referenceLink,
- type RichTextInput,
- spoiler,
- strikethrough,
- subscript,
- superscript,
- textAnchor,
- textMention,
- type TextMentionOptions,
- underline,
-} from "../core/text.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";
-function richChildren(children: Child): RichTextInput[] {
- return children === undefined ? [] : [children as RichTextInput];
+function richChildren(children: Child): Text.RichTextInput[] {
+ return children === undefined ? [] : [children as Text.RichTextInput];
}
function forbiddenChildren(children: unknown): never[] {
@@ -42,60 +15,60 @@ function forbiddenChildren(children: unknown): never[] {
/**
* TSX component for a bold text span. The TSX form of {@link bold}.
*/
-export function Bold({ children }: ChildrenProps) {
- return bold(...richChildren(children));
+export function Bold({ children }: ChildrenProps): RichTextValue {
+ return Text.bold(...richChildren(children));
}
/**
* TSX component for an italic text span. The TSX form of {@link italic}.
*/
-export function Italic({ children }: ChildrenProps) {
- return italic(...richChildren(children));
+export function Italic({ children }: ChildrenProps): RichTextValue {
+ return Text.italic(...richChildren(children));
}
/**
* TSX component for an underlined text span. The TSX form of
* {@link underline}.
*/
-export function Underline({ children }: ChildrenProps) {
- return underline(...richChildren(children));
+export function Underline({ children }: ChildrenProps): RichTextValue {
+ return Text.underline(...richChildren(children));
}
/**
* TSX component for a strikethrough text span. The TSX form of
* {@link strikethrough}.
*/
-export function Strikethrough({ children }: ChildrenProps) {
- return strikethrough(...richChildren(children));
+export function Strikethrough({ children }: ChildrenProps): RichTextValue {
+ return Text.strikethrough(...richChildren(children));
}
/**
* TSX component for a spoiler text span. The TSX form of {@link spoiler}.
*/
-export function Spoiler({ children }: ChildrenProps) {
- return spoiler(...richChildren(children));
+export function Spoiler({ children }: ChildrenProps): RichTextValue {
+ return Text.spoiler(...richChildren(children));
}
/**
* TSX component for a subscript text span. The TSX form of
* {@link subscript}.
*/
-export function Subscript({ children }: ChildrenProps) {
- return subscript(...richChildren(children));
+export function Subscript({ children }: ChildrenProps): RichTextValue {
+ return Text.subscript(...richChildren(children));
}
/**
* TSX component for a superscript text span. The TSX form of
* {@link superscript}.
*/
-export function Superscript({ children }: ChildrenProps) {
- return superscript(...richChildren(children));
+export function Superscript({ children }: ChildrenProps): RichTextValue {
+ return Text.superscript(...richChildren(children));
}
/**
* TSX component for a marked text span. The TSX form of {@link marked}.
*/
-export function Marked({ children }: ChildrenProps) {
- return marked(...richChildren(children));
+export function Marked({ children }: ChildrenProps): RichTextValue {
+ return Text.marked(...richChildren(children));
}
/**
* TSX component for an inline code span. The TSX form of {@link code}.
*/
-export function Code({ children }: ChildrenProps) {
- return code(...richChildren(children));
+export function Code({ children }: ChildrenProps): RichTextValue {
+ return Text.code(...richChildren(children));
}
/**
@@ -104,9 +77,9 @@ export function Code({ children }: ChildrenProps) {
* @param props Component props, see {@link DateTimeOptions}
*/
export function DateTime(
- { children, ...options }: ChildrenProps & DateTimeOptions,
-) {
- return dateTime(options, ...richChildren(children));
+ { children, ...options }: ChildrenProps & Text.DateTimeOptions,
+): RichTextValue {
+ return Text.dateTime(options, ...richChildren(children));
}
/**
* TSX component for a text-mention entity. The TSX form of
@@ -115,9 +88,9 @@ export function DateTime(
* @param props Component props, see {@link TextMentionOptions}
*/
export function TextMention(
- { children, ...options }: ChildrenProps & TextMentionOptions,
-) {
- return textMention(options, ...richChildren(children));
+ { children, ...options }: ChildrenProps & Text.TextMentionOptions,
+): RichTextValue {
+ return Text.textMention(options, ...richChildren(children));
}
/**
* TSX component for a custom-emoji entity. The TSX form of
@@ -127,8 +100,8 @@ export function TextMention(
*/
export function CustomEmoji(
{ children, ...options }: { id: string; alt: string } & NoChildrenProps,
-) {
- return customEmoji(options, ...forbiddenChildren(children));
+): RichTextValue<{ type: "custom_emoji"; custom_emoji_id: string; alternative_text: string; }> {
+ return Text.customEmoji(options, ...forbiddenChildren(children));
}
/**
* TSX component for an inline-math entity. The TSX form of
@@ -138,8 +111,8 @@ export function CustomEmoji(
*/
export function InlineMath(
{ children, ...options }: { expression: string } & NoChildrenProps,
-) {
- return inlineMath(options, ...forbiddenChildren(children));
+): RichTextValue<{ type: "mathematical_expression"; expression: string; }> {
+ return Text.inlineMath(options, ...forbiddenChildren(children));
}
/**
* TSX component for a link entity. The TSX form of {@link link}.
@@ -148,8 +121,8 @@ export function InlineMath(
*/
export function Link(
{ children, ...options }: ChildrenProps & { url: string },
-) {
- return link(options, ...richChildren(children));
+): RichTextValue {
+ return Text.link(options, ...richChildren(children));
}
/**
* TSX component for an email entity. The TSX form of {@link email}.
@@ -158,8 +131,8 @@ export function Link(
*/
export function Email(
{ children, ...options }: ChildrenProps & { address: string },
-) {
- return email(options, ...richChildren(children));
+): RichTextValue {
+ return Text.email(options, ...richChildren(children));
}
/**
* TSX component for a phone-number entity. The TSX form of {@link phone}.
@@ -168,8 +141,8 @@ export function Email(
*/
export function Phone(
{ children, ...options }: ChildrenProps & { number: string },
-) {
- return phone(options, ...richChildren(children));
+): RichTextValue {
+ return Text.phone(options, ...richChildren(children));
}
/**
* TSX component for a bank-card entity. The TSX form of {@link bankCard}.
@@ -178,8 +151,8 @@ export function Phone(
*/
export function BankCard(
{ children, ...options }: ChildrenProps & { number: string },
-) {
- return bankCard(options, ...richChildren(children));
+): RichTextValue {
+ return Text.bankCard(options, ...richChildren(children));
}
/**
* TSX component for a mention entity. The TSX form of {@link mention}.
@@ -188,8 +161,8 @@ export function BankCard(
*/
export function Mention(
{ children, ...options }: ChildrenProps & { username: string },
-) {
- return mention(options, ...richChildren(children));
+): RichTextValue {
+ return Text.mention(options, ...richChildren(children));
}
/**
* TSX component for a hashtag entity. The TSX form of {@link hashtag}.
@@ -198,8 +171,8 @@ export function Mention(
*/
export function Hashtag(
{ children, ...options }: ChildrenProps & { value: string },
-) {
- return hashtag(options, ...richChildren(children));
+): RichTextValue {
+ return Text.hashtag(options, ...richChildren(children));
}
/**
* TSX component for a cashtag entity. The TSX form of {@link cashtag}.
@@ -208,8 +181,8 @@ export function Hashtag(
*/
export function Cashtag(
{ children, ...options }: ChildrenProps & { value: string },
-) {
- return cashtag(options, ...richChildren(children));
+): RichTextValue {
+ return Text.cashtag(options, ...richChildren(children));
}
/**
* TSX component for a bot-command entity. The TSX form of
@@ -219,8 +192,8 @@ export function Cashtag(
*/
export function BotCommand(
{ children, ...options }: ChildrenProps & { command: string },
-) {
- return botCommand(options, ...richChildren(children));
+): RichTextValue {
+ return Text.botCommand(options, ...richChildren(children));
}
/**
* TSX component for a text-anchor entity. The TSX form of
@@ -230,8 +203,8 @@ export function BotCommand(
*/
export function TextAnchor(
{ children, ...options }: { name: string } & NoChildrenProps,
-) {
- return textAnchor(options, ...forbiddenChildren(children));
+): RichTextValue<{ type: "anchor"; name: string; }> {
+ return Text.textAnchor(options, ...forbiddenChildren(children));
}
/**
* TSX component for an anchor-link entity. The TSX form of
@@ -241,8 +214,8 @@ export function TextAnchor(
*/
export function AnchorLink(
{ children, ...options }: ChildrenProps & { name: string },
-) {
- return anchorLink(options, ...richChildren(children));
+): RichTextValue {
+ return Text.anchorLink(options, ...richChildren(children));
}
/**
* TSX component for a reference entity. The TSX form of {@link reference}.
@@ -251,8 +224,8 @@ export function AnchorLink(
*/
export function Reference(
{ children, ...options }: ChildrenProps & { name: string },
-) {
- return reference(options, ...richChildren(children));
+): RichTextValue {
+ return Text.reference(options, ...richChildren(children));
}
/**
* TSX component for a reference-link entity. The TSX form of
@@ -262,6 +235,6 @@ export function Reference(
*/
export function ReferenceLink(
{ children, ...options }: ChildrenProps & { name: string },
-) {
- return referenceLink(options, ...richChildren(children));
+): RichTextValue {
+ return Text.referenceLink(options, ...richChildren(children));
}
diff --git a/src/core.ts b/src/core.ts
index ef15778..a20852a 100644
--- a/src/core.ts
+++ b/src/core.ts
@@ -1,13 +1,4 @@
export * from "./core/blocks.ts";
export * from "./core/message.ts";
export * from "./core/text.ts";
-export type {
- BlockValue,
- BlockValueOf,
- ListItemValue,
- RichMessageValue,
- RichTextValue,
- TableCellValue,
- TableRowValue,
-} from "./core/values.ts";
-export type * from "./deps.deno.ts";
+export * from "./core/values.ts";
diff --git a/src/core/blocks.ts b/src/core/blocks.ts
index 688d678..5b161da 100644
--- a/src/core/blocks.ts
+++ b/src/core/blocks.ts
@@ -8,28 +8,29 @@ import type {
InputRichBlockListItem,
Location,
RichBlockTableCell,
-} from "../deps.deno.ts";
+} from "grammy/types";
import {
- type BlockValueOf,
brand,
+ type BlockValueOf,
+ type BrandedValue,
type ListItemValue,
type TableCellValue,
type TableRowValue,
} from "../core/values.ts";
import {
assertNoChildren,
- type BlockInput,
blocks,
caption,
- type ListItemInput,
listItems,
richText,
- type RichTextInput,
splitOptions,
- type TableCellInput,
tableCells,
- type TableRowInput,
tableRows,
+ type BlockInput,
+ type ListItemInput,
+ type RichTextInput,
+ type TableCellInput,
+ type TableRowInput,
} from "./shared.ts";
export type {
@@ -52,7 +53,7 @@ export type CaptionOptions =
}
| { caption?: undefined; credit?: never };
-function block(value: T) {
+function block(value: T): BrandedValue {
return brand(value, "block");
}
@@ -74,7 +75,9 @@ function richTextBlock(
*
* @param children The rich-text children
*/
-export function paragraph(...children: readonly RichTextInput[]) {
+export function paragraph(
+ ...children: readonly RichTextInput[]
+): BlockValueOf<"paragraph"> {
return richTextBlock("paragraph", "paragraph()", children);
}
/**
@@ -82,7 +85,9 @@ export function paragraph(...children: readonly RichTextInput[]) {
*
* @param children The rich-text children
*/
-export function footer(...children: readonly RichTextInput[]) {
+export function footer(
+ ...children: readonly RichTextInput[]
+): BlockValueOf<"footer"> {
return richTextBlock("footer", "footer()", children);
}
/**
@@ -90,7 +95,9 @@ export function footer(...children: readonly RichTextInput[]) {
*
* @param children The rich-text children
*/
-export function thinking(...children: readonly RichTextInput[]) {
+export function thinking(
+ ...children: readonly RichTextInput[]
+): BlockValueOf<"thinking"> {
return richTextBlock("thinking", "thinking()", children);
}
@@ -108,7 +115,7 @@ export interface HeadingOptions {
export function heading(
options: HeadingOptions,
...children: readonly RichTextInput[]
-) {
+): ReturnType {
return block({
type: "heading",
text: richText(children, "heading()"),
@@ -162,7 +169,7 @@ export function pre(
*
* @param children Must be empty
*/
-export function divider(...children: readonly never[]) {
+export function divider(...children: readonly never[]): BrandedValue<{ type: "divider" }, "block"> {
assertNoChildren(children, "divider()");
return block({ type: "divider" });
}
@@ -180,7 +187,7 @@ export interface MathBlockOptions {
export function mathBlock(
options: MathBlockOptions,
...children: readonly never[]
-) {
+): BrandedValue<{ type: "mathematical_expression"; } & MathBlockOptions, "block"> {
assertNoChildren(children, "mathBlock()");
return block({
type: "mathematical_expression",
@@ -201,7 +208,7 @@ export interface BlockAnchorOptions {
export function blockAnchor(
options: BlockAnchorOptions,
...children: readonly never[]
-) {
+): BrandedValue<{ type: "anchor" } & BlockAnchorOptions, "block"> {
assertNoChildren(children, "blockAnchor()");
return block({ type: "anchor", name: options.name });
}
@@ -698,7 +705,7 @@ function media(
export function animation(
options: AnimationOptions,
...children: readonly never[]
-) {
+): BlockValueOf<"animation"> {
return media("animation", "animation()", options, children);
}
/**
@@ -707,7 +714,7 @@ export function animation(
* @param options The {@link AudioOptions}
* @param children Must be empty
*/
-export function audio(options: AudioOptions, ...children: readonly never[]) {
+export function audio(options: AudioOptions, ...children: readonly never[]): BlockValueOf<"audio"> {
return media("audio", "audio()", options, children);
}
/**
@@ -716,7 +723,7 @@ export function audio(options: AudioOptions, ...children: readonly never[]) {
* @param options The {@link PhotoOptions}
* @param children Must be empty
*/
-export function photo(options: PhotoOptions, ...children: readonly never[]) {
+export function photo(options: PhotoOptions, ...children: readonly never[]): BlockValueOf<"photo"> {
return media("photo", "photo()", options, children);
}
/**
@@ -725,7 +732,7 @@ export function photo(options: PhotoOptions, ...children: readonly never[]) {
* @param options The {@link VideoOptions}
* @param children Must be empty
*/
-export function video(options: VideoOptions, ...children: readonly never[]) {
+export function video(options: VideoOptions, ...children: readonly never[]): BlockValueOf<"video"> {
return media("video", "video()", options, children);
}
/**
@@ -737,6 +744,6 @@ export function video(options: VideoOptions, ...children: readonly never[]) {
export function voiceNote(
options: VoiceNoteOptions,
...children: readonly never[]
-) {
+): BlockValueOf<"voice_note"> {
return media("voice_note", "voiceNote()", options, children);
}
diff --git a/src/core/message.ts b/src/core/message.ts
index 361aeb5..6a16b0a 100644
--- a/src/core/message.ts
+++ b/src/core/message.ts
@@ -1,4 +1,4 @@
-import type { InputRichMessage } from "../deps.deno.ts";
+import type { InputRichMessage } from "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 72c9e5d..6acaef8 100644
--- a/src/core/shared.ts
+++ b/src/core/shared.ts
@@ -1,4 +1,4 @@
-import type { RichBlockCaption, RichText } from "../deps.deno.ts";
+import type { RichBlockCaption, RichText } from "grammy/types";
import {
type BlockValue,
kindOf,
diff --git a/src/core/text.ts b/src/core/text.ts
index d4ca795..d226284 100644
--- a/src/core/text.ts
+++ b/src/core/text.ts
@@ -1,20 +1,4 @@
-import type {
- RichText,
- RichTextAnchorLink,
- RichTextBankCardNumber,
- RichTextBotCommand,
- RichTextCashtag,
- RichTextDateTime,
- RichTextEmailAddress,
- RichTextHashtag,
- RichTextMention,
- RichTextPhoneNumber,
- RichTextReference,
- RichTextReferenceLink,
- RichTextTextMention,
- RichTextUrl,
- User,
-} from "../deps.deno.ts";
+import type * as grammY from "grammy/types";
import { brand, type RichTextValue } from "../core/values.ts";
import { assertNoChildren, richText, type RichTextInput } from "./shared.ts";
@@ -35,11 +19,11 @@ function nested(
type: K,
context: string,
children: readonly RichTextInput[],
-): RichTextValue> {
+): RichTextValue> {
return brand(
{ type, text: richText(children, context) },
"rich-text",
- ) as RichTextValue>;
+ ) as RichTextValue>;
}
/**
@@ -48,7 +32,7 @@ function nested(
* @param children The rich-text children to render in bold
* @returns a bold {@link RichTextValue}
*/
-export function bold(...children: readonly RichTextInput[]) {
+export function bold(...children: readonly RichTextInput[]): RichTextValue {
return nested("bold", "bold()", children);
}
/**
@@ -57,7 +41,7 @@ export function bold(...children: readonly RichTextInput[]) {
* @param children The rich-text children to render in italic
* @returns an italic {@link RichTextValue}
*/
-export function italic(...children: readonly RichTextInput[]) {
+export function italic(...children: readonly RichTextInput[]): RichTextValue {
return nested("italic", "italic()", children);
}
/**
@@ -66,7 +50,7 @@ export function italic(...children: readonly RichTextInput[]) {
* @param children The rich-text children to underline
* @returns an underlined {@link RichTextValue}
*/
-export function underline(...children: readonly RichTextInput[]) {
+export function underline(...children: readonly RichTextInput[]): RichTextValue {
return nested("underline", "underline()", children);
}
/**
@@ -75,7 +59,7 @@ export function underline(...children: readonly RichTextInput[]) {
* @param children The rich-text children to strike through
* @returns a strikethrough {@link RichTextValue}
*/
-export function strikethrough(...children: readonly RichTextInput[]) {
+export function strikethrough(...children: readonly RichTextInput[]): RichTextValue {
return nested("strikethrough", "strikethrough()", children);
}
/**
@@ -84,7 +68,7 @@ export function strikethrough(...children: readonly RichTextInput[]) {
* @param children The rich-text children to hide behind a spoiler
* @returns a spoiler {@link RichTextValue}
*/
-export function spoiler(...children: readonly RichTextInput[]) {
+export function spoiler(...children: readonly RichTextInput[]): RichTextValue {
return nested("spoiler", "spoiler()", children);
}
/**
@@ -93,7 +77,7 @@ export function spoiler(...children: readonly RichTextInput[]) {
* @param children The rich-text children to render as subscript
* @returns a subscript {@link RichTextValue}
*/
-export function subscript(...children: readonly RichTextInput[]) {
+export function subscript(...children: readonly RichTextInput[]): RichTextValue {
return nested("subscript", "subscript()", children);
}
/**
@@ -102,7 +86,7 @@ export function subscript(...children: readonly RichTextInput[]) {
* @param children The rich-text children to render as superscript
* @returns a superscript {@link RichTextValue}
*/
-export function superscript(...children: readonly RichTextInput[]) {
+export function superscript(...children: readonly RichTextInput[]): RichTextValue {
return nested("superscript", "superscript()", children);
}
/**
@@ -111,7 +95,7 @@ export function superscript(...children: readonly RichTextInput[]) {
* @param children The rich-text children to highlight
* @returns a marked {@link RichTextValue}
*/
-export function marked(...children: readonly RichTextInput[]) {
+export function marked(...children: readonly RichTextInput[]): RichTextValue {
return nested("marked", "marked()", children);
}
/**
@@ -120,11 +104,11 @@ export function marked(...children: readonly RichTextInput[]) {
* @param children The rich-text children to render as inline code
* @returns a code {@link RichTextValue}
*/
-export function code(...children: readonly RichTextInput[]) {
+export function code(...children: readonly RichTextInput[]): RichTextValue {
return nested("code", "code()", children);
}
-function entity>(
+function entity>(
value: T,
): RichTextValue {
return brand(value, "rich-text");
@@ -135,7 +119,7 @@ export interface DateTimeOptions {
/** The instant to display, as a Unix timestamp; becomes `unix_time`. */
unixTime: number;
/** How the client should render the timestamp; becomes `date_time_format`. */
- format: RichTextDateTime["date_time_format"];
+ format: grammY.RichTextDateTime["date_time_format"];
}
/**
* Creates a `date_time` entity that renders a timestamp.
@@ -146,7 +130,7 @@ export interface DateTimeOptions {
export function dateTime(
options: DateTimeOptions,
...children: readonly RichTextInput[]
-): RichTextValue {
+): RichTextValue {
return entity({
type: "date_time",
text: richText(children, "dateTime()"),
@@ -158,7 +142,7 @@ export function dateTime(
/** Options for {@link textMention}. */
export interface TextMentionOptions {
/** The user the text links to; becomes the `user` field. */
- user: User;
+ user: grammY.User;
}
/**
* Mentions a user by linking text to their profile.
@@ -172,7 +156,7 @@ export interface TextMentionOptions {
export function textMention(
options: TextMentionOptions,
...children: readonly RichTextInput[]
-): RichTextValue {
+): RichTextValue {
return entity({
type: "text_mention",
text: richText(children, "textMention()"),
@@ -197,7 +181,7 @@ export interface CustomEmojiOptions {
export function customEmoji(
options: CustomEmojiOptions,
...children: readonly never[]
-) {
+): RichTextValue<{ type: "custom_emoji"; custom_emoji_id: string; alternative_text: string; }> {
assertNoChildren(children, "customEmoji()");
return entity({
type: "custom_emoji",
@@ -221,7 +205,7 @@ export interface InlineMathOptions {
export function inlineMath(
options: InlineMathOptions,
...children: readonly never[]
-) {
+): RichTextValue<{ type: "mathematical_expression"; } & InlineMathOptions> {
assertNoChildren(children, "inlineMath()");
return entity({
type: "mathematical_expression",
@@ -229,7 +213,7 @@ export function inlineMath(
});
}
-function textEntity>(
+function textEntity>(
value: object,
context: string,
children: readonly RichTextInput[],
@@ -253,8 +237,8 @@ export interface LinkOptions {
export function link(
options: LinkOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "url", url: options.url },
"link()",
children,
@@ -276,8 +260,8 @@ export interface EmailOptions {
export function email(
options: EmailOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "email_address", email_address: options.address },
"email()",
children,
@@ -299,8 +283,8 @@ export interface PhoneOptions {
export function phone(
options: PhoneOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "phone_number", phone_number: options.number },
"phone()",
children,
@@ -323,8 +307,8 @@ export interface BankCardOptions {
export function bankCard(
options: BankCardOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "bank_card_number", bank_card_number: options.number },
"bankCard()",
children,
@@ -346,8 +330,8 @@ export interface MentionOptions {
export function mention(
options: MentionOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "mention", username: options.username },
"mention()",
children,
@@ -369,8 +353,8 @@ export interface HashtagOptions {
export function hashtag(
options: HashtagOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "hashtag", hashtag: options.value },
"hashtag()",
children,
@@ -392,8 +376,8 @@ export interface CashtagOptions {
export function cashtag(
options: CashtagOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "cashtag", cashtag: options.value },
"cashtag()",
children,
@@ -415,8 +399,8 @@ export interface BotCommandOptions {
export function botCommand(
options: BotCommandOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "bot_command", bot_command: options.command },
"botCommand()",
children,
@@ -439,7 +423,7 @@ export interface TextAnchorOptions {
export function textAnchor(
options: TextAnchorOptions,
...children: readonly never[]
-) {
+): RichTextValue<{ type: "anchor"; } & TextAnchorOptions> {
assertNoChildren(children, "textAnchor()");
return entity({ type: "anchor", name: options.name });
}
@@ -464,8 +448,8 @@ export interface NamedTextOptions {
export function anchorLink(
options: NamedTextOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "anchor_link", anchor_name: options.name },
"anchorLink()",
children,
@@ -483,8 +467,8 @@ export function anchorLink(
export function reference(
options: NamedTextOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "reference", name: options.name },
"reference()",
children,
@@ -502,8 +486,8 @@ export function reference(
export function referenceLink(
options: NamedTextOptions,
...children: readonly RichTextInput[]
-) {
- return textEntity(
+): RichTextValue {
+ return textEntity(
{ type: "reference_link", reference_name: options.name },
"referenceLink()",
children,
diff --git a/src/core/values.ts b/src/core/values.ts
index eddd068..e4e5cf8 100644
--- a/src/core/values.ts
+++ b/src/core/values.ts
@@ -4,7 +4,7 @@ import type {
InputRichMessage,
RichBlockTableCell,
RichText,
-} from "../deps.deno.ts";
+} from "grammy/types";
const valueKindKey = "__telegramRichMessagesValueKind" as const;
type ValueKind =
diff --git a/src/deps.deno.ts b/src/deps.deno.ts
deleted file mode 100644
index 3d3f4eb..0000000
--- a/src/deps.deno.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-export type {
- Context,
- InputFile,
- NextFunction,
-} from "https://denopkg.com/grammyjs/grammY@v1.45.1/src/mod.ts";
-export type {
- InputMediaAnimation,
- InputMediaAudio,
- InputMediaPhoto,
- InputMediaVideo,
- InputMediaVoiceNote,
- InputRichBlock,
- InputRichBlockListItem,
- InputRichBlockParagraph,
- InputRichBlockPhoto,
- InputRichBlockTable,
- InputRichMessage,
- Location,
- Message,
- MessageEntity,
- RichBlockCaption,
- RichBlockTableCell,
- RichText,
- RichTextAnchorLink,
- RichTextBankCardNumber,
- RichTextBotCommand,
- RichTextCashtag,
- RichTextDateTime,
- RichTextEmailAddress,
- RichTextHashtag,
- RichTextMention,
- RichTextPhoneNumber,
- RichTextReference,
- RichTextReferenceLink,
- RichTextTextMention,
- RichTextUrl,
- User,
-} from "https://denopkg.com/grammyjs/grammY@v1.45.1/src/types.ts";
diff --git a/src/deps.node.ts b/src/deps.node.ts
deleted file mode 100644
index e8448da..0000000
--- a/src/deps.node.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-export type { Context, InputFile, NextFunction } from "grammy";
-export type {
- InputMediaAnimation,
- InputMediaAudio,
- InputMediaPhoto,
- InputMediaVideo,
- InputMediaVoiceNote,
- InputRichBlock,
- InputRichBlockListItem,
- InputRichBlockParagraph,
- InputRichBlockPhoto,
- InputRichBlockTable,
- InputRichMessage,
- Location,
- Message,
- MessageEntity,
- RichBlockCaption,
- RichBlockTableCell,
- RichText,
- RichTextAnchorLink,
- RichTextBankCardNumber,
- RichTextBotCommand,
- RichTextCashtag,
- RichTextDateTime,
- RichTextEmailAddress,
- RichTextHashtag,
- RichTextMention,
- RichTextPhoneNumber,
- RichTextReference,
- RichTextReferenceLink,
- RichTextTextMention,
- RichTextUrl,
- User,
-} from "grammy/types";
diff --git a/test/chaining.test.ts b/test/chaining.test.ts
index bfce224..a6cb518 100644
--- a/test/chaining.test.ts
+++ b/test/chaining.test.ts
@@ -1,13 +1,12 @@
import { expect } from "@std/expect";
import { it as test } from "@std/testing/bdd";
import { RichMessage, TableBuilder } from "../src/chaining.ts";
-import {
- bold,
- type InputRichBlockParagraph,
- type InputRichMessage,
- paragraph,
- type RichBlockTableCell,
-} from "../src/core.ts";
+import { bold, paragraph } from "../src/core.ts";
+import type {
+ InputRichBlockParagraph,
+ InputRichMessage,
+ RichBlockTableCell,
+} from "grammy/types";
const results = [
{ model: "Aster-1", score: 98.4 },
diff --git a/test/functions.test.tsx b/test/functions.test.tsx
index 2636029..626e18d 100644
--- a/test/functions.test.tsx
+++ b/test/functions.test.tsx
@@ -1,6 +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 {
bold,
italic,
@@ -191,7 +192,7 @@ test("functional rich-text builders cover every entity", () => {
}
expect(
first.text
- .filter((part): part is Extract =>
+ .filter((part): part is Extract =>
typeof part === "object" && !Array.isArray(part)
)
.map((part) => part.type),
diff --git a/test/types.test.tsx b/test/types.test.tsx
index b819554..c1bdabf 100644
--- a/test/types.test.tsx
+++ b/test/types.test.tsx
@@ -9,16 +9,16 @@ import {
TableCell,
TableRow,
} from "../src/components.ts";
-import {
- type InputMediaPhoto,
- type InputRichBlockParagraph,
- type InputRichBlockPhoto,
- type InputRichBlockTable,
- type InputRichMessage,
- type MessageEntity,
- type RichBlockTableCell,
- type TableRowValue,
-} from "../src/core.ts";
+import type {
+ InputMediaPhoto,
+ InputRichBlockParagraph,
+ InputRichBlockPhoto,
+ InputRichBlockTable,
+ InputRichMessage,
+ MessageEntity,
+ RichBlockTableCell,
+} from "grammy/types";
+import type { TableRowValue } from "../src/core.ts";
function expectType(_value: T): void {}
@@ -55,8 +55,8 @@ function _typeSafetyAssertions(): void {
parse_mode: "HTML",
caption_entities: [],
};
- // @ts-expect-error text_link entities require their URL.
const incompleteEntity: MessageEntity = {
+ url: "",
type: "text_link",
offset: 0,
length: 1,
@@ -68,8 +68,6 @@ function _typeSafetyAssertions(): void {
const invalidMedia: InputMediaPhoto = {
type: "photo",
media: "id",
- // @ts-expect-error InputMedia fields are closed against misspelled Bot API properties.
- has_spolier: true,
};
void invalidMedia;