@gramio/composer 0.3.3 → 0.3.4

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 CHANGED
@@ -386,6 +386,31 @@ class Composer {
386
386
  return info;
387
387
  });
388
388
  }
389
+ /**
390
+ * Returns a Set of all event names registered via `.on()` and event-specific `.derive()`.
391
+ *
392
+ * Useful for introspecting which update types the middleware chain handles,
393
+ * e.g. to auto-derive `allowed_updates` for the Telegram Bot API.
394
+ *
395
+ * @example
396
+ * ```typescript
397
+ * composer.on("message", handler);
398
+ * composer.on(["callback_query", "inline_query"], handler);
399
+ * composer.registeredEvents(); // Set {"message", "callback_query", "inline_query"}
400
+ * ```
401
+ */
402
+ registeredEvents() {
403
+ const events = /* @__PURE__ */ new Set();
404
+ for (const mw of this["~"].middlewares) {
405
+ if ((mw.type === "on" || mw.type === "derive") && mw.name) {
406
+ for (const part of mw.name.split("|")) {
407
+ const eventPart = part.includes(":") ? part.split(":")[0] : part;
408
+ if (eventPart) events.add(eventPart);
409
+ }
410
+ }
411
+ }
412
+ return events;
413
+ }
389
414
  trace(handler) {
390
415
  this["~"].tracer = handler;
391
416
  this.invalidate();
package/dist/index.d.cts CHANGED
@@ -191,6 +191,20 @@ declare class Composer<TIn extends object = {}, TOut extends TIn = TIn, TExposed
191
191
  group(fn: (composer: Composer<TOut, TOut, {}>) => void): Composer<TIn, TOut, TExposed>;
192
192
  extend<UIn extends object, UOut extends UIn, UExposed extends object, UMacros extends MacroDefinitions = {}>(other: Composer<UIn, UOut, UExposed, UMacros>): Composer<TIn, TOut & UExposed, TExposed, TMacros & UMacros>;
193
193
  inspect(): MiddlewareInfo[];
194
+ /**
195
+ * Returns a Set of all event names registered via `.on()` and event-specific `.derive()`.
196
+ *
197
+ * Useful for introspecting which update types the middleware chain handles,
198
+ * e.g. to auto-derive `allowed_updates` for the Telegram Bot API.
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * composer.on("message", handler);
203
+ * composer.on(["callback_query", "inline_query"], handler);
204
+ * composer.registeredEvents(); // Set {"message", "callback_query", "inline_query"}
205
+ * ```
206
+ */
207
+ registeredEvents(): Set<string>;
194
208
  trace(handler: TraceHandler): this;
195
209
  compose(): ComposedMiddleware<TIn>;
196
210
  run(context: TIn, next?: Next): Promise<void>;
@@ -301,6 +315,7 @@ interface EventComposer<TBase extends object, TEventMap extends Record<string, T
301
315
  /** Register multiple macros at once */
302
316
  macro<const TDefs extends Record<string, MacroDef<any, any>>>(definitions: TDefs): EventComposer<TBase, TEventMap, TIn, TOut, TExposed, TDerives, TMethods, TMacros & TDefs> & TMethods;
303
317
  inspect(): MiddlewareInfo[];
318
+ registeredEvents(): Set<string>;
304
319
  trace(handler: TraceHandler): this;
305
320
  compose(): ComposedMiddleware<TIn>;
306
321
  run(context: TIn, next?: Next): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -191,6 +191,20 @@ declare class Composer<TIn extends object = {}, TOut extends TIn = TIn, TExposed
191
191
  group(fn: (composer: Composer<TOut, TOut, {}>) => void): Composer<TIn, TOut, TExposed>;
192
192
  extend<UIn extends object, UOut extends UIn, UExposed extends object, UMacros extends MacroDefinitions = {}>(other: Composer<UIn, UOut, UExposed, UMacros>): Composer<TIn, TOut & UExposed, TExposed, TMacros & UMacros>;
193
193
  inspect(): MiddlewareInfo[];
194
+ /**
195
+ * Returns a Set of all event names registered via `.on()` and event-specific `.derive()`.
196
+ *
197
+ * Useful for introspecting which update types the middleware chain handles,
198
+ * e.g. to auto-derive `allowed_updates` for the Telegram Bot API.
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * composer.on("message", handler);
203
+ * composer.on(["callback_query", "inline_query"], handler);
204
+ * composer.registeredEvents(); // Set {"message", "callback_query", "inline_query"}
205
+ * ```
206
+ */
207
+ registeredEvents(): Set<string>;
194
208
  trace(handler: TraceHandler): this;
195
209
  compose(): ComposedMiddleware<TIn>;
196
210
  run(context: TIn, next?: Next): Promise<void>;
@@ -301,6 +315,7 @@ interface EventComposer<TBase extends object, TEventMap extends Record<string, T
301
315
  /** Register multiple macros at once */
302
316
  macro<const TDefs extends Record<string, MacroDef<any, any>>>(definitions: TDefs): EventComposer<TBase, TEventMap, TIn, TOut, TExposed, TDerives, TMethods, TMacros & TDefs> & TMethods;
303
317
  inspect(): MiddlewareInfo[];
318
+ registeredEvents(): Set<string>;
304
319
  trace(handler: TraceHandler): this;
305
320
  compose(): ComposedMiddleware<TIn>;
306
321
  run(context: TIn, next?: Next): Promise<void>;
package/dist/index.js CHANGED
@@ -383,6 +383,31 @@ class Composer {
383
383
  return info;
384
384
  });
385
385
  }
386
+ /**
387
+ * Returns a Set of all event names registered via `.on()` and event-specific `.derive()`.
388
+ *
389
+ * Useful for introspecting which update types the middleware chain handles,
390
+ * e.g. to auto-derive `allowed_updates` for the Telegram Bot API.
391
+ *
392
+ * @example
393
+ * ```typescript
394
+ * composer.on("message", handler);
395
+ * composer.on(["callback_query", "inline_query"], handler);
396
+ * composer.registeredEvents(); // Set {"message", "callback_query", "inline_query"}
397
+ * ```
398
+ */
399
+ registeredEvents() {
400
+ const events = /* @__PURE__ */ new Set();
401
+ for (const mw of this["~"].middlewares) {
402
+ if ((mw.type === "on" || mw.type === "derive") && mw.name) {
403
+ for (const part of mw.name.split("|")) {
404
+ const eventPart = part.includes(":") ? part.split(":")[0] : part;
405
+ if (eventPart) events.add(eventPart);
406
+ }
407
+ }
408
+ }
409
+ return events;
410
+ }
386
411
  trace(handler) {
387
412
  this["~"].tracer = handler;
388
413
  this.invalidate();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gramio/composer",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "General-purpose, type-safe middleware composition library for TypeScript",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",