| name | build-transformer |
| description | Build t7m transformers for API output transformation. Use when creating new transformers, adding includes, configuring cache, or wiring transformers into Hono or Elysia routes. |
Building a t7m Transformer
t7m is a TypeScript transformer layer for APIs. One class per model controls what gets exposed, loads includes in parallel, and caches repeated calls.
Quick Start
import { AbstractTransformer } from 't7m'
interface User {
id: number
name: string
email: string
password: string
}
interface PublicUser {
name: string
email: string
}
class UserTransformer extends AbstractTransformer<User, PublicUser> {
data(input: User): PublicUser {
return {
name: input.name,
email: input.email,
}
}
}
const transformer = new UserTransformer()
const result = await transformer.transform({ input: user })
Critical Rules
These are the most common mistakes. Follow them exactly.
All transform methods take a params OBJECT
await transformer.transform({ input: user })
await transformer.transform({ input: user, includes: ['posts'], props: { db } })
await transformer.transform(user)
Includes only work with optional output properties
type Output = {
name: string
avatar?: string
}
Cache uses .call(), not .get()
const user = await this.cache.userProfile.call(input.userId)
this.cache.userProfile.get(input.userId)
transformers is a Record, not an array
transformers = { author: this.authorTransformer }
transformers = [this.authorTransformer]
clearCacheOnTransform is on AbstractTransformer, not Cache
constructor() {
super({ clearCacheOnTransform: false })
}
new Cache(fn, { clearCacheOnTransform: false })
Detailed Patterns
- For includes, props, cache, nested transformers, and access modifiers, see reference.md
- For concurrency control (throttling external API calls), see reference.md — Concurrency Control
- For Hono middleware integration and route patterns, see hono.md
- For Elysia plugin integration and route patterns, see elysia.md