@gramio/composer 0.3.4 → 0.4.0

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
@@ -81,6 +81,7 @@ class Composer {
81
81
  errorsDefinitions: {},
82
82
  tracer: void 0,
83
83
  macros: {},
84
+ commandsMeta: /* @__PURE__ */ new Map(),
84
85
  /** Phantom type accessor — never set at runtime, used by `ContextOf<T>` */
85
86
  Out: void 0
86
87
  };
@@ -280,6 +281,11 @@ class Composer {
280
281
  }
281
282
  Object.assign(this["~"].errorsDefinitions, temp["~"].errorsDefinitions);
282
283
  this["~"].onErrors.push(...temp["~"].onErrors);
284
+ if (temp["~"].commandsMeta) {
285
+ for (const [cmd, meta] of temp["~"].commandsMeta) {
286
+ this["~"].commandsMeta.set(cmd, meta);
287
+ }
288
+ }
283
289
  for (const key of temp["~"].extended) {
284
290
  this["~"].extended.add(key);
285
291
  }
@@ -339,6 +345,11 @@ class Composer {
339
345
  Object.assign(this["~"].errorsDefinitions, other["~"].errorsDefinitions);
340
346
  Object.assign(this["~"].macros, other["~"].macros);
341
347
  this["~"].onErrors.push(...other["~"].onErrors);
348
+ if (other["~"].commandsMeta) {
349
+ for (const [cmd, meta] of other["~"].commandsMeta) {
350
+ this["~"].commandsMeta.set(cmd, meta);
351
+ }
352
+ }
342
353
  const pluginName = other["~"].name;
343
354
  const isNew = (m) => {
344
355
  if (!m.plugin) return true;
package/dist/index.d.cts CHANGED
@@ -124,6 +124,22 @@ interface ComposerOptions {
124
124
  name?: string;
125
125
  seed?: unknown;
126
126
  }
127
+ /** Shorthand strings for common BotCommandScope types */
128
+ type ScopeShorthand = "default" | "all_private_chats" | "all_group_chats" | "all_chat_administrators";
129
+ /**
130
+ * Metadata for a bot command, used by `syncCommands()` to push
131
+ * descriptions, localized names, and visibility scopes to the Telegram API.
132
+ */
133
+ interface CommandMeta<TScope = any> {
134
+ /** Command description shown in the Telegram menu (1-256 chars) */
135
+ description: string;
136
+ /** Localized descriptions keyed by IETF language tag */
137
+ locales?: Record<string, string>;
138
+ /** Where this command is visible. Default: `["default"]` */
139
+ scopes?: (TScope | ScopeShorthand)[];
140
+ /** Exclude this command from `syncCommands()`. The handler still works. @default false */
141
+ hide?: boolean;
142
+ }
127
143
 
128
144
  /**
129
145
  * Compose an array of middleware functions into a single middleware.
@@ -154,6 +170,7 @@ declare class Composer<TIn extends object = {}, TOut extends TIn = TIn, TExposed
154
170
  }>;
155
171
  tracer: TraceHandler | undefined;
156
172
  macros: Record<string, MacroDef<any, any>>;
173
+ commandsMeta: Map<string, CommandMeta<any>>;
157
174
  /** Phantom type accessor — never set at runtime, used by `ContextOf<T>` */
158
175
  Out: TOut;
159
176
  };
@@ -174,7 +191,8 @@ declare class Composer<TIn extends object = {}, TOut extends TIn = TIn, TExposed
174
191
  derive<D extends object>(handler: DeriveHandler<TOut, D>, options: {
175
192
  as: "scoped" | "global";
176
193
  }): Composer<TIn, TOut & D, TExposed & D>;
177
- guard<S extends TOut>(predicate: ((context: TOut) => context is S) | ((context: TOut) => boolean | Promise<boolean>), ...middleware: Middleware<any>[]): Composer<TIn, TOut, TExposed>;
194
+ guard<S extends TOut>(predicate: (context: TOut) => context is S): Composer<TIn, S, TExposed>;
195
+ guard(predicate: (context: TOut) => boolean | Promise<boolean>, ...middleware: Middleware<TOut>[]): Composer<TIn, TOut, TExposed>;
178
196
  branch(predicate: ((context: TOut) => boolean | Promise<boolean>) | boolean, onTrue: Middleware<TOut>, onFalse?: Middleware<TOut>): Composer<TIn, TOut, TExposed>;
179
197
  route<K extends string>(router: (context: TOut) => K | undefined | Promise<K | undefined>, builder: (route: RouteBuilder<TOut, K>) => void): Composer<TIn, TOut, TExposed>;
180
198
  route<K extends string>(router: (context: TOut) => K | undefined | Promise<K | undefined>, cases: Partial<Record<K, Middleware<TOut> | Middleware<TOut>[] | Composer<any, any, any>>>, fallback?: Middleware<TOut> | Middleware<TOut>[] | Composer<any, any, any>): Composer<TIn, TOut, TExposed>;
@@ -332,6 +350,7 @@ interface EventComposer<TBase extends object, TEventMap extends Record<string, T
332
350
  }>;
