# Storage and projections

## Storage is a facet of the schema

There is no storage registry. Portable storage meaning belongs to the schema it describes:

```ts
const stored = users.schemas({
  User: schema({
    id: field(values.UserId),
    email: field(values.Email),
  }).facets({
    storage: storage("users")
      .primaryKey("id")
      .indexes({ fields: ["email"], unique: true }),
  }),
});
```

A concrete stored schema needs a storage name. An abstract schema may contribute inherited storage rules without one.

## Projections derive shapes

```ts
users.schemas({
  UserRead: schema({}).projection(
    projection(stored.User)
      .purpose("read")
      .pick("id", "email")
      .rename({ email: "contactEmail" })
      .usage({ email: { optional: true } }),
  ),
});
```

| Method                                           | Effect                                                 |
| ------------------------------------------------ | ------------------------------------------------------ |
| `.pick(...)`                                     | Keep only these effective fields                       |
| `.rename({ from: "to" })`                        | Rename a field in the derived shape                    |
| `.usage({ field: { optional: true } })`          | Change presence in this shape                          |
| `.read()` / `.create()` / `.edit()` / `.query()` | Set the purpose (also available as `.purpose("read")`) |

Selectors are an authoring convenience. The compiler resolves them against the source schema's effective fields and emits explicit canonical `projection.fields`, so packs never guess.

## Why this matters

- One change to the stored schema updates every derived shape.
- Packs generating DTOs, entities and forms stay in agreement because they read the same fields.
- Purpose-aware projections let a pack drop system fields from `create` shapes without special cases.
