1import { Schema } from "effect"
2import { Model } from "effect/schema"
3
4export const UserId = Schema.String.pipe(Schema.brand("UserId"))
5export type UserId = typeof UserId.Type
6
7// `Model.Class` derives variants for the database (`User`, `User.insert`,
8// `User.update`) and the JSON API (`User.json`, `User.jsonCreate`,
9// `User.jsonUpdate`) from a single field declaration.
10export class User extends Model.Class<User>("User")({
11 // A UUID v4 primary key generated by the application on insert. It is
12 // excluded from the `jsonCreate` / `jsonUpdate` variants, so API clients can
13 // never set it.
14 id: Model.UuidV4Insert(UserId),
15 name: Schema.String,
16 email: Schema.String,
17 // Timestamps are managed by the model: set on insert, refreshed on update,
18 // and also excluded from the JSON create / update variants.
19 createdAt: Model.DateTimeInsert,
20 updatedAt: Model.DateTimeUpdate
21}) {}