jazz icon indicating copy to clipboard operation
jazz copied to clipboard

RFC: Add unique and appendOnly constraints to List

Open gdorsi opened this issue 10 months ago • 0 comments

Motivation

Currently, lists lack built-in support for:

  1. Enforcing unique values (Set-like behavior while preserving order)
  2. Append-only operations (preventing value removal)

These features are frequently needed when working with references and in scenarios requiring immutable history.
While CoFeed can be used for append-only operations, its API isn't optimized for this use case.

Proposed Solution

Introduce configuration options for Lists through a constraints system. This would allow developers to specify list behavior while maintaining the familiar Array-like interface of List.

Example implementation:

class MyAppendOnlyUniqueList extends List.Of(co.ref(Item)) {
  constraints = {
     unique: true,
     appendOnly: true,
  }
}

Note: defining constraints for lists will look nicer in the Zod-like schema API

gdorsi avatar Feb 21 '25 17:02 gdorsi