Skip to Content

Return(label, value)

Return is a runtime no-op for business logic — it just stamps metadata and emits a RETURN_RESOLVED inspector event tied to the currently active fnKey.

Signature

function Return<L extends string, T>(label: L, value: T): T

The inferred return type is T so the catalog’s declaredReturn matches getType(value) rather than picking up the brand.

Usage

import { Cat, Return } from '@gloocan/cat-inspector' class UserService { @Cat async findById(id: string): Promise<UserDto | null> { const row = await this.repo.findOne(id) if (!row) return Return('NOT_FOUND', null) return Return('FOUND', this.toDto(row)) } }

What happens at runtime

  1. Reads the current fnKey from ActiveContext.
  2. Looks up the matching returns entry on the registry record.
  3. Marks the label 'resolved', fills type = getShape(value).
  4. Captures the label so RpcResponse.label reflects it.
  5. Broadcasts a RETURN_RESOLVED inspector event.

Notes

  • Pre-populated labels come from a regex scan of the function body at registration time, so Return('FOUND', …) works even if the AST scan has not run.
  • Outside an ActiveContext (i.e. called directly, not from inside a @Cat/cat() function), Return simply returns value unchanged — safe to use anywhere.

See also