jazz
jazz copied to clipboard
RFC: Add unique and appendOnly constraints to List
Motivation
Currently, lists lack built-in support for:
- Enforcing unique values (Set-like behavior while preserving order)
- 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