@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
fnKeyof the formClassName.methodName. - A
RegistryEntrywith parameter and return metadata (from TypeScript decorator metadata when enabled), return/error/API label slots, and a wrapped method that maintains inspector context forReturn/Throw/ApiReturn. - A
CatModeinferred from the parameter pattern (servicevs Express-shaped handlers); Express pipelines may refineapivsapi_candidatewhen you useregisterCatPipeline.
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
- Registration →
cat()function — functional equivalent for plain functions. - Registration →
catModule()— register a whole module of functions in one call. - Registration →
CatClass/CatService— class-level decorator (constructor-only). - Registration →
registerInstance— explicit instance registration. - Return labels →
Return— label your return paths.