gramio 0.4.0 → 0.4.2
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 +2 -2
- package/dist/index.d.cts +15 -13
- package/dist/index.d.ts +15 -13
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -54,14 +54,14 @@ class Composer {
|
|
|
54
54
|
)) {
|
|
55
55
|
context[key] = value;
|
|
56
56
|
}
|
|
57
|
-
next();
|
|
57
|
+
return await next();
|
|
58
58
|
});
|
|
59
59
|
else if (handler)
|
|
60
60
|
this.on(updateNameOrHandler, async (context, next) => {
|
|
61
61
|
for (const [key, value] of Object.entries(await handler(context))) {
|
|
62
62
|
context[key] = value;
|
|
63
63
|
}
|
|
64
|
-
next();
|
|
64
|
+
return await next();
|
|
65
65
|
});
|
|
66
66
|
return this;
|
|
67
67
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CallbackData } from '@gramio/callback-data';
|
|
2
2
|
export * from '@gramio/callback-data';
|
|
3
|
-
import { Context, UpdateName,
|
|
3
|
+
import { Context, UpdateName, ContextType, MaybeArray as MaybeArray$1, BotLike, Attachment } from '@gramio/contexts';
|
|
4
4
|
export * from '@gramio/contexts';
|
|
5
5
|
import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramReactionTypeEmojiEmoji, SetMyCommandsParams, TelegramBotCommand } from '@gramio/types';
|
|
6
6
|
export * from '@gramio/types';
|
|
@@ -26,6 +26,8 @@ declare class TelegramError<T extends keyof APIMethods> extends Error {
|
|
|
26
26
|
constructor(error: TelegramAPIResponseError, method: T, params: MaybeSuppressedParams<T>);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
type MaybeArray<T> = T | T[] | ReadonlyArray<T>;
|
|
30
|
+
|
|
29
31
|
/** Base-composer without chainable type-safety */
|
|
30
32
|
declare class Composer {
|
|
31
33
|
protected composer: Composer$1<Context<AnyBot> & {
|
|
@@ -109,11 +111,11 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
109
111
|
/** Composer */
|
|
110
112
|
composer: Composer;
|
|
111
113
|
/** Store plugin preRequests hooks */
|
|
112
|
-
preRequests: [Hooks.PreRequest<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
114
|
+
preRequests: [Hooks.PreRequest<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
113
115
|
/** Store plugin onResponses hooks */
|
|
114
|
-
onResponses: [Hooks.OnResponse<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
116
|
+
onResponses: [Hooks.OnResponse<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
115
117
|
/** Store plugin onResponseErrors hooks */
|
|
116
|
-
onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
118
|
+
onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
117
119
|
/**
|
|
118
120
|
* Store plugin groups
|
|
119
121
|
*
|
|
@@ -145,11 +147,11 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
145
147
|
/** Composer */
|
|
146
148
|
composer: Composer;
|
|
147
149
|
/** Store plugin preRequests hooks */
|
|
148
|
-
preRequests: [Hooks.PreRequest<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
150
|
+
preRequests: [Hooks.PreRequest<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
149
151
|
/** Store plugin onResponses hooks */
|
|
150
|
-
onResponses: [Hooks.OnResponse<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
152
|
+
onResponses: [Hooks.OnResponse<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
151
153
|
/** Store plugin onResponseErrors hooks */
|
|
152
|
-
onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
154
|
+
onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
153
155
|
/**
|
|
154
156
|
* Store plugin groups
|
|
155
157
|
*
|
|
@@ -201,7 +203,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
201
203
|
derive<Handler extends Hooks.Derive<Context<BotLike> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
|
|
202
204
|
global: Awaited<ReturnType<Handler>>;
|
|
203
205
|
}>;
|
|
204
|
-
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
|
|
206
|
+
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray$1<Update>, handler: Handler): Plugin<Errors, Derives & {
|
|
205
207
|
[K in Update]: Awaited<ReturnType<Handler>>;
|
|
206
208
|
}>;
|
|
207
209
|
decorate<Value extends Record<string, any>>(value: Value): Plugin<Errors, Derives & {
|
|
@@ -215,7 +217,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
215
217
|
};
|
|
216
218
|
}>;
|
|
217
219
|
/** Register handler to one or many Updates */
|
|
218
|
-
on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
220
|
+
on<T extends UpdateName>(updateName: MaybeArray$1<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
219
221
|
/** Register handler to any Updates */
|
|
220
222
|
use(handler: Handler<Context<BotLike> & Derives["global"]>): this;
|
|
221
223
|
/**
|
|
@@ -238,21 +240,21 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
238
240
|
*
|
|
239
241
|
* [Documentation](https://gramio.dev/hooks/pre-request.html)
|
|
240
242
|
* */
|
|
241
|
-
preRequest<Methods extends keyof APIMethods, Handler extends Hooks.PreRequest<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
|
|
243
|
+
preRequest<Methods extends keyof APIMethods, Handler extends Hooks.PreRequest<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
|
|
242
244
|
preRequest(handler: Hooks.PreRequest): this;
|
|
243
245
|
/**
|
|
244
246
|
* This hook called when API return successful response
|
|
245
247
|
*
|
|
246
248
|
* [Documentation](https://gramio.dev/hooks/on-response.html)
|
|
247
249
|
* */
|
|
248
|
-
onResponse<Methods extends keyof APIMethods, Handler extends Hooks.OnResponse<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
|
|
250
|
+
onResponse<Methods extends keyof APIMethods, Handler extends Hooks.OnResponse<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
|
|
249
251
|
onResponse(handler: Hooks.OnResponse): this;
|
|
250
252
|
/**
|
|
251
253
|
* This hook called when API return an error
|
|
252
254
|
*
|
|
253
255
|
* [Documentation](https://gramio.dev/hooks/on-response-error.html)
|
|
254
256
|
* */
|
|
255
|
-
onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
|
|
257
|
+
onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
|
|
256
258
|
onResponseError(handler: Hooks.OnResponseError): this;
|
|
257
259
|
/**
|
|
258
260
|
* This hook called when the bot is `started`.
|
|
@@ -305,7 +307,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
305
307
|
* })
|
|
306
308
|
* ```
|
|
307
309
|
*/
|
|
308
|
-
onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
310
|
+
onError<T extends UpdateName>(updateName: MaybeArray$1<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
309
311
|
onError(handler: Hooks.OnError<Errors, Context<BotLike> & Derives["global"]>): this;
|
|
310
312
|
/**
|
|
311
313
|
* ! ** At the moment, it can only pick up types** */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CallbackData } from '@gramio/callback-data';
|
|
2
2
|
export * from '@gramio/callback-data';
|
|
3
|
-
import { Context, UpdateName,
|
|
3
|
+
import { Context, UpdateName, ContextType, MaybeArray as MaybeArray$1, BotLike, Attachment } from '@gramio/contexts';
|
|
4
4
|
export * from '@gramio/contexts';
|
|
5
5
|
import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramReactionTypeEmojiEmoji, SetMyCommandsParams, TelegramBotCommand } from '@gramio/types';
|
|
6
6
|
export * from '@gramio/types';
|
|
@@ -26,6 +26,8 @@ declare class TelegramError<T extends keyof APIMethods> extends Error {
|
|
|
26
26
|
constructor(error: TelegramAPIResponseError, method: T, params: MaybeSuppressedParams<T>);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
type MaybeArray<T> = T | T[] | ReadonlyArray<T>;
|
|
30
|
+
|
|
29
31
|
/** Base-composer without chainable type-safety */
|
|
30
32
|
declare class Composer {
|
|
31
33
|
protected composer: Composer$1<Context<AnyBot> & {
|
|
@@ -109,11 +111,11 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
109
111
|
/** Composer */
|
|
110
112
|
composer: Composer;
|
|
111
113
|
/** Store plugin preRequests hooks */
|
|
112
|
-
preRequests: [Hooks.PreRequest<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
114
|
+
preRequests: [Hooks.PreRequest<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
113
115
|
/** Store plugin onResponses hooks */
|
|
114
|
-
onResponses: [Hooks.OnResponse<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
116
|
+
onResponses: [Hooks.OnResponse<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
115
117
|
/** Store plugin onResponseErrors hooks */
|
|
116
|
-
onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
118
|
+
onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
117
119
|
/**
|
|
118
120
|
* Store plugin groups
|
|
119
121
|
*
|
|
@@ -145,11 +147,11 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
145
147
|
/** Composer */
|
|
146
148
|
composer: Composer;
|
|
147
149
|
/** Store plugin preRequests hooks */
|
|
148
|
-
preRequests: [Hooks.PreRequest<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
150
|
+
preRequests: [Hooks.PreRequest<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
149
151
|
/** Store plugin onResponses hooks */
|
|
150
|
-
onResponses: [Hooks.OnResponse<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
152
|
+
onResponses: [Hooks.OnResponse<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
151
153
|
/** Store plugin onResponseErrors hooks */
|
|
152
|
-
onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray<keyof APIMethods> | undefined][];
|
|
154
|
+
onResponseErrors: [Hooks.OnResponseError<any>, MaybeArray$1<keyof APIMethods> | undefined][];
|
|
153
155
|
/**
|
|
154
156
|
* Store plugin groups
|
|
155
157
|
*
|
|
@@ -201,7 +203,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
201
203
|
derive<Handler extends Hooks.Derive<Context<BotLike> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
|
|
202
204
|
global: Awaited<ReturnType<Handler>>;
|
|
203
205
|
}>;
|
|
204
|
-
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
|
|
206
|
+
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray$1<Update>, handler: Handler): Plugin<Errors, Derives & {
|
|
205
207
|
[K in Update]: Awaited<ReturnType<Handler>>;
|
|
206
208
|
}>;
|
|
207
209
|
decorate<Value extends Record<string, any>>(value: Value): Plugin<Errors, Derives & {
|
|
@@ -215,7 +217,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
215
217
|
};
|
|
216
218
|
}>;
|
|
217
219
|
/** Register handler to one or many Updates */
|
|
218
|
-
on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
220
|
+
on<T extends UpdateName>(updateName: MaybeArray$1<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
219
221
|
/** Register handler to any Updates */
|
|
220
222
|
use(handler: Handler<Context<BotLike> & Derives["global"]>): this;
|
|
221
223
|
/**
|
|
@@ -238,21 +240,21 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
238
240
|
*
|
|
239
241
|
* [Documentation](https://gramio.dev/hooks/pre-request.html)
|
|
240
242
|
* */
|
|
241
|
-
preRequest<Methods extends keyof APIMethods, Handler extends Hooks.PreRequest<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
|
|
243
|
+
preRequest<Methods extends keyof APIMethods, Handler extends Hooks.PreRequest<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
|
|
242
244
|
preRequest(handler: Hooks.PreRequest): this;
|
|
243
245
|
/**
|
|
244
246
|
* This hook called when API return successful response
|
|
245
247
|
*
|
|
246
248
|
* [Documentation](https://gramio.dev/hooks/on-response.html)
|
|
247
249
|
* */
|
|
248
|
-
onResponse<Methods extends keyof APIMethods, Handler extends Hooks.OnResponse<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
|
|
250
|
+
onResponse<Methods extends keyof APIMethods, Handler extends Hooks.OnResponse<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
|
|
249
251
|
onResponse(handler: Hooks.OnResponse): this;
|
|
250
252
|
/**
|
|
251
253
|
* This hook called when API return an error
|
|
252
254
|
*
|
|
253
255
|
* [Documentation](https://gramio.dev/hooks/on-response-error.html)
|
|
254
256
|
* */
|
|
255
|
-
onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
|
|
257
|
+
onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray$1<Methods>, handler: Handler): this;
|
|
256
258
|
onResponseError(handler: Hooks.OnResponseError): this;
|
|
257
259
|
/**
|
|
258
260
|
* This hook called when the bot is `started`.
|
|
@@ -305,7 +307,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
305
307
|
* })
|
|
306
308
|
* ```
|
|
307
309
|
*/
|
|
308
|
-
onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
310
|
+
onError<T extends UpdateName>(updateName: MaybeArray$1<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
|
|
309
311
|
onError(handler: Hooks.OnError<Errors, Context<BotLike> & Derives["global"]>): this;
|
|
310
312
|
/**
|
|
311
313
|
* ! ** At the moment, it can only pick up types** */
|
package/dist/index.js
CHANGED
|
@@ -56,14 +56,14 @@ class Composer {
|
|
|
56
56
|
)) {
|
|
57
57
|
context[key] = value;
|
|
58
58
|
}
|
|
59
|
-
next();
|
|
59
|
+
return await next();
|
|
60
60
|
});
|
|
61
61
|
else if (handler)
|
|
62
62
|
this.on(updateNameOrHandler, async (context, next) => {
|
|
63
63
|
for (const [key, value] of Object.entries(await handler(context))) {
|
|
64
64
|
context[key] = value;
|
|
65
65
|
}
|
|
66
|
-
next();
|
|
66
|
+
return await next();
|
|
67
67
|
});
|
|
68
68
|
return this;
|
|
69
69
|
}
|