✨ Add batch push endpoint for synced collections

POST /api/sync/push applies up to 500 client changes of a signed-in
user in one transaction. Every change is answered with ok, stale,
forbidden or readonly, so the client can reconcile its local state
with the server state.

closed_days and closed_weeks are answered as readonly because only
the server computes them. The last remaining settings row of a user
cannot be deleted either; such a change is answered as stale, which
clients already treat as "server wins".
This commit is contained in:
2026-11-29 17:03:42 +00:00
parent a2507d22d3
commit f63fe1b549
3 changed files with 212 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
package syncapi
import (
"github.com/pocketbase/pocketbase/core"
"github.com/wotra/wotra/internal/collections"
)
func RegisterHooks(app core.App) {
app.OnRecordCreateRequest(collections.Synced...).BindFunc(func(e *core.RecordRequestEvent) error {
if e.Auth != nil && !e.HasSuperuserAuth() {
e.Record.Set("owner", e.Auth.Id)
}
e.Record.Set("rev", 1)
return e.Next()
})
app.OnRecordUpdateRequest(collections.Synced...).BindFunc(func(e *core.RecordRequestEvent) error {
orig := e.Record.Original()
e.Record.Set("owner", orig.GetString("owner"))
e.Record.Set("rev", orig.GetInt("rev")+1)
return e.Next()
})
}