feat(): mvp

This commit is contained in:
unknown 2020-12-26 16:11:09 +03:00
parent 80853be80c
commit d02a52a7ae
29 changed files with 99 additions and 107 deletions

View File

@ -1,6 +1,5 @@
# source # source
lib lib
index.ts
package-lock.json package-lock.json
tsconfig.json tsconfig.json
.prettierrc .prettierrc

1
index.d.ts vendored
View File

@ -1 +0,0 @@
export * from './dist';

View File

@ -1,6 +0,0 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
exports.__esModule = true;
__export(require("./dist"));

View File

@ -1 +0,0 @@
export * from './dist';

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafUpdateType } from '../../telegraf.types'; import { TelegrafUpdateType } from '../../telegraf.types';
@ -17,8 +17,8 @@ export interface OnOptions {
*/ */
export const On = (updateTypes: TelegrafUpdateType): MethodDecorator => { export const On = (updateTypes: TelegrafUpdateType): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.On), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.On),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
updateTypes, updateTypes,
} as OnOptions), } as OnOptions),
); );

View File

@ -1,9 +1,8 @@
import { SetMetadata } from '@nestjs/common'; import { SetMetadata } from '@nestjs/common';
import { TELEGRAF_UPDATE_METADATA } from '../../telegraf.constants'; import { UPDATE_METADATA } from '../../telegraf.constants';
/** /**
* `@Update` decorator, it's like NestJS `@Controller` decorator, * `@Update` decorator, it's like NestJS `@Controller` decorator,
* but for Telegram Bot API updates. * but for Telegram Bot API updates.
*/ */
export const Update = (): ClassDecorator => export const Update = (): ClassDecorator => SetMetadata(UPDATE_METADATA, true);
SetMetadata(TELEGRAF_UPDATE_METADATA, true);

View File

@ -1,5 +1,5 @@
import { SetMetadata } from '@nestjs/common'; import { SetMetadata } from '@nestjs/common';
import { LISTENER_TYPE_METADATA } from '../../telegraf.constants'; import { UPDATE_LISTENER_TYPE_METADATA } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
/** /**
@ -8,5 +8,5 @@ import { ListenerType } from '../../enums/listener-type.enum';
* @see https://telegraf.js.org/#/?id=use * @see https://telegraf.js.org/#/?id=use
*/ */
export const Use = (): MethodDecorator => { export const Use = (): MethodDecorator => {
return SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Use); return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Use);
}; };

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { TelegrafActionTriggers } from '../../telegraf.types'; import { TelegrafActionTriggers } from '../../telegraf.types';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
@ -17,8 +17,8 @@ export interface ActionOptions {
*/ */
export const Action = (triggers: TelegrafActionTriggers): MethodDecorator => { export const Action = (triggers: TelegrafActionTriggers): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Action), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Action),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
triggers, triggers,
} as ActionOptions), } as ActionOptions),
); );

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { TelegrafCashtag } from '../../telegraf.types'; import { TelegrafCashtag } from '../../telegraf.types';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
@ -17,8 +17,8 @@ export interface CashtagOptions {
*/ */
export const Cashtag = (cashtag: TelegrafCashtag): MethodDecorator => { export const Cashtag = (cashtag: TelegrafCashtag): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Cashtag), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Cashtag),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
cashtag, cashtag,
} as CashtagOptions), } as CashtagOptions),
); );

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafCommand } from '../../telegraf.types'; import { TelegrafCommand } from '../../telegraf.types';
@ -17,8 +17,8 @@ export interface CommandOptions {
*/ */
export const Command = (command: TelegrafCommand): MethodDecorator => { export const Command = (command: TelegrafCommand): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Command), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Command),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
command: command, command: command,
} as CommandOptions), } as CommandOptions),
); );

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafEmail } from '../../telegraf.types'; import { TelegrafEmail } from '../../telegraf.types';
@ -17,8 +17,8 @@ export interface EmailOptions {
*/ */
export const Email = (email: TelegrafEmail): MethodDecorator => { export const Email = (email: TelegrafEmail): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Email), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Email),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
email, email,
} as EmailOptions), } as EmailOptions),
); );

View File

