Comparing version 0.0.14 to 0.0.15
import { Context, ContextType, MaybeArray, UpdateName } from "@gramio/contexts"; | ||
import type { APIMethods } from "@gramio/types"; | ||
import "reflect-metadata"; | ||
import { Plugin } from "#plugin"; | ||
import { Plugin } from "./plugin"; | ||
import { BotOptions, DeriveDefinitions, ErrorDefinitions, Handler, Hooks } from "./types"; | ||
@@ -64,6 +64,6 @@ import { Updates } from "./updates"; | ||
derive<Handler extends Hooks.Derive<Context<typeof this>>>(handler: Handler): Bot<Errors, Derives & { | ||
global: ReturnType<Handler>; | ||
global: Awaited<ReturnType<Handler>>; | ||
}>; | ||
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<typeof this, Update>>>(updateName: Update, handler: Handler): Bot<Errors, Derives & { | ||
[K in Update]: ReturnType<Handler>; | ||
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<typeof this, Update>>>(updateName: MaybeArray<Update>, handler: Handler): Bot<Errors, Derives & { | ||
[K in Update]: Awaited<ReturnType<Handler>>; | ||
}>; | ||
@@ -70,0 +70,0 @@ on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<typeof this, T> & Derives["global"] & Derives[T]>): this; |
@@ -150,4 +150,4 @@ "use strict"; | ||
if (typeof updateNameOrHandler === "function") | ||
this.updates.use((context, next) => { | ||
for (const [key, value] of Object.entries(updateNameOrHandler(context))) { | ||
this.updates.use(async (context, next) => { | ||
for (const [key, value] of Object.entries(await updateNameOrHandler(context))) { | ||
context[key] = value; | ||
@@ -158,4 +158,4 @@ } | ||
else if (handler) | ||
this.updates.on(updateNameOrHandler, (context, next) => { | ||
for (const [key, value] of Object.entries(handler(context))) { | ||
this.updates.on(updateNameOrHandler, async (context, next) => { | ||
for (const [key, value] of Object.entries(await handler(context))) { | ||
context[key] = value; | ||
@@ -162,0 +162,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { BotLike, Context, ContextType, UpdateName } from "@gramio/contexts"; | ||
import { DeriveDefinitions, ErrorDefinitions, Hooks } from "types"; | ||
import { BotLike, Context, ContextType, MaybeArray, UpdateName } from "@gramio/contexts"; | ||
import { DeriveDefinitions, ErrorDefinitions, Hooks } from "./types"; | ||
export declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends DeriveDefinitions = DeriveDefinitions> { | ||
@@ -19,9 +19,9 @@ Errors: Errors; | ||
prototype: Error; | ||
}>(kind: Name, error: NewError): Plugin<Errors & { [name in Name]: InstanceType<NewError>; }, DeriveDefinitions>; | ||
}>(kind: Name, error: NewError): Plugin<Errors & { [name in Name]: InstanceType<NewError>; }, Derives>; | ||
derive<Handler extends Hooks.Derive<Context<BotLike>>>(handler: Handler): Plugin<Errors, Derives & { | ||
global: ReturnType<Handler>; | ||
global: Awaited<ReturnType<Handler>>; | ||
}>; | ||
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update>>>(updateName: Update, handler: Handler): Plugin<Errors, Derives & { | ||
[K in Update]: ReturnType<Handler>; | ||
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update>>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & { | ||
[K in Update]: Awaited<ReturnType<Handler>>; | ||
}>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Plugin = void 0; | ||
const _errors_1 = require("#errors"); | ||
const _errors_1 = require("./errors"); | ||
class Plugin { | ||
@@ -6,0 +6,0 @@ // TODO: fix that dump error. https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcCiUrQCLAGYCWAdgTAREQM5wC8cASsAMbQAmAPAFACQlMUxAOYAaHhixROAPgDcnTqEiw4TADYBDStQAKqgK6Di7cdGqgYwIq2omouQiTIVqdAN4BfKXFc8i6gLbAAFxwfAJEgnI8wJim9sSk5FQhjCxQHDy8-EKi3NyucETAAO5wABQAdFXqUIKUIepEiACUDU0ycGBYMBBIKCG2cO48Xm7uUdwsVPx6TD1QZX6BIWFCzd6ZMAAWBJQVS6h0B3LcwzwA9ABUlzxwlwzAhnwxKnp8EP4qGloAtDEScGInX0hiIt2u52isSgXDyADkAqhzJZrKFshFctw4SVBsirNQCkVSpVqrV6nBGi02ogOl1er1kMF0NChrkpGUANbEVghBGBYRwf7QXk46HrHx5c7nAACMEof3AzBgfxZAGVgPBbABpbmZIVQADa2u5AF1aHAuVYTtxNjs9vrKPFHElKAbLawzXR9RNuFANXooEQEHaKdQ9EQOUQIMUg5o4LoDEZMtxbNQAGTeOAGg6AoN84AmkIASWmjSYwAAKoz2NjirYvMM8rIeMMzgpwNB4GpNNQAEK9YzQswgCz45kSJ2JZzmjxeHzybh4ji1hOgwUjlE6EFGSlSdmZMDbogi4qr4i5VpwFdH9ej1FnojsYh4F4P1NeAD8cH7MEHEnT8ZHu+cAhNsuwbHkfowAGQZgdQcaUicrbyO2Shdt81BwhA9AEIIWxyrem7jtAEFFMArD0BAqhMgAROorD+MQNFwAAPnANH+BArAxOo8w0RMUxhLM8xlFg1EhHRDFMax7GcdxUC8dANHipklB6CgCzNNacH7MA5GUdR5picASGcGcgnwBYfDmkSgGJkQZQ0TAykVPqjlwgA8gA+vQRYAOIABIVqqNEClhOF4XKWnyBZcAAEa9DZJTfr0ZTNDwrkblYZRWTAzRAA |
@@ -23,5 +23,5 @@ import { BotLike, Context, UpdateName } from "@gramio/contexts"; | ||
}[keyof APIMethods]; | ||
type MaybePromise<T> = T | Promise<T>; | ||
export type MaybePromise<T> = Promise<T> | T; | ||
export declare namespace Hooks { | ||
type Derive<Ctx> = (context: Ctx) => object; | ||
type Derive<Ctx> = (context: Ctx) => MaybePromise<Record<string, unknown>>; | ||
type PreRequestContext = AnyTelegramMethod; | ||
@@ -28,0 +28,0 @@ type PreRequest = (ctx: PreRequestContext) => MaybePromise<PreRequestContext>; |
{ | ||
"name": "gramio", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Powerful Telegram Bot API framework", | ||
@@ -22,3 +22,3 @@ "main": "./dist/index.js", | ||
"lint:fix": "bun lint --apply", | ||
"prepublishOnly": "tsc" | ||
"prepublishOnly": "tsc && bunx tsc-alias" | ||
}, | ||
@@ -25,0 +25,0 @@ "author": "kravets", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22344