gramio 0.0.43 → 0.0.45

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <div align="center">
4
4
 
5
- [![Bot API](https://img.shields.io/badge/Bot%20API-7.6-blue?logo=telegram&style=flat&labelColor=000&color=3b82f6)](https://core.telegram.org/bots/api)
5
+ [![Bot API](https://img.shields.io/badge/Bot%20API-7.7-blue?logo=telegram&style=flat&labelColor=000&color=3b82f6)](https://core.telegram.org/bots/api)
6
6
  [![npm](https://img.shields.io/npm/v/gramio?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/@gramio/core)
7
7
  [![JSR](https://jsr.io/badges/@gramio/core)](https://jsr.io/@gramio/core)
8
8
  [![JSR Score](https://jsr.io/badges/@gramio/core/score)](https://jsr.io/@gramio/core)
package/dist/bot.d.ts CHANGED
@@ -139,6 +139,9 @@ export declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends D
139
139
  derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<typeof this, Update>>>(updateName: MaybeArray<Update>, handler: Handler): Bot<Errors, Derives & {
140
140
  [K in Update]: Awaited<ReturnType<Handler>>;
141
141
  }>;
142
+ decorate<Name extends string, Value>(name: Name, value: Value): Bot<Errors, Derives & {
143
+ global: { [K in Name]: Value; };
144
+ }>;
142
145
  /**
143
146
  * This hook called when the bot is `started`.
144
147
  *
package/dist/bot.js CHANGED
@@ -297,6 +297,15 @@ let Bot = (() => {
297
297
  this.updates.composer.derive(updateNameOrHandler, handler);
298
298
  return this;
299
299
  }
300
+ decorate(name, value) {
301
+ for (const contextName of Object.keys(contexts_1.contextsMappings)) {
302
+ // @ts-expect-error
303
+ Object.defineProperty(contexts_1.contextsMappings[contextName].prototype, name, {
304
+ value,
305
+ });
306
+ }
307
+ return this;
308
+ }
300
309
  /**
301
310
  * This hook called when the bot is `started`.
302
311
  *
@@ -463,6 +472,9 @@ let Bot = (() => {
463
472
  if (plugin._.composer.length) {
464
473
  this.use(plugin._.composer.composed);
465
474
  }
475
+ for (const [key, value] of Object.entries(plugin._.decorators)) {
476
+ this.decorate(key, value);
477
+ }
466
478
  for (const [key, value] of Object.entries(plugin._.errorsDefinitions)) {
467
479
  if (this.errorsDefinitions[key])
468
480
  this.errorsDefinitions[key] = value;
package/dist/plugin.d.ts CHANGED
@@ -75,6 +75,7 @@ export declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extend
75
75
  new (...args: any): any;
76
76
  prototype: Error;
77
77
  }>;
78
+ decorators: Record<string, unknown>;
78
79
  };
79
80
  /** Create new Plugin. Please provide `name` */
80
81
  constructor(name: string, { dependencies }?: {
@@ -111,6 +112,9 @@ export declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extend
111
112
  derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<AnyBot, Update>>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
112
113
  [K in Update]: Awaited<ReturnType<Handler>>;
113
114
  }>;
115
+ decorate<Name extends string, Value>(name: Name, value: Value): Plugin<Errors, Derives & {
116
+ global: { [K in Name]: Value; };
117
+ }>;
114
118
  /** Register handler to one or many Updates */
115
119
  on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<AnyBot, T> & Derives["global"] & Derives[T]>): this;
116
120
  /** Register handler to any Updates */
package/dist/plugin.js CHANGED
@@ -125,6 +125,7 @@ let Plugin = (() => {
125
125
  onErrors: [],
126
126
  /** Map of plugin errors */
127
127
  errorsDefinitions: {},
128
+ decorators: {},
128
129
  };
129
130
  /** Create new Plugin. Please provide `name` */
130
131
  constructor(name, { dependencies } = {}) {
@@ -154,6 +155,10 @@ let Plugin = (() => {
154
155
  this._.composer.derive(updateNameOrHandler, handler);
155
156
  return this;
156
157
  }
158
+ decorate(name, value) {
159
+ this._.decorators[name] = value;
160
+ return this;
161
+ }
157
162
  /** Register handler to one or many Updates */
158
163
  on(updateName, handler) {
159
164
  this._.composer.on(updateName, handler);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "commonjs",
4
- "version": "0.0.43",
4
+ "version": "0.0.45",
5
5
  "description": "Powerful Telegram Bot API framework",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -29,21 +29,24 @@
29
29
  "devDependencies": {
30
30
  "@biomejs/biome": "1.7.3",
31
31
  "@types/debug": "^4.1.12",
32
- "@types/node": "^20.14.9",
33
- "typescript": "^5.5.2"
32
+ "@types/node": "^20.14.10",
33
+ "typescript": "^5.5.3"
34
34
  },
35
35
  "dependencies": {
36
36
  "@gramio/callback-data": "^0.0.3",
37
- "@gramio/contexts": "^0.0.18",
38
- "@gramio/files": "^0.0.9",
37
+ "@gramio/contexts": "^0.0.20",
38
+ "@gramio/files": "^0.0.10",
39
39
  "@gramio/format": "^0.1.3",
40
40
  "@gramio/keyboards": "^0.3.3",
41
- "@gramio/types": "^7.6.0",
41
+ "@gramio/types": "^7.7.0",
42
42
  "debug": "^4.3.5",
43
43
  "inspectable": "^3.0.2",
44
44
  "middleware-io": "^2.8.1",
45
45
  "undici": "^6.19.2"
46
46
  },
47
+ "overrides": {
48
+ "@gramio/types": "^7.7.0"
49
+ },
47
50
  "files": [
48
51
  "dist"
49
52
  ]