-
Notifications
You must be signed in to change notification settings - Fork 0
serialize
awekrx edited this page May 29, 2026
·
1 revision
import { serialize } from '@dev-suite/decorators/serialize'
method
Transform method response into stable DTO/transport shape.
- Inline mapping in every return path
- Scattered serializer helper calls
class UserService {
async getUser(id: string) {
const user = await this.repo.get(id);
return {
id: user.id,
fullName: user.firstName + ' ' + user.lastName,
createdAt: user.createdAt.toISOString(),
};
}
}import { serialize } from '@dev-suite/decorators/serialize';
class UserService {
@serialize({
serializer: (user: UserEntity) => ({
id: user.id,
fullName: user.firstName + ' ' + user.lastName,
createdAt: user.createdAt.toISOString(),
}),
})
async getUser(id: string) {
return this.repo.get(id);
}
}- Serializer policy is explicit and testable in one place.
- Domain retrieval remains separate from transport shape.
class ExportService {
async file(id: string) {
const file = await this.storage.fetch(id);
return {
id: file.id,
size: file.buffer.length,
checksum: file.checksum,
};
}
}import { serialize } from '@dev-suite/decorators/serialize';
class ExportService {
@serialize({ serializer: (file: StoredFile) => ({ id: file.id, size: file.buffer.length, checksum: file.checksum }) })
async file(id: string) {
return this.storage.fetch(id);
}
}- Supports multiple output contracts without method duplication.
- Avoids repeated DTO mapping code.