gramio 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +3 -3
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -306,12 +306,12 @@ class Updates {
|
|
|
306
306
|
this.composer = new Composer(onError);
|
|
307
307
|
this.queue = new UpdateQueue(this.handleUpdate.bind(this));
|
|
308
308
|
}
|
|
309
|
-
async handleUpdate(data) {
|
|
309
|
+
async handleUpdate(data, mode = "wait") {
|
|
310
310
|
const updateType = Object.keys(data).at(1);
|
|
311
311
|
const UpdateContext = contexts.contextsMappings[updateType];
|
|
312
312
|
if (!UpdateContext) throw new Error(updateType);
|
|
313
313
|
const updatePayload = data[updateType];
|
|
314
|
-
if (!updatePayload) throw new Error("");
|
|
314
|
+
if (!updatePayload) throw new Error("Unsupported event??");
|
|
315
315
|
try {
|
|
316
316
|
let context = new UpdateContext({
|
|
317
317
|
bot: this.bot,
|
|
@@ -333,7 +333,7 @@ class Updates {
|
|
|
333
333
|
updateId: data.update_id
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
|
-
return this.composer.composeWait(context);
|
|
336
|
+
return mode === "wait" ? this.composer.composeWait(context) : this.composer.compose(context);
|
|
337
337
|
} catch (error) {
|
|
338
338
|
throw new Error(`[UPDATES] Update type ${updateType} not supported.`);
|
|
339
339
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -198,10 +198,10 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
198
198
|
* })
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
201
|
-
derive<Handler extends Hooks.Derive<Context<
|
|
201
|
+
derive<Handler extends Hooks.Derive<Context<BotLike> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
|
|
202
202
|
global: Awaited<ReturnType<Handler>>;
|
|
203
203
|
}>;
|
|
204
|
-
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<
|
|
204
|
+
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
|
|
205
205
|
[K in Update]: Awaited<ReturnType<Handler>>;
|
|
206
206
|
}>;
|
|
207
207
|
decorate<Value extends Record<string, any>>(value: Value): Plugin<Errors, Derives & {
|
|
@@ -215,9 +215,9 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
215
215
|
};
|
|
216
216
|
}>;
|
|
217
217
|
/** Register handler to one or many Updates */
|
|
218
|
-
on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<
|
|
218
|
+
on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
219
219
|
/** Register handler to any Updates */
|
|
220
|
-
use(handler: Handler<Context<
|
|
220
|
+
use(handler: Handler<Context<BotLike> & Derives["global"]>): this;
|
|
221
221
|
/**
|
|
222
222
|
* This hook called before sending a request to Telegram Bot API (allows us to impact the sent parameters).
|
|
223
223
|
*
|
|
@@ -305,8 +305,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
305
305
|
* })
|
|
306
306
|
* ```
|
|
307
307
|
*/
|
|
308
|
-
onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<
|
|
309
|
-
onError(handler: Hooks.OnError<Errors, Context<
|
|
308
|
+
onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
309
|
+
onError(handler: Hooks.OnError<Errors, Context<BotLike> & Derives["global"]>): this;
|
|
310
310
|
/**
|
|
311
311
|
* ! ** At the moment, it can only pick up types** */
|
|
312
312
|
extend<NewPlugin extends AnyPlugin>(plugin: MaybePromise<NewPlugin>): Plugin<Errors & NewPlugin["_"]["Errors"], Derives & NewPlugin["_"]["Derives"]>;
|
|
@@ -580,7 +580,7 @@ declare class Updates {
|
|
|
580
580
|
composer: Composer;
|
|
581
581
|
queue: UpdateQueue<TelegramUpdate>;
|
|
582
582
|
constructor(bot: AnyBot, onError: CaughtMiddlewareHandler<Context<any>>);
|
|
583
|
-
handleUpdate(data: TelegramUpdate): Promise<unknown>;
|
|
583
|
+
handleUpdate(data: TelegramUpdate, mode?: "wait" | "lazy"): Promise<unknown>;
|
|
584
584
|
/** @deprecated use bot.start instead @internal */
|
|
585
585
|
startPolling(params?: APIMethodParams<"getUpdates">): void;
|
|
586
586
|
startFetchLoop(params?: APIMethodParams<"getUpdates">): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -198,10 +198,10 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
198
198
|
* })
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
201
|
-
derive<Handler extends Hooks.Derive<Context<
|
|
201
|
+
derive<Handler extends Hooks.Derive<Context<BotLike> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
|
|
202
202
|
global: Awaited<ReturnType<Handler>>;
|
|
203
203
|
}>;
|
|
204
|
-
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<
|
|
204
|
+
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
|
|
205
205
|
[K in Update]: Awaited<ReturnType<Handler>>;
|
|
206
206
|
}>;
|
|
207
207
|
decorate<Value extends Record<string, any>>(value: Value): Plugin<Errors, Derives & {
|
|
@@ -215,9 +215,9 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
215
215
|
};
|
|
216
216
|
}>;
|
|
217
217
|
/** Register handler to one or many Updates */
|
|
218
|
-
on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<
|
|
218
|
+
on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
219
219
|
/** Register handler to any Updates */
|
|
220
|
-
use(handler: Handler<Context<
|
|
220
|
+
use(handler: Handler<Context<BotLike> & Derives["global"]>): this;
|
|
221
221
|
/**
|
|
222
222
|
* This hook called before sending a request to Telegram Bot API (allows us to impact the sent parameters).
|
|
223
223
|
*
|
|
@@ -305,8 +305,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
305
305
|
* })
|
|
306
306
|
* ```
|
|
307
307
|
*/
|
|
308
|
-
onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<
|
|
309
|
-
onError(handler: Hooks.OnError<Errors, Context<
|
|
308
|
+
onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
309
|
+
onError(handler: Hooks.OnError<Errors, Context<BotLike> & Derives["global"]>): this;
|
|
310
310
|
/**
|
|
311
311
|
* ! ** At the moment, it can only pick up types** */
|
|
312
312
|
extend<NewPlugin extends AnyPlugin>(plugin: MaybePromise<NewPlugin>): Plugin<Errors & NewPlugin["_"]["Errors"], Derives & NewPlugin["_"]["Derives"]>;
|
|
@@ -580,7 +580,7 @@ declare class Updates {
|
|
|
580
580
|
composer: Composer;
|
|
581
581
|
queue: UpdateQueue<TelegramUpdate>;
|
|
582
582
|
constructor(bot: AnyBot, onError: CaughtMiddlewareHandler<Context<any>>);
|
|
583
|
-
handleUpdate(data: TelegramUpdate): Promise<unknown>;
|
|
583
|
+
handleUpdate(data: TelegramUpdate, mode?: "wait" | "lazy"): Promise<unknown>;
|
|
584
584
|
/** @deprecated use bot.start instead @internal */
|
|
585
585
|
startPolling(params?: APIMethodParams<"getUpdates">): void;
|
|
586
586
|
startFetchLoop(params?: APIMethodParams<"getUpdates">): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -308,12 +308,12 @@ class Updates {
|
|
|
308
308
|
this.composer = new Composer(onError);
|
|
309
309
|
this.queue = new UpdateQueue(this.handleUpdate.bind(this));
|
|
310
310
|
}
|
|
311
|
-
async handleUpdate(data) {
|
|
311
|
+
async handleUpdate(data, mode = "wait") {
|
|
312
312
|
const updateType = Object.keys(data).at(1);
|
|
313
313
|
const UpdateContext = contextsMappings[updateType];
|
|
314
314
|
if (!UpdateContext) throw new Error(updateType);
|
|
315
315
|
const updatePayload = data[updateType];
|
|
316
|
-
if (!updatePayload) throw new Error("");
|
|
316
|
+
if (!updatePayload) throw new Error("Unsupported event??");
|
|
317
317
|
try {
|
|
318
318
|
let context = new UpdateContext({
|
|
319
319
|
bot: this.bot,
|
|
@@ -335,7 +335,7 @@ class Updates {
|
|
|
335
335
|
updateId: data.update_id
|
|
336
336
|
});
|
|
337
337
|
}
|
|
338
|
-
return this.composer.composeWait(context);
|
|
338
|
+
return mode === "wait" ? this.composer.composeWait(context) : this.composer.compose(context);
|
|
339
339
|
} catch (error) {
|
|
340
340
|
throw new Error(`[UPDATES] Update type ${updateType} not supported.`);
|
|
341
341
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gramio",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"description": "Powerful, extensible and really type-safe Telegram Bot API framework",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -56,14 +56,15 @@
|
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@biomejs/biome": "1.9.4",
|
|
59
|
-
"@types/bun": "^1.2.
|
|
59
|
+
"@types/bun": "^1.2.10",
|
|
60
60
|
"@types/debug": "^4.1.12",
|
|
61
|
+
"expect-type": "^1.2.1",
|
|
61
62
|
"pkgroll": "^2.12.1",
|
|
62
63
|
"typescript": "^5.8.3"
|
|
63
64
|
},
|
|
64
65
|
"dependencies": {
|
|
65
66
|
"@gramio/callback-data": "^0.0.3",
|
|
66
|
-
"@gramio/contexts": "^0.2.
|
|
67
|
+
"@gramio/contexts": "^0.2.5",
|
|
67
68
|
"@gramio/files": "^0.3.0",
|
|
68
69
|
"@gramio/format": "^0.2.0",
|
|
69
70
|
"@gramio/keyboards": "^1.2.1",
|