Skip to Content

catModule(moduleName, fns, perMethodOptions?)

Registers every enumerable function on fns as ${moduleName}.${methodName}, sharing the same wrapper behavior as cat.

Pass an object of named methods (method shorthand is fine—the SDK registers each key as ModuleName.methodName):

import { catModule, Return, Throw } from '@gloocan/cat-inspector' export type ShipmentPriority = 'economy' | 'express' | 'overnight' export const WorkflowCatalog = catModule( 'WorkflowCatalog', { buildShipmentTimeline( originCountry: string, destinationCountry: string, priorityTier: ShipmentPriority, ) { const o = originCountry.trim().toUpperCase() const d = destinationCountry.trim().toUpperCase() if (!o || !d) { Throw('EMPTY_COUNTRY', new Error('origin and destination are required')) } return Return('TIMELINE', { originCountry: o, destinationCountry: d, priorityTier, }) }, async aggregateChannelMetrics( channels: { name: string; impressions: number; clicks: number }[], ) { // …business logic… return Return('CHANNEL_ROLLUP', { winners: channels.map((c) => c.name) }) }, }, { buildShipmentTimeline: { declaredReturn: 'ShipmentTimeline' }, aggregateChannelMetrics: { paramsJsonSchema: { /* tuple over args */ } }, }, ) // fnKeys → WorkflowCatalog.buildShipmentTimeline, WorkflowCatalog.aggregateChannelMetrics

Arrow properties (refund: async (id) => …) work too; method shorthand is often clearer for multi-line handlers.

Signature

function catModule<T extends Record<string, (...args: any[]) => any>>( moduleName: string, fns: T, options?: Record< string, Pick<CatFunctionOptions, 'params' | 'declaredReturn' | 'paramsJsonSchema' | 'returnJsonSchema'> >, ): T

The third argument is keyed by method name (object key in fns). Only params, declaredReturn, paramsJsonSchema, and returnJsonSchema are supported per method—not route / method (set those per function with individual cat calls if needed).

Duplicate keys

Each generated fnKey must be new; a duplicate throws the same way as cat.

See also