Comparing version 0.0.17 to 0.0.18
import { Context, ContextType, MaybeArray, UpdateName } from "@gramio/contexts"; | ||
import type { APIMethodParams, APIMethods, TelegramUser } from "@gramio/types"; | ||
import "reflect-metadata"; | ||
import { Plugin } from "./plugin"; | ||
@@ -8,2 +7,3 @@ import { BotOptions, DeriveDefinitions, ErrorDefinitions, Handler, Hooks } from "./types"; | ||
export declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDefinitions = DeriveDefinitions> { | ||
__Derives: Derives; | ||
readonly options: BotOptions; | ||
@@ -10,0 +10,0 @@ info: TelegramUser | undefined; |
450
dist/bot.js
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { | ||
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } | ||
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; | ||
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; | ||
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); | ||
var _, done = false; | ||
for (var i = decorators.length - 1; i >= 0; i--) { | ||
var context = {}; | ||
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; | ||
for (var p in contextIn.access) context.access[p] = contextIn.access[p]; | ||
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; | ||
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); | ||
if (kind === "accessor") { | ||
if (result === void 0) continue; | ||
if (result === null || typeof result !== "object") throw new TypeError("Object expected"); | ||
if (_ = accept(result.get)) descriptor.get = _; | ||
if (_ = accept(result.set)) descriptor.set = _; | ||
if (_ = accept(result.init)) initializers.unshift(_); | ||
} | ||
else if (_ = accept(result)) { | ||
if (kind === "field") initializers.unshift(_); | ||
else descriptor[key] = _; | ||
} | ||
} | ||
if (target) Object.defineProperty(target, contextIn.name, descriptor); | ||
done = true; | ||
}; | ||
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
var useValue = arguments.length > 2; | ||
for (var i = 0; i < initializers.length; i++) { | ||
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); | ||
} | ||
return useValue ? value : void 0; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -14,197 +42,226 @@ exports.Bot = void 0; | ||
const inspectable_1 = require("inspectable"); | ||
require("reflect-metadata"); | ||
const undici_1 = require("undici"); | ||
const errors_1 = require("./errors"); | ||
const updates_1 = require("./updates"); | ||
let Bot = class Bot { | ||
options = {}; | ||
info; | ||
api = new Proxy({}, { | ||
get: (_target, method) => (args) => this._callApi(method, args), | ||
}); | ||
dependencies = []; | ||
errorsDefinitions = { | ||
TELEGRAM: errors_1.TelegramError, | ||
}; | ||
errorHandler(context, error) { | ||
return this.runImmutableHooks("onError", { | ||
context, | ||
//@ts-expect-error ErrorKind exists if user register error-class with .error("kind", SomeError); | ||
kind: error.constructor[errors_1.ErrorKind] ?? "UNKNOWN", | ||
error: error, | ||
let Bot = (() => { | ||
let _classDecorators = [(0, inspectable_1.Inspectable)({ | ||
serialize: () => ({}), | ||
})]; | ||
let _classDescriptor; | ||
let _classExtraInitializers = []; | ||
let _classThis; | ||
var Bot = class { | ||
static { _classThis = this; } | ||
static { | ||
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; | ||
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); | ||
Bot = _classThis = _classDescriptor.value; | ||
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); | ||
__runInitializers(_classThis, _classExtraInitializers); | ||
} | ||
__Derives; | ||
options = {}; | ||
info; | ||
api = new Proxy({}, { | ||
get: (_target, method) => (args) => this._callApi(method, args), | ||
}); | ||
} | ||
updates = new updates_1.Updates(this, this.errorHandler.bind(this)); | ||
hooks = { | ||
preRequest: [ | ||
(ctx) => { | ||
if (!ctx.params) | ||
dependencies = []; | ||
errorsDefinitions = { | ||
TELEGRAM: errors_1.TelegramError, | ||
}; | ||
errorHandler(context, error) { | ||
return this.runImmutableHooks("onError", { | ||
context, | ||
//@ts-expect-error ErrorKind exists if user register error-class with .error("kind", SomeError); | ||
kind: error.constructor[errors_1.ErrorKind] ?? "UNKNOWN", | ||
error: error, | ||
}); | ||
} | ||
updates = new updates_1.Updates(this, this.errorHandler.bind(this)); | ||
hooks = { | ||
preRequest: [ | ||
(ctx) => { | ||
if (!ctx.params) | ||
return ctx; | ||
const formattable = format_1.FormattableMap[ctx.method]; | ||
// @ts-ignore add AnyTelegramMethod to @gramio/format | ||
if (formattable) | ||
ctx.params = formattable(ctx.params); | ||
return ctx; | ||
const formattable = format_1.FormattableMap[ctx.method]; | ||
// @ts-ignore add AnyTelegramMethod to @gramio/format | ||
if (formattable) | ||
ctx.params = formattable(ctx.params); | ||
return ctx; | ||
}, | ||
], | ||
onError: [], | ||
onStart: [], | ||
}; | ||
constructor(token, options) { | ||
this.options = { ...options, token }; | ||
} | ||
async runHooks(type, context) { | ||
let data = context; | ||
for await (const hook of this.hooks[type]) { | ||
data = await hook(data); | ||
}, | ||
], | ||
onError: [], | ||
onStart: [], | ||
}; | ||
constructor(token, options) { | ||
this.options = { ...options, token }; | ||
} | ||
return data; | ||
} | ||
async runImmutableHooks(type, context) { | ||
for await (const hook of this.hooks[type]) { | ||
//TODO: solve that later | ||
//@ts-expect-error | ||
await hook(context); | ||
async runHooks(type, context) { | ||
let data = context; | ||
for await (const hook of this.hooks[type]) { | ||
data = await hook(data); | ||
} | ||
return data; | ||
} | ||
} | ||
async _callApi(method, params = {}) { | ||
const url = `https://api.telegram.org/bot${this.options.token}/${method}`; | ||
const reqOptions = { | ||
method: "POST", | ||
duplex: "half", | ||
}; | ||
const context = await this.runHooks("preRequest", | ||
// TODO: fix type error | ||
// @ts-expect-error | ||
{ | ||
method, | ||
params, | ||
}); | ||
// biome-ignore lint/style/noParameterAssign: mutate params | ||
params = context.params; | ||
if (params && (0, files_1.isMediaUpload)(method, params)) { | ||
const formData = await (0, files_1.convertJsonToFormData)(method, params); | ||
const encoder = new form_data_encoder_1.FormDataEncoder(formData); | ||
reqOptions.body = encoder.encode(); | ||
reqOptions.headers = encoder.headers; | ||
async runImmutableHooks(type, context) { | ||
for await (const hook of this.hooks[type]) { | ||
//TODO: solve that later | ||
//@ts-expect-error | ||
await hook(context); | ||
} | ||
} | ||
else { | ||
reqOptions.headers = { | ||
"Content-Type": "application/json", | ||
async _callApi(method, params = {}) { | ||
const url = `https://api.telegram.org/bot${this.options.token}/${method}`; | ||
const reqOptions = { | ||
method: "POST", | ||
duplex: "half", | ||
}; | ||
reqOptions.body = JSON.stringify(params); | ||
const context = await this.runHooks("preRequest", | ||
// TODO: fix type error | ||
// @ts-expect-error | ||
{ | ||
method, | ||
params, | ||
}); | ||
// biome-ignore lint/style/noParameterAssign: mutate params | ||
params = context.params; | ||
if (params && (0, files_1.isMediaUpload)(method, params)) { | ||
const formData = await (0, files_1.convertJsonToFormData)(method, params); | ||
const encoder = new form_data_encoder_1.FormDataEncoder(formData); | ||
reqOptions.body = encoder.encode(); | ||
reqOptions.headers = encoder.headers; | ||
} | ||
else { | ||
reqOptions.headers = { | ||
"Content-Type": "application/json", | ||
}; | ||
reqOptions.body = JSON.stringify(params); | ||
} | ||
const response = await (0, undici_1.fetch)(url, reqOptions); | ||
const data = (await response.json()); | ||
if (!data.ok) | ||
throw new errors_1.TelegramError(data, method, params); | ||
return data.result; | ||
} | ||
const response = await (0, undici_1.fetch)(url, reqOptions); | ||
const data = (await response.json()); | ||
if (!data.ok) | ||
throw new errors_1.TelegramError(data, method, params); | ||
return data.result; | ||
} | ||
/** | ||
* Register custom class-error for type-safe catch in `onError` hook | ||
* | ||
* @example | ||
* ```ts | ||
* export class NoRights extends Error { | ||
* needRole: "admin" | "moderator"; | ||
* | ||
* constructor(role: "admin" | "moderator") { | ||
* super(); | ||
* this.needRole = role; | ||
* } | ||
* } | ||
* | ||
* const bot = new Bot(process.env.TOKEN!) | ||
* .error("NO_RIGHTS", NoRights) | ||
* .onError(({ context, kind, error }) => { | ||
* if (context.is("message") && kind === "NO_RIGHTS") | ||
* return context.send( | ||
* format`You don't have enough rights! You need to have an «${bold( | ||
* error.needRole | ||
* )}» role.` | ||
* ); | ||
* }); | ||
* | ||
* bot.updates.on("message", (context) => { | ||
* if (context.text === "bun") throw new NoRights("admin"); | ||
* }); | ||
* ``` | ||
*/ | ||
error(kind, error) { | ||
//@ts-expect-error Set ErrorKind | ||
error[errors_1.ErrorKind] = kind; | ||
this.errorsDefinitions[kind] = error; | ||
return this; | ||
} | ||
onError(updateNameOrHandler, handler) { | ||
if (typeof updateNameOrHandler === "function") { | ||
this.hooks.onError.push(updateNameOrHandler); | ||
/** | ||
* Register custom class-error for type-safe catch in `onError` hook | ||
* | ||
* @example | ||
* ```ts | ||
* export class NoRights extends Error { | ||
* needRole: "admin" | "moderator"; | ||
* | ||
* constructor(role: "admin" | "moderator") { | ||
* super(); | ||
* this.needRole = role; | ||
* } | ||
* } | ||
* | ||
* const bot = new Bot(process.env.TOKEN!) | ||
* .error("NO_RIGHTS", NoRights) | ||
* .onError(({ context, kind, error }) => { | ||
* if (context.is("message") && kind === "NO_RIGHTS") | ||
* return context.send( | ||
* format`You don't have enough rights! You need to have an «${bold( | ||
* error.needRole | ||
* )}» role.` | ||
* ); | ||
* }); | ||
* | ||
* bot.updates.on("message", (context) => { | ||
* if (context.text === "bun") throw new NoRights("admin"); | ||
* }); | ||
* ``` | ||
*/ | ||
error(kind, error) { | ||
//@ts-expect-error Set ErrorKind | ||
error[errors_1.ErrorKind] = kind; | ||
this.errorsDefinitions[kind] = error; | ||
return this; | ||
} | ||
if (handler) { | ||
this.hooks.onError.push(async (errContext) => { | ||
if (errContext.context.is(updateNameOrHandler)) | ||
// TODO: Sorry... fix later | ||
//@ts-expect-error | ||
await handler(errContext); | ||
}); | ||
onError(updateNameOrHandler, handler) { | ||
if (typeof updateNameOrHandler === "function") { | ||
this.hooks.onError.push(updateNameOrHandler); | ||
return this; | ||
} | ||
if (handler) { | ||
this.hooks.onError.push(async (errContext) => { | ||
if (errContext.context.is(updateNameOrHandler)) | ||
// TODO: Sorry... fix later | ||
//@ts-expect-error | ||
await handler(errContext); | ||
}); | ||
} | ||
return this; | ||
} | ||
return this; | ||
} | ||
derive(updateNameOrHandler, handler) { | ||
if (typeof updateNameOrHandler === "function") | ||
this.updates.use(async (context, next) => { | ||
for (const [key, value] of Object.entries(await updateNameOrHandler(context))) { | ||
context[key] = value; | ||
} | ||
next(); | ||
}); | ||
else if (handler) | ||
this.updates.on(updateNameOrHandler, async (context, next) => { | ||
for (const [key, value] of Object.entries(await handler(context))) { | ||
context[key] = value; | ||
} | ||
next(); | ||
}); | ||
return this; | ||
} | ||
onStart(handler) { | ||
this.hooks.onStart.push(handler); | ||
return this; | ||
} | ||
on(updateName, handler) { | ||
this.updates.on(updateName, handler); | ||
return this; | ||
} | ||
use(handler) { | ||
this.updates.use(handler); | ||
return this; | ||
} | ||
extend(plugin) { | ||
if (plugin.dependencies.some((dep) => !this.dependencies.includes(dep))) | ||
throw new Error(`The «${plugin.name}» plugin needs dependencies registered before: ${plugin.dependencies | ||
.filter((dep) => !this.dependencies.includes(dep)) | ||
.join(", ")}`); | ||
for (const [key, value] of Object.entries(plugin.errorsDefinitions)) { | ||
if (this.errorsDefinitions[key]) | ||
this.errorsDefinitions[key] = value; | ||
derive(updateNameOrHandler, handler) { | ||
if (typeof updateNameOrHandler === "function") | ||
this.updates.use(async (context, next) => { | ||
for (const [key, value] of Object.entries(await updateNameOrHandler(context))) { | ||
context[key] = value; | ||
} | ||
next(); | ||
}); | ||
else if (handler) | ||
this.updates.on(updateNameOrHandler, async (context, next) => { | ||
for (const [key, value] of Object.entries(await handler(context))) { | ||
context[key] = value; | ||
} | ||
next(); | ||
}); | ||
return this; | ||
} | ||
for (const value of plugin.derives) { | ||
const [derive, updateName] = value; | ||
if (!updateName) | ||
this.derive(derive); | ||
else | ||
this.derive(updateName, derive); | ||
onStart(handler) { | ||
this.hooks.onStart.push(handler); | ||
return this; | ||
} | ||
this.dependencies.push(plugin.name); | ||
return this; | ||
} | ||
async start({ webhook, dropPendingUpdates, allowedUpdates, } = {}) { | ||
//TODO: maybe it useless?? | ||
this.info = await this.api.getMe(); | ||
if (!webhook) { | ||
await this.api.deleteWebhook({ | ||
on(updateName, handler) { | ||
this.updates.on(updateName, handler); | ||
return this; | ||
} | ||
use(handler) { | ||
this.updates.use(handler); | ||
return this; | ||
} | ||
extend(plugin) { | ||
if (plugin.dependencies.some((dep) => !this.dependencies.includes(dep))) | ||
throw new Error(`The «${plugin.name}» plugin needs dependencies registered before: ${plugin.dependencies | ||
.filter((dep) => !this.dependencies.includes(dep)) | ||
.join(", ")}`); | ||
for (const [key, value] of Object.entries(plugin.errorsDefinitions)) { | ||
if (this.errorsDefinitions[key]) | ||
this.errorsDefinitions[key] = value; | ||
} | ||
for (const value of plugin.derives) { | ||
const [derive, updateName] = value; | ||
if (!updateName) | ||
this.derive(derive); | ||
else | ||
this.derive(updateName, derive); | ||
} | ||
this.dependencies.push(plugin.name); | ||
return this; | ||
} | ||
async start({ webhook, dropPendingUpdates, allowedUpdates, } = {}) { | ||
//TODO: maybe it useless?? | ||
this.info = await this.api.getMe(); | ||
if (!webhook) { | ||
await this.api.deleteWebhook({ | ||
drop_pending_updates: dropPendingUpdates, | ||
}); | ||
await this.updates.startPolling({ | ||
allowed_updates: allowedUpdates, | ||
}); | ||
this.runImmutableHooks("onStart", { | ||
plugins: this.dependencies, | ||
info: this.info, | ||
updatesFrom: "long-polling", | ||
}); | ||
return this.info; | ||
} | ||
if (this.updates.isStarted) | ||
this.updates.stopPolling(); | ||
await this.api.setWebhook({ | ||
...webhook, | ||
drop_pending_updates: dropPendingUpdates, | ||
}); | ||
await this.updates.startPolling({ | ||
allowed_updates: allowedUpdates, | ||
@@ -215,26 +272,9 @@ }); | ||
info: this.info, | ||
updatesFrom: "long-polling", | ||
updatesFrom: "webhook", | ||
}); | ||
return this.info; | ||
} | ||
if (this.updates.isStarted) | ||
this.updates.stopPolling(); | ||
await this.api.setWebhook({ | ||
...webhook, | ||
drop_pending_updates: dropPendingUpdates, | ||
allowed_updates: allowedUpdates, | ||
}); | ||
this.runImmutableHooks("onStart", { | ||
plugins: this.dependencies, | ||
info: this.info, | ||
updatesFrom: "long-polling", | ||
}); | ||
return this.info; | ||
} | ||
}; | ||
}; | ||
return Bot = _classThis; | ||
})(); | ||
exports.Bot = Bot; | ||
exports.Bot = Bot = __decorate([ | ||
(0, inspectable_1.Inspectable)({ | ||
serialize: () => ({}), | ||
}) | ||
], Bot); |
@@ -17,2 +17,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// INFO: Temp polyfill, more info https://github.com/microsoft/TypeScript/issues/55453#issuecomment-1687496648 | ||
Symbol.metadata ??= Symbol("Symbol.metadata"); | ||
__exportStar(require("./bot"), exports); | ||
@@ -19,0 +21,0 @@ __exportStar(require("./errors"), exports); |
"use strict"; | ||
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { | ||
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } | ||
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; | ||
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; | ||
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); | ||
var _, done = false; | ||
for (var i = decorators.length - 1; i >= 0; i--) { | ||
var context = {}; | ||
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; | ||
for (var p in contextIn.access) context.access[p] = contextIn.access[p]; | ||
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; | ||
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); | ||
if (kind === "accessor") { | ||
if (result === void 0) continue; | ||
if (result === null || typeof result !== "object") throw new TypeError("Object expected"); | ||
if (_ = accept(result.get)) descriptor.get = _; | ||
if (_ = accept(result.set)) descriptor.set = _; | ||
if (_ = accept(result.init)) initializers.unshift(_); | ||
} | ||
else if (_ = accept(result)) { | ||
if (kind === "field") initializers.unshift(_); | ||
else descriptor[key] = _; | ||
} | ||
} | ||
if (target) Object.defineProperty(target, contextIn.name, descriptor); | ||
done = true; | ||
}; | ||
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
var useValue = arguments.length > 2; | ||
for (var i = 0; i < initializers.length; i++) { | ||
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); | ||
} | ||
return useValue ? value : void 0; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Plugin = void 0; | ||
const inspectable_1 = require("inspectable"); | ||
const _errors_1 = require("./errors"); | ||
class Plugin { | ||
// TODO: fix that dump error. https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcCiUrQCLAGYCWAdgTAREQM5wC8cASsAMbQAmAPAFACQlMUxAOYAaHhixROAPgDcnTqEiw4TADYBDStQAKqgK6Di7cdGqgYwIq2omouQiTIVqdAN4BfKXFc8i6gLbAAFxwfAJEgnI8wJim9sSk5FQhjCxQHDy8-EKi3NyucETAAO5wABQAdFXqUIKUIepEiACUDU0ycGBYMBBIKCG2cO48Xm7uUdwsVPx6TD1QZX6BIWFCzd6ZMAAWBJQVS6h0B3LcwzwA9ABUlzxwlwzAhnwxKnp8EP4qGloAtDEScGInX0hiIt2u52isSgXDyADkAqhzJZrKFshFctw4SVBsirNQCkVSpVqrV6nBGi02ogOl1er1kMF0NChrkpGUANbEVghBGBYRwf7QXk46HrHx5c7nAACMEof3AzBgfxZAGVgPBbABpbmZIVQADa2u5AF1aHAuVYTtxNjs9vrKPFHElKAbLawzXR9RNuFANXooEQEHaKdQ9EQOUQIMUg5o4LoDEZMtxbNQAGTeOAGg6AoN84AmkIASWmjSYwAAKoz2NjirYvMM8rIeMMzgpwNB4GpNNQAEK9YzQswgCz45kSJ2JZzmjxeHzybh4ji1hOgwUjlE6EFGSlSdmZMDbogi4qr4i5VpwFdH9ej1FnojsYh4F4P1NeAD8cH7MEHEnT8ZHu+cAhNsuwbHkfowAGQZgdQcaUicrbyO2Shdt81BwhA9AEIIWxyrem7jtAEFFMArD0BAqhMgAROorD+MQNFwAAPnANH+BArAxOo8w0RMUxhLM8xlFg1EhHRDFMax7GcdxUC8dANHipklB6CgCzNNacH7MA5GUdR5picASGcGcgnwBYfDmkSgGJkQZQ0TAykVPqjlwgA8gA+vQRYAOIABIVqqNEClhOF4XKWnyBZcAAEa9DZJTfr0ZTNDwrkblYZRWTAzRAA | ||
Errors; | ||
Derives; | ||
derives = []; | ||
name; | ||
errorsDefinitions = {}; | ||
dependencies = []; | ||
constructor(name, { dependencies } = {}) { | ||
this.name = name; | ||
if (dependencies) | ||
this.dependencies = dependencies; | ||
} | ||
/** | ||
* Register custom class-error in plugin | ||
**/ | ||
error(kind, error) { | ||
//@ts-expect-error Set ErrorKind | ||
error[_errors_1.ErrorKind] = kind; | ||
this.errorsDefinitions[kind] = error; | ||
return this; | ||
} | ||
derive(updateNameOrHandler, handler) { | ||
if (typeof updateNameOrHandler === "string" && handler) | ||
this.derives.push([handler, updateNameOrHandler]); | ||
else if (typeof updateNameOrHandler === "function") | ||
this.derives.push([updateNameOrHandler, undefined]); | ||
return this; | ||
} | ||
} | ||
let Plugin = (() => { | ||
let _classDecorators = [(0, inspectable_1.Inspectable)({ | ||
serialize: (plugin) => ({ | ||
name: plugin.name, | ||
dependencies: plugin.dependencies, | ||
}), | ||
})]; | ||
let _classDescriptor; | ||
let _classExtraInitializers = []; | ||
let _classThis; | ||
var Plugin = class { | ||
static { _classThis = this; } | ||
static { | ||
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; | ||
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); | ||
Plugin = _classThis = _classDescriptor.value; | ||
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); | ||
__runInitializers(_classThis, _classExtraInitializers); | ||
} | ||
// TODO: fix that dump error. https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcCiUrQCLAGYCWAdgTAREQM5wC8cASsAMbQAmAPAFACQlMUxAOYAaHhixROAPgDcnTqEiw4TADYBDStQAKqgK6Di7cdGqgYwIq2omouQiTIVqdAN4BfKXFc8i6gLbAAFxwfAJEgnI8wJim9sSk5FQhjCxQHDy8-EKi3NyucETAAO5wABQAdFXqUIKUIepEiACUDU0ycGBYMBBIKCG2cO48Xm7uUdwsVPx6TD1QZX6BIWFCzd6ZMAAWBJQVS6h0B3LcwzwA9ABUlzxwlwzAhnwxKnp8EP4qGloAtDEScGInX0hiIt2u52isSgXDyADkAqhzJZrKFshFctw4SVBsirNQCkVSpVqrV6nBGi02ogOl1er1kMF0NChrkpGUANbEVghBGBYRwf7QXk46HrHx5c7nAACMEof3AzBgfxZAGVgPBbABpbmZIVQADa2u5AF1aHAuVYTtxNjs9vrKPFHElKAbLawzXR9RNuFANXooEQEHaKdQ9EQOUQIMUg5o4LoDEZMtxbNQAGTeOAGg6AoN84AmkIASWmjSYwAAKoz2NjirYvMM8rIeMMzgpwNB4GpNNQAEK9YzQswgCz45kSJ2JZzmjxeHzybh4ji1hOgwUjlE6EFGSlSdmZMDbogi4qr4i5VpwFdH9ej1FnojsYh4F4P1NeAD8cH7MEHEnT8ZHu+cAhNsuwbHkfowAGQZgdQcaUicrbyO2Shdt81BwhA9AEIIWxyrem7jtAEFFMArD0BAqhMgAROorD+MQNFwAAPnANH+BArAxOo8w0RMUxhLM8xlFg1EhHRDFMax7GcdxUC8dANHipklB6CgCzNNacH7MA5GUdR5picASGcGcgnwBYfDmkSgGJkQZQ0TAykVPqjlwgA8gA+vQRYAOIABIVqqNEClhOF4XKWnyBZcAAEa9DZJTfr0ZTNDwrkblYZRWTAzRAA | ||
Errors; | ||
Derives; | ||
derives = []; | ||
name; | ||
errorsDefinitions = {}; | ||
dependencies = []; | ||
constructor(name, { dependencies } = {}) { | ||
this.name = name; | ||
if (dependencies) | ||
this.dependencies = dependencies; | ||
} | ||
/** | ||
* Register custom class-error in plugin | ||
**/ | ||
error(kind, error) { | ||
//@ts-expect-error Set ErrorKind | ||
error[_errors_1.ErrorKind] = kind; | ||
this.errorsDefinitions[kind] = error; | ||
return this; | ||
} | ||
derive(updateNameOrHandler, handler) { | ||
if (typeof updateNameOrHandler === "string" && handler) | ||
this.derives.push([handler, updateNameOrHandler]); | ||
else if (typeof updateNameOrHandler === "function") | ||
this.derives.push([updateNameOrHandler, undefined]); | ||
return this; | ||
} | ||
}; | ||
return Plugin = _classThis; | ||
})(); | ||
exports.Plugin = Plugin; |
{ | ||
"name": "gramio", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "Powerful Telegram Bot API framework", | ||
@@ -33,10 +33,9 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"@gramio/contexts": "^0.0.5", | ||
"@gramio/contexts": "^0.0.6", | ||
"@gramio/files": "^0.0.3", | ||
"@gramio/format": "^0.0.8", | ||
"@gramio/keyboards": "^0.1.6", | ||
"@gramio/keyboards": "^0.2.0", | ||
"form-data-encoder": "^4.0.2", | ||
"inspectable": "^2.1.0", | ||
"inspectable": "^3.0.0", | ||
"middleware-io": "^2.8.1", | ||
"reflect-metadata": "^0.2.1", | ||
"undici": "^6.6.2" | ||
@@ -43,0 +42,0 @@ }, |
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
33190
8
751
+ Added@gramio/contexts@0.0.6(transitive)
+ Added@gramio/keyboards@0.2.3(transitive)
+ Addedinspectable@3.0.2(transitive)
- Removedreflect-metadata@^0.2.1
- Removed@gramio/contexts@0.0.5(transitive)
- Removed@gramio/keyboards@0.1.6(transitive)
- Removedinspectable@2.1.1(transitive)
- Removedreflect-metadata@0.2.2(transitive)
- Removedtypescript@5.7.2(transitive)
Updated@gramio/contexts@^0.0.6
Updated@gramio/keyboards@^0.2.0
Updatedinspectable@^3.0.0