Skip to content

Entity

type Entity<E> = ZodOutput<E["schema"]>;

Utility type to derive the type of a DynamoEntity’s schema.

This is the Zod output type of a Zod schema (the type after a codec has been applied). It is the equivalent of z.infer<typeof entity.schema> or z.output<typeof entity.schema>.

E extends DynamoEntity<any>

import { DynamoTable, DynamoEntity, type Entity } from 'dynamo-document-builder';
import { z } from 'zod';
const table = new DynamoTable({
tableName: 'ExampleTable',
documentClient,
});
const userEntity = new DynamoEntity({
table,
schema: z.object({
id: z.string(),
name: z.string(),
age: z.number().optional(),
}),
partitionKey: user => key('USER', user.id),
sortKey: user => 'USER',
});
type User = Entity<typeof userEntity>;