diff --git a/.gitignore b/.gitignore index 1f51356..bd0a416 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ dist node_modules tg-bot-api test.ts -tsconfig.tsbuildinfo \ No newline at end of file +tsconfig.tsbuildinfo +build.ts \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index b06c8d0..b424abd 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index b188a14..ca53c0e 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,12 @@ "devDependencies": { "@biomejs/biome": "1.7.3", "@types/bun": "^1.1.6", - "@types/node": "^20.14.9", + "@types/node": "^20.14.10", "prettier": "^3.3.2", "typescript": "^5.5.3" }, "dependencies": { - "@gramio/types": "^7.6.0" + "@gramio/types": "^7.7.0" }, "files": [ "dist" diff --git a/scripts/generate.ts b/scripts/generate.ts index 493ac6f..0673bb6 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -119,11 +119,11 @@ fs.writeFile( [Method in keyof APIMethods]?: [(params: (NonNullable>)) => boolean, Extractor[] | null]; }; - /** Guard for check is it File or Promise */ - export function isFile(file?: TelegramInputFile | object | string) { - if(!file || typeof file !== "object") return false; + /** Guard for check is it {@link Blob} or {@link Promise} */ + export function isBlob(blob?: TelegramInputFile | object | string) { + if (!blob || typeof blob !== "object") return false; - return file instanceof File || file instanceof Promise; + return blob instanceof Blob || blob instanceof Promise; } /** @@ -138,7 +138,7 @@ fs.writeFile( return `${key}: [(params) => ${value .map((x) => { if (x.type === "array") - return `params.${x.property}.some(x => "${x.name}" in x && isFile(x.${x.name}))`; + return `params.${x.property}.some(x => "${x.name}" in x && isBlob(x.${x.name}))`; return /* ts */ `${ x.type === "union" @@ -146,7 +146,7 @@ fs.writeFile( x.property ? `.${x.property}` : "" } && ` : "" - }isFile(params.${ + }isBlob(params.${ x.property ? `${x.property}.${x.name}` : `${x.name}` })`; }) diff --git a/src/index.ts b/src/index.ts index 9d303b8..8d9613f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,6 +22,6 @@ */ export * from "./utils"; -export { isFile, MEDIA_METHODS } from "./media-methods-helper"; +export { isBlob, MEDIA_METHODS } from "./media-methods-helper"; export * from "./media-input"; export * from "./media-upload"; diff --git a/src/media-methods-helper.ts b/src/media-methods-helper.ts index b4044a5..fe36c15 100644 --- a/src/media-methods-helper.ts +++ b/src/media-methods-helper.ts @@ -16,11 +16,11 @@ type MethodsWithMediaUpload = { ]; }; -/** Guard for check is it {@link File} or {@link Promise} */ -export function isFile(file?: TelegramInputFile | object | string) { - if (!file || typeof file !== "object") return false; +/** Guard for check is it {@link Blob} or {@link Promise} */ +export function isBlob(blob?: TelegramInputFile | object | string) { + if (!blob || typeof blob !== "object") return false; - return file instanceof File || file instanceof Promise; + return blob instanceof Blob || blob instanceof Promise; } /** @@ -29,31 +29,31 @@ export function isFile(file?: TelegramInputFile | object | string) { * @codegenerated * */ export const MEDIA_METHODS: MethodsWithMediaUpload = { - setWebhook: [(params) => isFile(params.certificate), null], - sendPhoto: [(params) => isFile(params.photo), null], + setWebhook: [(params) => isBlob(params.certificate), null], + sendPhoto: [(params) => isBlob(params.photo), null], sendAudio: [ - (params) => isFile(params.audio) || isFile(params.thumbnail), + (params) => isBlob(params.audio) || isBlob(params.thumbnail), null, ], sendDocument: [ - (params) => isFile(params.document) || isFile(params.thumbnail), + (params) => isBlob(params.document) || isBlob(params.thumbnail), null, ], sendVideo: [ - (params) => isFile(params.video) || isFile(params.thumbnail), + (params) => isBlob(params.video) || isBlob(params.thumbnail), null, ], sendAnimation: [ - (params) => isFile(params.animation) || isFile(params.thumbnail), + (params) => isBlob(params.animation) || isBlob(params.thumbnail), null, ], - sendVoice: [(params) => isFile(params.voice), null], + sendVoice: [(params) => isBlob(params.voice), null], sendVideoNote: [ - (params) => isFile(params.video_note) || isFile(params.thumbnail), + (params) => isBlob(params.video_note) || isBlob(params.thumbnail), null, ], sendPaidMedia: [ - (params) => params.media.some((x) => "media" in x && isFile(x.media)), + (params) => params.media.some((x) => "media" in x && isBlob(x.media)), [ { name: "media", @@ -64,8 +64,8 @@ export const MEDIA_METHODS: MethodsWithMediaUpload = { ], sendMediaGroup: [ (params) => - params.media.some((x) => "media" in x && isFile(x.media)) || - params.media.some((x) => "thumbnail" in x && isFile(x.thumbnail)), + params.media.some((x) => "media" in x && isBlob(x.media)) || + params.media.some((x) => "thumbnail" in x && isBlob(x.thumbnail)), [ { name: "media", @@ -79,11 +79,11 @@ export const MEDIA_METHODS: MethodsWithMediaUpload = { }, ], ], - setChatPhoto: [(params) => isFile(params.photo), null], + setChatPhoto: [(params) => isBlob(params.photo), null], editMessageMedia: [ (params) => - ("media" in params.media && isFile(params.media.media)) || - ("thumbnail" in params.media && isFile(params.media.thumbnail)), + ("media" in params.media && isBlob(params.media.media)) || + ("thumbnail" in params.media && isBlob(params.media.thumbnail)), [ { name: "media", @@ -97,11 +97,11 @@ export const MEDIA_METHODS: MethodsWithMediaUpload = { }, ], ], - sendSticker: [(params) => isFile(params.sticker), null], - uploadStickerFile: [(params) => isFile(params.sticker), null], + sendSticker: [(params) => isBlob(params.sticker), null], + uploadStickerFile: [(params) => isBlob(params.sticker), null], createNewStickerSet: [ (params) => - params.stickers.some((x) => "sticker" in x && isFile(x.sticker)), + params.stickers.some((x) => "sticker" in x && isBlob(x.sticker)), [ { name: "sticker", @@ -110,7 +110,7 @@ export const MEDIA_METHODS: MethodsWithMediaUpload = { }, ], ], - addStickerToSet: [(params) => isFile(params.sticker.sticker), null], - replaceStickerInSet: [(params) => isFile(params.sticker.sticker), null], - setStickerSetThumbnail: [(params) => isFile(params.thumbnail), null], + addStickerToSet: [(params) => isBlob(params.sticker.sticker), null], + replaceStickerInSet: [(params) => isBlob(params.sticker.sticker), null], + setStickerSetThumbnail: [(params) => isBlob(params.thumbnail), null], };