@ -1,5 +1,5 @@
import { SetMetadata } from '@nestjs/common'; import { SetMetadata } from '@nestjs/common';
import { LISTENER_TYPE_METADATA } from '../../telegraf.constants'; import { UPDATE_LISTENER_TYPE_METADATA } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
/** /**
@ -8,5 +8,5 @@ import { ListenerType } from '../../enums/listener-type.enum';
* @see https://telegraf.js.org/#/?id=inlinequery * @see https://telegraf.js.org/#/?id=inlinequery
*/ */
export const GameQuery = (): MethodDecorator => { export const GameQuery = (): MethodDecorator => {
return SetMetadata(LISTENER_TYPE_METADATA, ListenerType.GameQuery); return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.GameQuery);
}; };

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafHashtag } from '../../telegraf.types'; import { TelegrafHashtag } from '../../telegraf.types';
@ -17,8 +17,8 @@ export interface HashtagOptions {
*/ */
export const Hashtag = (hashtag: TelegrafHashtag): MethodDecorator => { export const Hashtag = (hashtag: TelegrafHashtag): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Hashtag), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Hashtag),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
hashtag, hashtag,
} as HashtagOptions), } as HashtagOptions),
); );

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafHearsTriggers } from '../../telegraf.types'; import { TelegrafHearsTriggers } from '../../telegraf.types';
@ -17,8 +17,8 @@ export interface HearsOptions {
*/ */
export const Hears = (triggers: TelegrafHearsTriggers): MethodDecorator => { export const Hears = (triggers: TelegrafHearsTriggers): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Hears), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Hears),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
triggers, triggers,
} as HearsOptions), } as HearsOptions),
); );

View File

@ -1,5 +1,5 @@
import { SetMetadata } from '@nestjs/common'; import { SetMetadata } from '@nestjs/common';
import { LISTENER_TYPE_METADATA } from '../../telegraf.constants'; import { UPDATE_LISTENER_TYPE_METADATA } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
/** /**
@ -8,5 +8,5 @@ import { ListenerType } from '../../enums/listener-type.enum';
* @see https://telegraf.js.org/#/?id=help * @see https://telegraf.js.org/#/?id=help
*/ */
export const Help = (): MethodDecorator => { export const Help = (): MethodDecorator => {
return SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Help); return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Help);
}; };

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafInlineQueryTriggers } from '../../telegraf.types'; import { TelegrafInlineQueryTriggers } from '../../telegraf.types';
@ -19,8 +19,8 @@ export const InlineQuery = (
triggers: TelegrafInlineQueryTriggers, triggers: TelegrafInlineQueryTriggers,
): MethodDecorator => { ): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.InlineQuery), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.InlineQuery),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
triggers, triggers,
} as InlineQueryOptions), } as InlineQueryOptions),
); );

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafMention } from '../../telegraf.types'; import { TelegrafMention } from '../../telegraf.types';
@ -17,8 +17,8 @@ export interface MentionOptions {
*/ */
export const Mention = (mention: TelegrafMention): MethodDecorator => { export const Mention = (mention: TelegrafMention): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Mention), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Mention),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
mention, mention,
} as MentionOptions), } as MentionOptions),
); );

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafPhone } from '../../telegraf.types'; import { TelegrafPhone } from '../../telegraf.types';
@ -17,8 +17,8 @@ export interface PhoneOptions {
*/ */
export const Phone = (phone: TelegrafPhone): MethodDecorator => { export const Phone = (phone: TelegrafPhone): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Phone), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Phone),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
phone, phone,
} as PhoneOptions), } as PhoneOptions),
); );

View File

@ -1,5 +1,5 @@
import { SetMetadata } from '@nestjs/common'; import { SetMetadata } from '@nestjs/common';
import { LISTENER_TYPE_METADATA } from '../../telegraf.constants'; import { UPDATE_LISTENER_TYPE_METADATA } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
/** /**
@ -8,5 +8,5 @@ import { ListenerType } from '../../enums/listener-type.enum';
* @see https://telegraf.js.org/#/?id=settings * @see https://telegraf.js.org/#/?id=settings
*/ */
export const Settings = (): MethodDecorator => { export const Settings = (): MethodDecorator => {
return SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Settings); return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Settings);
}; };

View File

