Skip to Content

@Cat decorator

The @Cat decorator is the class-method registration path. It writes one RegistryEntry per decorated method, wraps the method to track inspector context, and registers the owning class constructor so RPC can auto-instantiate the service when needed.

Source: sdk/ts/src/decorators/cat.ts.

Prerequisites

Add reflect-metadata once at app boot, and enable the decorator-metadata compiler flags in tsconfig.json:

{ "compilerOptions": { "experimentalDecorators": true, "emitDecoratorMetadata": true } }
import 'reflect-metadata'

Basic usage

import { Cat, Return, Throw } from '@gloocan/cat-inspector' class OrdersService { @Cat async placeOrder(userId: string, items: Item[]): Promise<OrderDto> { if (!userId) Throw('UNAUTHENTICATED', new Error('missing user')) return Return('PLACED', await this.persist(userId, items)) } private async persist(userId: string, items: Item[]): Promise<OrderDto> { // … } }

What @Cat registers

  • A stable fnKey of the form ClassName.methodName.
  • A RegistryEntry with parameter and return metadata (from TypeScript decorator metadata when enabled), return/error/API label slots, and a wrapped method that maintains inspector context for Return / Throw / ApiReturn.
  • A CatMode inferred from the parameter pattern (service vs Express-shaped handlers); Express pipelines may refine api vs api_candidate when you use registerCatPipeline.

Uncaught errors surface to inspector consumers as ERROR_THROWN with layer unexpected when they were not already labeled via Throw(...).

Auto-instantiation note

Because @Cat registers the class constructor, RPC can call new Service() on first use if no explicit registerInstance(...) was made. This assumes the constructor is safe to run automatically (ideally zero-arg, no heavy side effects). For DI-heavy services, prefer:

import { registerInstance } from '@gloocan/cat-inspector' registerInstance(new OrdersService(db, mailer))

See also