333
351
  tracer: TraceHandler | undefined;
334
352
  macros: Record<string, MacroDef<any, any>>;
353
+ commandsMeta: Map<string, CommandMeta>;
335
354
  Derives: TDerives;
336
355
  /** Phantom type accessor — never set at runtime, used by `ContextOf<T>` */
337
356
  Out: TOut;
@@ -515,4 +534,4 @@ declare const skip: Middleware<any>;
515
534
  declare const stop: Middleware<any>;
516
535
 
517
536
  export { Composer, EventQueue, buildFromOptions, compose, createComposer, defineComposerMethods, eventTypes, noopNext, skip, stop };
518
- export type { CompatibleEvents, ComposedMiddleware, ComposerLike, ComposerOptions, ContextCallback, ContextOf, DeriveFromOptions, DeriveHandler, ErrorHandler, EventComposer, EventComposerConstructor, EventContextOf, HandlerOptions, LazyFactory, MacroDef, MacroDefinitions, MacroDeriveType, MacroHooks, MacroOptionType, MaybeArray, Middleware, MiddlewareInfo, MiddlewareType, Next, RouteBuilder, RouteHandler, Scope, TraceHandler, WithCtx };
537
+ export type { CommandMeta, CompatibleEvents, ComposedMiddleware, ComposerLike, ComposerOptions, ContextCallback, ContextOf, DeriveFromOptions, DeriveHandler, ErrorHandler, EventComposer, EventComposerConstructor, EventContextOf, HandlerOptions, LazyFactory, MacroDef, MacroDefinitions, MacroDeriveType, MacroHooks, MacroOptionType, MaybeArray, Middleware, MiddlewareInfo, MiddlewareType, Next, RouteBuilder, RouteHandler, Scope, ScopeShorthand, TraceHandler, WithCtx };
package/dist/index.d.ts CHANGED
@@ -124,6 +124,22 @@ interface ComposerOptions {
124
124
  name?: string;
125
125
  seed?: unknown;
126
126
  }
127
+ /** Shorthand strings for common BotCommandScope types */
128
+ type ScopeShorthand = "default" | "all_private_chats" | "all_group_chats" | "all_chat_administrators";
129
+ /**
130
+ * Metadata for a bot command, used by `syncCommands()` to push
131
+ * descriptions, localized names, and visibility scopes to the Telegram API.
132
+ */
133
+ interface CommandMeta<TScope = any> {
134
+ /** Command description shown in the Telegram menu (1-256 chars) */
135
+ description: string;
136
+ /** Localized descriptions keyed by IETF language tag */
137
+ locales?: Record<string, string>;
138
+ /** Where this command is visible. Default: `["default"]` */
139
+ scopes?: (TScope | ScopeShorthand)[];
140
+ /** Exclude this command from `syncCommands()`. The handler still works. @default false */
141
+ hide?: boolean;
142
+ }
127
143
 
128
144
  /**
129
145
  * Compose an array of middleware functions into a single middleware.
@@ -154,6 +170,7 @@ declare class Composer<TIn extends object = {}, TOut extends TIn = TIn, TExposed
154
170
  }>;
155
171
  tracer: TraceHandler | undefined;
156
172
  macros: Record<string, MacroDef<any, any>>;
173
+ commandsMeta: Map<string, CommandMeta<any>>;
157
174
  /** Phantom type accessor — never set at runtime, used by `ContextOf<T>` */
158
175
  Out: TOut;
159
176
  };
@@ -174,7 +191,8 @@ declare class Composer<TIn extends object = {}, TOut extends TIn = TIn, TExposed
174
191
  derive<D extends object>(handler: DeriveHandler<TOut, D>, options: {
175
192
  as: "scoped" | "global";
176
193
  }): Composer<TIn, TOut & D, TExposed & D>;
177
- guard<S extends TOut>(predicate: ((context: TOut) => context is S) | ((context: TOut) => boolean | Promise<boolean>), ...middleware: Middleware<any>[]): Composer<TIn, TOut, TExposed>;
194
+ guard<S extends TOut>(predicate: (context: TOut) => context is S): Composer<TIn, S, TExposed>;
195
+ guard(predicate: (context: TOut) => boolean | Promise<boolean>, ...middleware: Middleware<TOut>[]): Composer<TIn, TOut, TExposed>;
178
196
  branch(predicate: ((context: TOut) => boolean | Promise<boolean>) | boolean, onTrue: Middleware<TOut>, onFalse?: Middleware<TOut>): Composer<TIn, TOut, TExposed>;
