feat(decorators): metadata typings added

This commit is contained in:
Aleksandr Bukhalo
2020-03-19 18:20:07 +03:00
parent dd59da7737
commit 25710b7908
13 changed files with 162 additions and 34 deletions

View File

@@ -2,12 +2,20 @@ import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';
import { HearsTriggers } from 'telegraf';
export type TelegrafActionTriggers = HearsTriggers;
export interface TelegrafActionMetadata {
triggers: TelegrafActionTriggers;
}
/**
* Registers middleware for handling callback_data actions with regular expressions.
* @param triggers Triggers
*
* https://telegraf.js.org/#/?id=action
*/
export function TelegrafAction(triggers: HearsTriggers): MethodDecorator {
export function TelegrafAction(
triggers: TelegrafActionTriggers,
): MethodDecorator {
return SetMetadata(DECORATORS.ACTION, { triggers });
}

View File

@@ -1,12 +1,20 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';
export type TelegrafCashtagCashtag = string | string[];
export interface TelegrafCashtagMetadata {
cashtag: TelegrafCashtagCashtag;
}
/**
* Cashtag handling.
* @param cashtag Cashtag
*
* https://telegraf.js.org/#/?id=cashtag
*/
export function TelegrafCashtag(cashtag: string | string[]): MethodDecorator {
export function TelegrafCashtag(
cashtag: TelegrafCashtagCashtag,
): MethodDecorator {
return SetMetadata(DECORATORS.CASHTAG, { cashtag });
}

View File

@@ -1,12 +1,20 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';
export type TelegrafCommandCommands = string | string[];
export interface TelegrafCommandMetadata {
commands: TelegrafCommandCommands;
}
/**
* Command handling.
* @param commands Commands
*
* https://telegraf.js.org/#/?id=command
*/
export function TelegrafCommand(commands: string | string[]): MethodDecorator {
export function TelegrafCommand(
commands: TelegrafCommandCommands,
): MethodDecorator {
return SetMetadata(DECORATORS.COMMAND, { commands });
}

View File

@@ -1,7 +1,16 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';
export type Entity = string | string[] | RegExp | RegExp[] | Function;
export type TelegrafEntityEntity =
| string
| string[]
| RegExp
| RegExp[]
| Function;
export interface TelegrafEntityMetadata {
entity: TelegrafEntityEntity;
}
/**
* Entity handling.
@@ -9,6 +18,6 @@ export type Entity = string | string[] | RegExp | RegExp[] | Function;
*
* https://telegraf.js.org/#/?id=entity
*/
export function TelegrafEntity(entity: Entity): MethodDecorator {
export function TelegrafEntity(entity: TelegrafEntityEntity): MethodDecorator {
return SetMetadata(DECORATORS.ENTITY, { entity });
}

View File

@@ -1,12 +1,20 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';
export type TelegrafHashtagHashtag = string | string[];
export interface TelegrafHashtagMetadata {
hashtag: TelegrafHashtagHashtag;
}
/**
* Hashtag handling.
* @param hashtag Hashtag
*
* https://telegraf.js.org/#/?id=hashtag
*/
export function TelegrafHashtag(hashtag: string | string[]): MethodDecorator {
export function TelegrafHashtag(
hashtag: TelegrafHashtagHashtag,
): MethodDecorator {
return SetMetadata(DECORATORS.HASHTAG, { hashtag });
}

View File

@@ -2,12 +2,20 @@ import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';
import { HearsTriggers } from 'telegraf';
export type TelegrafHearsTriggers = HearsTriggers;
export interface TelegrafHearsMetadata {
triggers: TelegrafHearsTriggers;
}
/**
* Registers middleware for handling text messages.
* @param triggers Triggers
*
* https://telegraf.js.org/#/?id=hears
*/
export function TelegrafHears(triggers: HearsTriggers): MethodDecorator {
export function TelegrafHears(
triggers: TelegrafHearsTriggers,
): MethodDecorator {
return SetMetadata(DECORATORS.HEARS, { triggers: triggers });
}

View File

@@ -1,7 +1,11 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';
export type Triggers = string | string[] | RegExp | RegExp[];
export type TelegrafInlineQueryTriggers = string | string[] | RegExp | RegExp[];
export interface TelegrafInlineQueryMetadata {
triggers: TelegrafInlineQueryTriggers;
}
/**
* Registers middleware for handling inline_query actions with regular expressions.
@@ -9,6 +13,8 @@ export type Triggers = string | string[] | RegExp | RegExp[];
*
* https://telegraf.js.org/#/?id=inlinequery
*/
export function TelegrafInlineQuery(triggers: Triggers): MethodDecorator {
export function TelegrafInlineQuery(
triggers: TelegrafInlineQueryTriggers,
): MethodDecorator {
return SetMetadata(DECORATORS.INLINE_QUERY, { triggers });
}

View File

@@ -1,12 +1,20 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';
export type TelegrafMentionUsername = string | string[];
export interface TelegrafMentionMetadata {
username: TelegrafMentionUsername;
}
/**
* Mention handling.
* @param username Username
*
* https://telegraf.js.org/#/?id=mention
*/
export function TelegrafMention(username: string | string[]): MethodDecorator {
export function TelegrafMention(
username: TelegrafMentionUsername,
): MethodDecorator {
return SetMetadata(DECORATORS.MENTION, { username });
}

View File

@@ -2,6 +2,16 @@ import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';
import { UpdateType, MessageSubTypes } from 'telegraf/typings/telegram-types';
export type TelegrafOnUpdateTypes =
| UpdateType
| UpdateType[]
| MessageSubTypes
| MessageSubTypes[];
export interface TelegrafOnMetadata {
updateTypes: TelegrafOnUpdateTypes;
}
/**
* Registers middleware for provided update type.
* @param updateTypes Update type
@@ -9,7 +19,7 @@ import { UpdateType, MessageSubTypes } from 'telegraf/typings/telegram-types';
* https://telegraf.js.org/#/?id=on
*/
export function TelegrafOn(
updateTypes: UpdateType | UpdateType[] | MessageSubTypes | MessageSubTypes[],
updateTypes: TelegrafOnUpdateTypes,
): MethodDecorator {
return SetMetadata(DECORATORS.ON, { updateTypes: updateTypes });
}

View File

@@ -1,12 +1,18 @@
import { SetMetadata } from '@nestjs/common';
import { DECORATORS } from '../telegraf.constants';
export type TelegrafPhonePhone = string | string[];
export interface TelegrafPhoneMetadata {
phone: TelegrafPhonePhone;
}
/**
* Phone number handling.
* @param phone Phone number
*
* https://telegraf.js.org/#/?id=phone
*/
export function TelegrafPhone(phone: string | string[]): MethodDecorator {
export function TelegrafPhone(phone: TelegrafPhonePhone): MethodDecorator {
return SetMetadata(DECORATORS.PHONE, { phone });
}