@ -1,5 +1,5 @@
import { SetMetadata } from '@nestjs/common'; import { SetMetadata } from '@nestjs/common';
import { LISTENER_TYPE_METADATA } from '../../telegraf.constants'; import { UPDATE_LISTENER_TYPE_METADATA } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
/** /**
@ -8,5 +8,5 @@ import { ListenerType } from '../../enums/listener-type.enum';
* @see https://telegraf.js.org/#/?id=start * @see https://telegraf.js.org/#/?id=start
*/ */
export const Start = (): MethodDecorator => { export const Start = (): MethodDecorator => {
return SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Start); return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Start);
}; };

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafTextLink } from '../../telegraf.types'; import { TelegrafTextLink } from '../../telegraf.types';
@ -17,8 +17,8 @@ export interface TextLinkOptions {
*/ */
export const TetxLink = (link: TelegrafTextLink): MethodDecorator => { export const TetxLink = (link: TelegrafTextLink): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.TextLink), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.TextLink),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
link, link,
} as TextLinkOptions), } as TextLinkOptions),
); );

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafTextMention } from '../../telegraf.types'; import { TelegrafTextMention } from '../../telegraf.types';
@ -17,8 +17,8 @@ export interface TextMentionOptions {
*/ */
export const TetxMention = (mention: TelegrafTextMention): MethodDecorator => { export const TetxMention = (mention: TelegrafTextMention): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.TextMention), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.TextMention),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
mention, mention,
} as TextMentionOptions), } as TextMentionOptions),
); );

View File

@ -1,7 +1,7 @@
import { applyDecorators, SetMetadata } from '@nestjs/common'; import { applyDecorators, SetMetadata } from '@nestjs/common';
import { import {
LISTENER_OPTIONS_METADATA, UPDATE_LISTENER_OPTIONS_METADATA,
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
} from '../../telegraf.constants'; } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum'; import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafUrl } from '../../telegraf.types'; import { TelegrafUrl } from '../../telegraf.types';
@ -17,8 +17,8 @@ export interface UrlOptions {
*/ */
export const Url = (url: TelegrafUrl): MethodDecorator => { export const Url = (url: TelegrafUrl): MethodDecorator => {
return applyDecorators( return applyDecorators(
SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Url), SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Url),
SetMetadata(LISTENER_OPTIONS_METADATA, { SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
url, url,
} as UrlOptions), } as UrlOptions),
); );

View File

@ -1,5 +1,6 @@
export const TELEGRAF_MODULE_OPTIONS = 'TELEGRAF_MODULE_OPTIONS'; export const TELEGRAF_MODULE_OPTIONS = 'TELEGRAF_MODULE_OPTIONS';
export const TELEGRAF_UPDATE_METADATA = 'TELEGRAF_UPDATE_METADATA'; export const UPDATE_METADATA = 'UPDATE_METADATA';
export const LISTENER_TYPE_METADATA = 'LISTENER_TYPE_METADATA'; export const UPDATE_LISTENER_TYPE_METADATA = 'UPDATE_LISTENER_TYPE_METADATA';
export const LISTENER_OPTIONS_METADATA = 'LISTENER_OPTIONS_METADATA'; export const UPDATE_LISTENER_OPTIONS_METADATA =
'UPDATE_LISTENER_OPTIONS_METADATA';

View File

