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): TThe 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
- Reads the current
fnKeyfromActiveContext. - Looks up the matching
returnsentry on the registry record. - Marks the label
'resolved', fillstype = getShape(value). - Captures the label so
RpcResponse.labelreflects it. - Broadcasts a
RETURN_RESOLVEDinspector 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),Returnsimply returnsvalueunchanged — safe to use anywhere.
See also
- Return labels →
Throw— expected error paths. - Return labels →
ApiReturn— Express endpoint responses. - Return labels →
getType/getShape— runtime type / shape helpers.