# Bug 3045: Custom mutators

- Status: closed
- Project: Zero
- Creator: @aboodman
- Labels: zero
- Created: 2024-10-10T00:51:40Z
- Modified: 2025-04-07T03:31:51Z
- Reactions: ❤️ ×5 (Kbs56, djm, lukeshay, mathieupost, warrenbhw) · 🎁 ×4 (AceroM, crvouga, erikmunson, saturnonearth) · 🎄 ×4 (AceroM, crvouga, erikmunson, warrenbhw) · 🎅 ×4 (AceroM, arjansunar, erikmunson, malakhov-dmitrii) · 💦 ×1 (saturnonearth) · 🙏 ×22 (AceroM, AkshayPathak, Exerosis, Nuhvi, RobertoSnap, alamothe, amosbastian, angelcervera, cbnsndwch, citriqa, crvouga, davemaier, erikmunson, homanizer, jackfraser70, kschrader, lukeshay, mod08, nivekithan, ouhndelof, shobokshy, vasyaqwe) · 🤚 ×31 (0xcadams, AceroM, AkshayPathak, Cmion, FredrikZeiner, MauruschatM, RobertoSnap, SabBits, SickanK, a-poor, amosbastian, ashot, cbnsndwch, cloleb, crvouga, denkasyanov, devtestersweden, elledienne, erikmunson, jackfraser70, jasonsilberman, jorroll, lazarandrei2, nivekithan, saturnonearth, sherwinyu, shobokshy, tmm, vasyaqwe, warrenbhw, zhm)
- URL: https://bugs.rocicorp.dev/p/zero/issue/3045

## Description

This has got to be one of the most common feature requests right now:

https://www.notion.so/replicache/Introducing-Zero-8ce1b1f184aa4a9088a9f76e1b8db003?pvs=4#1350c2d5001a4bcb88ee8d3fdb7a125f

Probably should have been prioritized higher for alpha, whoops!

## Must Have

* [x] Spruce up API details around registering mutators and auth (https://github.com/rocicorp/mono/pull/4103)
* [x] I think I saw that when a mutator name wasn't defined, the system keeps trying to send forever. It should skip the mutation.
* [x] Notifications should not block db transaction (https://github.com/rocicorp/mono/pull/4103)
* [x] Fix underscores in filenames in zbugs (https://github.com/rocicorp/mono/pull/4113)
* [x] Fix datetime conversion in z2s (https://github.com/rocicorp/mono/pull/4110) 
* [x] Support for `enumeration` and `uuid` types (wip - greg)
* [x] Print out `ServerError` messages to console.error and also `console.warn` in `zero-cache`
* [x] Weird behavior when push endpoint doesn't wait correctly: https://bugs.rocicorp.dev/issue/3695 (cannot repro so far - matt and aa to try and repro)
* [x] Initial docs (aa)

## Follow-On

* [ ] There needs to be validation for input args to mutators (https://bugs.rocicorp.dev/issue/3694)
* [ ] Email notifications in zbugs
* [ ] crdt for bug descriptions in zbugs
* [x] Return type of mutators should be {server: Promise<T>} not Promise<server: Promise<T>}. (https://github.com/rocicorp/mono/pull/4148)
* [ ] Successful / skipped mutation responses should be transactional with poke (https://bugs.rocicorp.dev/issue/3659)
* [ ] API server errors that do not cause the mutation to be skipped should cause the client to retry (only OOO mutation, protocol-verison and schema-version errors force a retry. fetch failures from zero-cache to the API server should cause a retry too)
* [ ] Allow mutators to return custom data
* [ ] Split push into its own websocket connection

## Comments (8)

### @ashot — 2024-12-16T19:16:50Z

please :)

### @jasonsilberman — 2024-12-25T20:42:56Z

+1 on having support for `onError` callbacks for mutators like mentioned in this Discord thread: https://discord.com/channels/830183651022471199/1288232858795769917/1319584057276891237

### @RobertoSnap — 2025-01-10T08:10:16Z

Need!

Reactions: 👆️ ×3 (AceroM, jackfraser70, julianarchila) · 🫡 ×2 (aboodman, vasyaqwe)

### @jackfraser70 — 2025-01-17T11:51:32Z

Any idea for a timeline on this feature @aboodman?

### @aboodman — 2025-01-30T00:56:06Z

We went around a bit about how to do this well w/o losing the DX we love from Zero. Found a design we're excited about and have restarted the work.

See design: https://www.notion.so/replicache/Custom-Mutators-1353bed8954580f09875f1484e7ce7d4

~Hate to put a number on it but hopefully end of february?~

Looks like beginning of march now! Sorry!

Reactions: ❤️ ×1 (djm) · 👍️ ×2 (jorroll, miguelrk) · 😀 ×2 (citriqa, miguelrk) · 🥳 ×3 (jackfraser70, miguelrk, ouhndelof)

### @aboodman — 2025-02-08T22:32:47Z

Putting workarounds here so I don't have to keep retyping them in Discord:

1. Monitor database for row changes and send notifications that way. Can monitor database many ways: supabase functions if you're on supabase, raw pg triggers, or even use `zero-client` within a node process or cloudflare worker (https://github.com/rocicorp/hello-zero-do).

2. Send a classic query from client to your server telling it to send notifications. This is lame, but it's temporary until custom mutators.

### @aboodman — 2025-03-26T07:06:20Z

> Looks like beginning of march now! Sorry!

lol 😬

Reactions: 😅 ×2 (aboodman, moeamaya)

### @aboodman — 2025-04-03T06:47:48Z

Done: https://zero.rocicorp.dev/docs/custom-mutators

Reactions: 🎉 ×1 (jorroll)