@ -1,7 +1,7 @@
import { Injectable, OnModuleInit } from '@nestjs/common'; import { Injectable, OnModuleInit } from '@nestjs/common';
import { DiscoveryService, ModuleRef } from '@nestjs/core'; import { DiscoveryService, ModuleRef } from '@nestjs/core';
import { MetadataScanner } from '@nestjs/core/metadata-scanner'; import { MetadataScanner } from '@nestjs/core/metadata-scanner';
import { TelegrafMetadataAccessor } from './telegraf-metadata.accessor'; import { TelegrafMetadataAccessor } from './telegraf.metadata-accessor';
import { TelegrafProvider } from './telegraf.provider'; import { TelegrafProvider } from './telegraf.provider';
import { ListenerType } from './enums'; import { ListenerType } from './enums';
import { import {
@ -19,6 +19,7 @@ import {
TextMentionOptions, TextMentionOptions,
UrlOptions, UrlOptions,
} from './decorators'; } from './decorators';
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
@Injectable() @Injectable()
export class TelegrafExplorer implements OnModuleInit { export class TelegrafExplorer implements OnModuleInit {
@ -39,29 +40,29 @@ export class TelegrafExplorer implements OnModuleInit {
} }
explore(): void { explore(): void {
this.discoveryService const updateInstanceWrappers = this.filterUpdateClass();
updateInstanceWrappers.forEach((wrapper) => {
const { instance } = wrapper;
const prototype = Object.getPrototypeOf(instance);
this.metadataScanner.scanFromPrototype(
instance,
prototype,
(methodKey: string) =>
this.registerIfUpdateListener(instance, methodKey),
);
});
}
private filterUpdateClass(): InstanceWrapper[] {
return this.discoveryService
.getProviders() .getProviders()
.filter((wrapper) => wrapper.instance) .filter((wrapper) => wrapper.instance)
.forEach((wrapper) => { .filter((wrapper) => this.metadataAccessor.isUpdate(wrapper.instance));
const { instance } = wrapper;
const prototype = Object.getPrototypeOf(instance);
this.metadataScanner.scanFromPrototype(
instance,
prototype,
(methodKey: string) => this.registerIfUpdate(instance, methodKey),
);
});
} }
private registerIfUpdate( private registerIfUpdateListener(
instance: Record<string, Function>,
methodKey: string,
): void {
const isUpdate = this.metadataAccessor.isUpdate(instance);
}
private registerIfListener(
instance: Record<string, Function>, instance: Record<string, Function>,
methodKey: string, methodKey: string,
): void { ): void {

View File

@ -1,9 +1,9 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core'; import { Reflector } from '@nestjs/core';
import { import {
LISTENER_TYPE_METADATA, UPDATE_LISTENER_TYPE_METADATA,
TELEGRAF_MODULE_OPTIONS, TELEGRAF_MODULE_OPTIONS,
TELEGRAF_UPDATE_METADATA, UPDATE_METADATA,
} from './telegraf.constants'; } from './telegraf.constants';
import { ListenerType } from './enums'; import { ListenerType } from './enums';
@ -12,14 +12,14 @@ export class TelegrafMetadataAccessor {
constructor(private readonly reflector: Reflector) {} constructor(private readonly reflector: Reflector) {}
isUpdate(target: Function): boolean { isUpdate(target: Function): boolean {
return !!this.reflector.get<true | undefined>( return !!this.reflector.get<true | undefined>(UPDATE_METADATA, target);
TELEGRAF_UPDATE_METADATA,
target,
);
} }
getListenerType(target: Function): ListenerType | undefined { getListenerType(target: Function): ListenerType | undefined {
return this.reflector.get<ListenerType>(LISTENER_TYPE_METADATA, target); return this.reflector.get<ListenerType>(
UPDATE_LISTENER_TYPE_METADATA,
target,
);
} }
getListenerOptions<T>(target: Function): unknown | undefined { getListenerOptions<T>(target: Function): unknown | undefined {

View File

@ -6,7 +6,7 @@ import {
TelegrafOptionsFactory, TelegrafOptionsFactory,
} from './interfaces'; } from './interfaces';
import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants'; import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants';
import { TelegrafMetadataAccessor } from './telegraf-metadata.accessor'; import { TelegrafMetadataAccessor } from './telegraf.metadata-accessor';
import { TelegrafExplorer } from './telegraf.explorer'; import { TelegrafExplorer } from './telegraf.explorer';
import { TelegrafProvider } from './telegraf.provider'; import { TelegrafProvider } from './telegraf.provider';

View File

@ -1,6 +1,6 @@
{ {
"name": "nestjs-telegraf", "name": "nestjs-telegraf",
"version": "2.0.0-alpha.1", "version": "2.0.0",
"description": "Telegraf module for NestJS", "description": "Telegraf module for NestJS",
"keywords": [ "keywords": [
"nest", "nest",

View File

@ -13,6 +13,6 @@
"rootDir": "./lib", "rootDir": "./lib",
"skipLibCheck": true "skipLibCheck": true
}, },
"include": ["lib/**/*", "../index.ts"], "include": ["lib/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"] "exclude": ["node_modules", "**/*.spec.ts"]
} }