diff --git a/.npmignore b/.npmignore index 130fdb1..267876c 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,5 @@ # source lib -index.ts package-lock.json tsconfig.json .prettierrc diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 5703fb5..0000000 --- a/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './dist'; diff --git a/index.js b/index.js deleted file mode 100644 index a82ea05..0000000 --- a/index.js +++ /dev/null @@ -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")); \ No newline at end of file diff --git a/index.ts b/index.ts deleted file mode 100644 index 5703fb5..0000000 --- a/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './dist'; diff --git a/lib/decorators/core/on.decorator.ts b/lib/decorators/core/on.decorator.ts index 3bef944..17b052b 100644 --- a/lib/decorators/core/on.decorator.ts +++ b/lib/decorators/core/on.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafUpdateType } from '../../telegraf.types'; @@ -17,8 +17,8 @@ export interface OnOptions { */ export const On = (updateTypes: TelegrafUpdateType): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.On), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.On), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { updateTypes, } as OnOptions), ); diff --git a/lib/decorators/core/update.decorator.ts b/lib/decorators/core/update.decorator.ts index fde0d76..2002fec 100644 --- a/lib/decorators/core/update.decorator.ts +++ b/lib/decorators/core/update.decorator.ts @@ -1,9 +1,8 @@ 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, * but for Telegram Bot API updates. */ -export const Update = (): ClassDecorator => - SetMetadata(TELEGRAF_UPDATE_METADATA, true); +export const Update = (): ClassDecorator => SetMetadata(UPDATE_METADATA, true); diff --git a/lib/decorators/core/use.decorator.ts b/lib/decorators/core/use.decorator.ts index 72fc62e..8b393e6 100644 --- a/lib/decorators/core/use.decorator.ts +++ b/lib/decorators/core/use.decorator.ts @@ -1,5 +1,5 @@ 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'; /** @@ -8,5 +8,5 @@ import { ListenerType } from '../../enums/listener-type.enum'; * @see https://telegraf.js.org/#/?id=use */ export const Use = (): MethodDecorator => { - return SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Use); + return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Use); }; diff --git a/lib/decorators/listeners/action.decorator.ts b/lib/decorators/listeners/action.decorator.ts index 502b1b0..1a8a5a1 100644 --- a/lib/decorators/listeners/action.decorator.ts +++ b/lib/decorators/listeners/action.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { TelegrafActionTriggers } from '../../telegraf.types'; import { ListenerType } from '../../enums/listener-type.enum'; @@ -17,8 +17,8 @@ export interface ActionOptions { */ export const Action = (triggers: TelegrafActionTriggers): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Action), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Action), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { triggers, } as ActionOptions), ); diff --git a/lib/decorators/listeners/cashtag.decorator.ts b/lib/decorators/listeners/cashtag.decorator.ts index d9784cf..8b4f859 100644 --- a/lib/decorators/listeners/cashtag.decorator.ts +++ b/lib/decorators/listeners/cashtag.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { TelegrafCashtag } from '../../telegraf.types'; import { ListenerType } from '../../enums/listener-type.enum'; @@ -17,8 +17,8 @@ export interface CashtagOptions { */ export const Cashtag = (cashtag: TelegrafCashtag): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Cashtag), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Cashtag), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { cashtag, } as CashtagOptions), ); diff --git a/lib/decorators/listeners/command.decorator.ts b/lib/decorators/listeners/command.decorator.ts index eb4b01e..15d4d36 100644 --- a/lib/decorators/listeners/command.decorator.ts +++ b/lib/decorators/listeners/command.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafCommand } from '../../telegraf.types'; @@ -17,8 +17,8 @@ export interface CommandOptions { */ export const Command = (command: TelegrafCommand): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Command), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Command), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { command: command, } as CommandOptions), ); diff --git a/lib/decorators/listeners/email.decorator.ts b/lib/decorators/listeners/email.decorator.ts index 9f890fe..23aad1b 100644 --- a/lib/decorators/listeners/email.decorator.ts +++ b/lib/decorators/listeners/email.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafEmail } from '../../telegraf.types'; @@ -17,8 +17,8 @@ export interface EmailOptions { */ export const Email = (email: TelegrafEmail): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Email), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Email), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { email, } as EmailOptions), ); diff --git a/lib/decorators/listeners/game-query.decorator.ts b/lib/decorators/listeners/game-query.decorator.ts index 25e0410..898b1d5 100644 --- a/lib/decorators/listeners/game-query.decorator.ts +++ b/lib/decorators/listeners/game-query.decorator.ts @@ -1,5 +1,5 @@ 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'; /** @@ -8,5 +8,5 @@ import { ListenerType } from '../../enums/listener-type.enum'; * @see https://telegraf.js.org/#/?id=inlinequery */ export const GameQuery = (): MethodDecorator => { - return SetMetadata(LISTENER_TYPE_METADATA, ListenerType.GameQuery); + return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.GameQuery); }; diff --git a/lib/decorators/listeners/hashtag.decorator.ts b/lib/decorators/listeners/hashtag.decorator.ts index 4c86618..4d344c6 100644 --- a/lib/decorators/listeners/hashtag.decorator.ts +++ b/lib/decorators/listeners/hashtag.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafHashtag } from '../../telegraf.types'; @@ -17,8 +17,8 @@ export interface HashtagOptions { */ export const Hashtag = (hashtag: TelegrafHashtag): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Hashtag), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Hashtag), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { hashtag, } as HashtagOptions), ); diff --git a/lib/decorators/listeners/hears.decorator.ts b/lib/decorators/listeners/hears.decorator.ts index cef3453..1f2f93e 100644 --- a/lib/decorators/listeners/hears.decorator.ts +++ b/lib/decorators/listeners/hears.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafHearsTriggers } from '../../telegraf.types'; @@ -17,8 +17,8 @@ export interface HearsOptions { */ export const Hears = (triggers: TelegrafHearsTriggers): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Hears), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Hears), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { triggers, } as HearsOptions), ); diff --git a/lib/decorators/listeners/help.decorator.ts b/lib/decorators/listeners/help.decorator.ts index 2fec408..9909f1d 100644 --- a/lib/decorators/listeners/help.decorator.ts +++ b/lib/decorators/listeners/help.decorator.ts @@ -1,5 +1,5 @@ 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'; /** @@ -8,5 +8,5 @@ import { ListenerType } from '../../enums/listener-type.enum'; * @see https://telegraf.js.org/#/?id=help */ export const Help = (): MethodDecorator => { - return SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Help); + return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Help); }; diff --git a/lib/decorators/listeners/inline-query.decorator.ts b/lib/decorators/listeners/inline-query.decorator.ts index 70da417..f9a4efd 100644 --- a/lib/decorators/listeners/inline-query.decorator.ts +++ b/lib/decorators/listeners/inline-query.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafInlineQueryTriggers } from '../../telegraf.types'; @@ -19,8 +19,8 @@ export const InlineQuery = ( triggers: TelegrafInlineQueryTriggers, ): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.InlineQuery), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.InlineQuery), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { triggers, } as InlineQueryOptions), ); diff --git a/lib/decorators/listeners/mention.decorator.ts b/lib/decorators/listeners/mention.decorator.ts index a703a23..db25ff8 100644 --- a/lib/decorators/listeners/mention.decorator.ts +++ b/lib/decorators/listeners/mention.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafMention } from '../../telegraf.types'; @@ -17,8 +17,8 @@ export interface MentionOptions { */ export const Mention = (mention: TelegrafMention): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Mention), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Mention), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { mention, } as MentionOptions), ); diff --git a/lib/decorators/listeners/phone.decorator.ts b/lib/decorators/listeners/phone.decorator.ts index b0b794b..f327762 100644 --- a/lib/decorators/listeners/phone.decorator.ts +++ b/lib/decorators/listeners/phone.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafPhone } from '../../telegraf.types'; @@ -17,8 +17,8 @@ export interface PhoneOptions { */ export const Phone = (phone: TelegrafPhone): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Phone), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Phone), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { phone, } as PhoneOptions), ); diff --git a/lib/decorators/listeners/settings.decorator.ts b/lib/decorators/listeners/settings.decorator.ts index 6bbb86b..8c25331 100644 --- a/lib/decorators/listeners/settings.decorator.ts +++ b/lib/decorators/listeners/settings.decorator.ts @@ -1,5 +1,5 @@ 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'; /** @@ -8,5 +8,5 @@ import { ListenerType } from '../../enums/listener-type.enum'; * @see https://telegraf.js.org/#/?id=settings */ export const Settings = (): MethodDecorator => { - return SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Settings); + return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Settings); }; diff --git a/lib/decorators/listeners/start.decorator.ts b/lib/decorators/listeners/start.decorator.ts index b6d3025..6de6e55 100644 --- a/lib/decorators/listeners/start.decorator.ts +++ b/lib/decorators/listeners/start.decorator.ts @@ -1,5 +1,5 @@ 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'; /** @@ -8,5 +8,5 @@ import { ListenerType } from '../../enums/listener-type.enum'; * @see https://telegraf.js.org/#/?id=start */ export const Start = (): MethodDecorator => { - return SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Start); + return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Start); }; diff --git a/lib/decorators/listeners/text-link.decorator.ts b/lib/decorators/listeners/text-link.decorator.ts index 7dedd6f..cfefc96 100644 --- a/lib/decorators/listeners/text-link.decorator.ts +++ b/lib/decorators/listeners/text-link.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafTextLink } from '../../telegraf.types'; @@ -17,8 +17,8 @@ export interface TextLinkOptions { */ export const TetxLink = (link: TelegrafTextLink): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.TextLink), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.TextLink), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { link, } as TextLinkOptions), ); diff --git a/lib/decorators/listeners/text-mention.decorator.ts b/lib/decorators/listeners/text-mention.decorator.ts index b098c4e..fc8cecc 100644 --- a/lib/decorators/listeners/text-mention.decorator.ts +++ b/lib/decorators/listeners/text-mention.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafTextMention } from '../../telegraf.types'; @@ -17,8 +17,8 @@ export interface TextMentionOptions { */ export const TetxMention = (mention: TelegrafTextMention): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.TextMention), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.TextMention), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { mention, } as TextMentionOptions), ); diff --git a/lib/decorators/listeners/url.decorator.ts b/lib/decorators/listeners/url.decorator.ts index e38167e..b104dd2 100644 --- a/lib/decorators/listeners/url.decorator.ts +++ b/lib/decorators/listeners/url.decorator.ts @@ -1,7 +1,7 @@ import { applyDecorators, SetMetadata } from '@nestjs/common'; import { - LISTENER_OPTIONS_METADATA, - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_OPTIONS_METADATA, + UPDATE_LISTENER_TYPE_METADATA, } from '../../telegraf.constants'; import { ListenerType } from '../../enums/listener-type.enum'; import { TelegrafUrl } from '../../telegraf.types'; @@ -17,8 +17,8 @@ export interface UrlOptions { */ export const Url = (url: TelegrafUrl): MethodDecorator => { return applyDecorators( - SetMetadata(LISTENER_TYPE_METADATA, ListenerType.Url), - SetMetadata(LISTENER_OPTIONS_METADATA, { + SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Url), + SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, { url, } as UrlOptions), ); diff --git a/lib/telegraf.constants.ts b/lib/telegraf.constants.ts index 16fa981..6bba348 100644 --- a/lib/telegraf.constants.ts +++ b/lib/telegraf.constants.ts @@ -1,5 +1,6 @@ export const TELEGRAF_MODULE_OPTIONS = 'TELEGRAF_MODULE_OPTIONS'; -export const TELEGRAF_UPDATE_METADATA = 'TELEGRAF_UPDATE_METADATA'; -export const LISTENER_TYPE_METADATA = 'LISTENER_TYPE_METADATA'; -export const LISTENER_OPTIONS_METADATA = 'LISTENER_OPTIONS_METADATA'; +export const UPDATE_METADATA = 'UPDATE_METADATA'; +export const UPDATE_LISTENER_TYPE_METADATA = 'UPDATE_LISTENER_TYPE_METADATA'; +export const UPDATE_LISTENER_OPTIONS_METADATA = + 'UPDATE_LISTENER_OPTIONS_METADATA'; diff --git a/lib/telegraf.explorer.ts b/lib/telegraf.explorer.ts index fa805b9..4df95e5 100644 --- a/lib/telegraf.explorer.ts +++ b/lib/telegraf.explorer.ts @@ -1,7 +1,7 @@ import { Injectable, OnModuleInit } from '@nestjs/common'; import { DiscoveryService, ModuleRef } from '@nestjs/core'; 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 { ListenerType } from './enums'; import { @@ -19,6 +19,7 @@ import { TextMentionOptions, UrlOptions, } from './decorators'; +import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper'; @Injectable() export class TelegrafExplorer implements OnModuleInit { @@ -39,29 +40,29 @@ export class TelegrafExplorer implements OnModuleInit { } 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() .filter((wrapper) => wrapper.instance) - .forEach((wrapper) => { - const { instance } = wrapper; - - const prototype = Object.getPrototypeOf(instance); - this.metadataScanner.scanFromPrototype( - instance, - prototype, - (methodKey: string) => this.registerIfUpdate(instance, methodKey), - ); - }); + .filter((wrapper) => this.metadataAccessor.isUpdate(wrapper.instance)); } - private registerIfUpdate( - instance: Record, - methodKey: string, - ): void { - const isUpdate = this.metadataAccessor.isUpdate(instance); - } - - private registerIfListener( + private registerIfUpdateListener( instance: Record, methodKey: string, ): void { diff --git a/lib/telegraf-metadata.accessor.ts b/lib/telegraf.metadata-accessor.ts similarity index 73% rename from lib/telegraf-metadata.accessor.ts rename to lib/telegraf.metadata-accessor.ts index f61bb3a..29b5c68 100644 --- a/lib/telegraf-metadata.accessor.ts +++ b/lib/telegraf.metadata-accessor.ts @@ -1,9 +1,9 @@ import { Injectable } from '@nestjs/common'; import { Reflector } from '@nestjs/core'; import { - LISTENER_TYPE_METADATA, + UPDATE_LISTENER_TYPE_METADATA, TELEGRAF_MODULE_OPTIONS, - TELEGRAF_UPDATE_METADATA, + UPDATE_METADATA, } from './telegraf.constants'; import { ListenerType } from './enums'; @@ -12,14 +12,14 @@ export class TelegrafMetadataAccessor { constructor(private readonly reflector: Reflector) {} isUpdate(target: Function): boolean { - return !!this.reflector.get( - TELEGRAF_UPDATE_METADATA, - target, - ); + return !!this.reflector.get(UPDATE_METADATA, target); } getListenerType(target: Function): ListenerType | undefined { - return this.reflector.get(LISTENER_TYPE_METADATA, target); + return this.reflector.get( + UPDATE_LISTENER_TYPE_METADATA, + target, + ); } getListenerOptions(target: Function): unknown | undefined { diff --git a/lib/telegraf.module.ts b/lib/telegraf.module.ts index 77bf8b5..f0e82a2 100644 --- a/lib/telegraf.module.ts +++ b/lib/telegraf.module.ts @@ -6,7 +6,7 @@ import { TelegrafOptionsFactory, } from './interfaces'; 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 { TelegrafProvider } from './telegraf.provider'; diff --git a/package.json b/package.json index 16b1ffc..9756227 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nestjs-telegraf", - "version": "2.0.0-alpha.1", + "version": "2.0.0", "description": "Telegraf module for NestJS", "keywords": [ "nest", diff --git a/tsconfig.json b/tsconfig.json index bb13608..e47f6d2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,6 @@ "rootDir": "./lib", "skipLibCheck": true }, - "include": ["lib/**/*", "../index.ts"], + "include": ["lib/**/*"], "exclude": ["node_modules", "**/*.spec.ts"] }