179
197
  route<K extends string>(router: (context: TOut) => K | undefined | Promise<K | undefined>, builder: (route: RouteBuilder<TOut, K>) => void): Composer<TIn, TOut, TExposed>;
180
198
  route<K extends string>(router: (context: TOut) => K | undefined | Promise<K | undefined>, cases: Partial<Record<K, Middleware<TOut> | Middleware<TOut>[] | Composer<any, any, any>>>, fallback?: Middleware<TOut> | Middleware<TOut>[] | Composer<any, any, any>): Composer<TIn, TOut, TExposed>;
@@ -332,6 +350,7 @@ interface EventComposer<TBase extends object, TEventMap extends Record<string, T
332
350
  }>;
333
351
  tracer: TraceHandler | undefined;
334
352
  macros: Record<string, MacroDef<any, any>>;
353
+ commandsMeta: Map<string, CommandMeta>;
335
354
  Derives: TDerives;
336
355
  /** Phantom type accessor — never set at runtime, used by `ContextOf<T>` */
337
356
  Out: TOut;
@@ -515,4 +534,4 @@ declare const skip: Middleware<any>;
515
534
  declare const stop: Middleware<any>;
516
535
 
517
536
  export { Composer, EventQueue, buildFromOptions, compose, createComposer, defineComposerMethods, eventTypes, noopNext, skip, stop };
518
- export type { CompatibleEvents, ComposedMiddleware, ComposerLike, ComposerOptions, ContextCallback, ContextOf, DeriveFromOptions, DeriveHandler, ErrorHandler, EventComposer, EventComposerConstructor, EventContextOf, HandlerOptions, LazyFactory, MacroDef, MacroDefinitions, MacroDeriveType, MacroHooks, MacroOptionType, MaybeArray, Middleware, MiddlewareInfo, MiddlewareType, Next, RouteBuilder, RouteHandler, Scope, TraceHandler, WithCtx };
537
+ export type { CommandMeta, CompatibleEvents, ComposedMiddleware, ComposerLike, ComposerOptions, ContextCallback, ContextOf, DeriveFromOptions, DeriveHandler, ErrorHandler, EventComposer, EventComposerConstructor, EventContextOf, HandlerOptions, LazyFactory, MacroDef, MacroDefinitions, MacroDeriveType, MacroHooks, MacroOptionType, MaybeArray, Middleware, MiddlewareInfo, MiddlewareType, Next, RouteBuilder, RouteHandler, Scope, ScopeShorthand, TraceHandler, WithCtx };
package/dist/index.js CHANGED
@@ -78,6 +78,7 @@ class Composer {
78
78
  errorsDefinitions: {},
79
79
  tracer: void 0,
80
80
  macros: {},
81
+ commandsMeta: /* @__PURE__ */ new Map(),
81
82
  /** Phantom type accessor — never set at runtime, used by `ContextOf<T>` */
82
83
  Out: void 0
83
84
  };
@@ -277,6 +278,11 @@ class Composer {
277
278
  }
278
279
  Object.assign(this["~"].errorsDefinitions, temp["~"].errorsDefinitions);
279
280
  this["~"].onErrors.push(...temp["~"].onErrors);
281
+ if (temp["~"].commandsMeta) {
282
+ for (const [cmd, meta] of temp["~"].commandsMeta) {
283
+ this["~"].commandsMeta.set(cmd, meta);
284
+ }
285
+ }
280
286
  for (const key of temp["~"].extended) {
281
287
  this["~"].extended.add(key);
282
288
  }
@@ -336,6 +342,11 @@ class Composer {
336
342
  Object.assign(this["~"].errorsDefinitions, other["~"].errorsDefinitions);
337
343
  Object.assign(this["~"].macros, other["~"].macros);
338
344
  this["~"].onErrors.push(...other["~"].onErrors);
345
+ if (other["~"].commandsMeta) {
346
+ for (const [cmd, meta] of other["~"].commandsMeta) {
347
+ this["~"].commandsMeta.set(cmd, meta);
348
+ }
349
+ }
339
350
  const pluginName = other["~"].name;
340
351
  const isNew = (m) => {
341
352
  if (!m.plugin) return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gramio/composer",
3
- "version": "0.3.4",
3
+ "version": "0.4.0",
4
4
  "description": "General-purpose, type-safe middleware composition library for TypeScript",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",