JMAP Registry API implementation - part 4

This commit is contained in:
mdecimus
2026-02-26 18:11:41 +01:00
parent f16e737221
commit e24b595a16
44 changed files with 1562 additions and 1718 deletions

View File

@@ -208,6 +208,24 @@ impl RegistryJsonPatch for f64 {
}
}
impl RegistryJsonPatch for trc::Key {
fn patch(
&mut self,
pointer: JsonPointerPatch<'_>,
value: super::JmapValue<'_>,
) -> Result<(), PatchError> {
if let Some(new_value) = value.as_str().and_then(|v| trc::Key::try_parse(v.as_ref())) {
*self = new_value;
pointer.assert_eof()
} else {
Err(PatchError::new(
pointer,
format!("Invalid value {:?} for enum type {:?}.", value, self),
))
}
}
}
impl<T: EnumImpl> RegistryJsonEnumPatch for T {
fn patch(
&mut self,

View File

@@ -100,3 +100,9 @@ impl<V: IntoValue> IntoValue for Vec<V> {
JmapValue::Array(array)
}
}
impl IntoValue for trc::Key {
fn into_value(self) -> JmapValue<'static> {
JmapValue::Str(self.name().into())
}
}

View File

@@ -250,3 +250,13 @@ where
Some(map)
}
}
impl Pickle for trc::Key {
fn pickle(&self, out: &mut Vec<u8>) {
self.code().pickle(out);
}
fn unpickle(stream: &mut PickledStream<'_>) -> Option<Self> {
u64::unpickle(stream).and_then(Self::from_code)
}
}

View File

@@ -16,17 +16,14 @@ use types::id::Id;
pub enum IndexKey<'x> {
Unique {
property: Property,
value: IndexValue<'x>,
value_1: IndexValue<'x>,
value_2: IndexValue<'x>,
global: bool,
},
Search {
property: Property,
value: IndexValue<'x>,
},
Global {
property: Property,
value_1: IndexValue<'x>,
value_2: IndexValue<'x>,
},
ForeignKey {
object_id: ObjectId,
type_filter: IndexValue<'x>,
@@ -52,17 +49,10 @@ pub enum IndexValue<'x> {
#[derive(Debug, Default)]
pub struct IndexBuilder<'x> {
pub object: Option<ObjectType>,
pub keys: AHashSet<IndexKey<'x>>,
}
impl<'x> IndexBuilder<'x> {
pub fn object(&mut self, object: ObjectType) {
if self.object.is_none() {
self.object = Some(object);
}
}
pub fn typ(&mut self, typ: u16) {
self.keys.insert(IndexKey::Search {
property: Property::Type,
@@ -73,7 +63,9 @@ impl<'x> IndexBuilder<'x> {
pub fn unique(&mut self, property: Property, value: impl Into<IndexValue<'x>>) {
self.keys.insert(IndexKey::Unique {
property,
value: value.into(),
value_1: value.into(),
value_2: IndexValue::None,
global: false,
});
}
@@ -106,24 +98,26 @@ impl<'x> IndexBuilder<'x> {
}
}
pub fn global(&mut self, property: Property, value: impl Into<IndexValue<'x>>) {
self.keys.insert(IndexKey::Global {
pub fn unique_global(&mut self, property: Property, value: impl Into<IndexValue<'x>>) {
self.keys.insert(IndexKey::Unique {
property,
value_1: value.into(),
value_2: IndexValue::None,
global: true,
});
}
pub fn composite(
pub fn unique_global_composite(
&mut self,
property: Property,
value: impl Into<IndexValue<'x>>,
composite: impl Into<IndexValue<'x>>,
) {
self.keys.insert(IndexKey::Global {
self.keys.insert(IndexKey::Unique {
property,
value_1: value.into(),
value_2: composite.into(),
global: true,
});
}

View File

@@ -16,6 +16,8 @@ impl Task {
Task::CalendarAlarmNotification(task) => task.status = status,
Task::CalendarItipMessage(task) => task.status = status,
Task::MergeThreads(task) => task.status = status,
Task::DmarcReport(task) => task.status = status,
Task::TlsReport(task) => task.status = status,
}
}
@@ -28,6 +30,8 @@ impl Task {
Task::CalendarAlarmNotification(task) => &task.status,
Task::CalendarItipMessage(task) => &task.status,
Task::MergeThreads(task) => &task.status,
Task::DmarcReport(task) => &task.status,
Task::TlsReport(task) => &task.status,
}
}