Skip to main content

Op

Enum Op 

Source
pub enum Op {
    Increment(f64),
    Add(Vec<ParseValue>),
    AddUnique(Vec<ParseValue>),
    Remove(Vec<ParseValue>),
    SetOnInsert(ParseValue),
    Delete,
    AddRelation(Vec<ParseValue>),
    RemoveRelation(Vec<ParseValue>),
    Batch(Vec<Op>),
}
Expand description

A field operation.

Not #[non_exhaustive], for the reason given on ParseValue: a new operation must break every write path that applies one, rather than falling into a wildcard arm that silently ignores it.

Variants§

§

Increment(f64)

{"__op":"Increment","amount":n}. Negative amounts decrement; there is no separate op.

§

Add(Vec<ParseValue>)

{"__op":"Add","objects":[...]}. Appends, duplicates allowed.

§

AddUnique(Vec<ParseValue>)

{"__op":"AddUnique","objects":[...]}. Appends only values not already present.

§

Remove(Vec<ParseValue>)

{"__op":"Remove","objects":[...]}. Removes every occurrence.

§

SetOnInsert(ParseValue)

{"__op":"SetOnInsert","amount":v}. Sets the field only if the write inserts a row.

Note the key: amount, not objects and not value, and it carries an arbitrary value rather than a number despite the name (MongoTransform.js:993-998). There is no type check on it anywhere upstream, so there is none here.

§

Delete

{"__op":"Delete"}. Unsets the field.

§

AddRelation(Vec<ParseValue>)

{"__op":"AddRelation","objects":[pointers]}

§

RemoveRelation(Vec<ParseValue>)

{"__op":"RemoveRelation","objects":[pointers]}

§

Batch(Vec<Op>)

{"__op":"Batch","ops":[...]}. Upstream only ever produces a batch of relation ops, but the decoder does not enforce that, so neither does this.

Implementations§

Source§

impl Op

Source

pub fn classify(value: &Json) -> Result<Option<Op>, ParseError>

Decode an {"__op":...} object on the update path.

Returns Ok(None) when the value is not an op at all, so a caller can try this before falling back to crate::decode::classify without treating “not an op” as an error.

Source

pub fn classify_with( value: &Json, path: OpPath, ) -> Result<Option<Op>, ParseError>

Decode an {"__op":...} object, with the path that decides one error message.

Source

pub fn flatten_for_create(&self) -> Result<Option<ParseValue>, ParseError>

What this op collapses to on a create, per flattenUpdateOperatorsForCreate (DatabaseController.js:323-365).

Ok(None) means the key is removed from the row entirely, which is what Delete does. Two results are counter-intuitive and both are upstream’s: Remove yields an empty array rather than removing anything, and the relation ops are not handled here at all because collectRelationUpdates has already stripped them out.

Source

pub fn name(&self) -> &'static str

The __op string, for the error messages that quote it back.

Source

pub fn echoes_result(&self) -> bool

Does the update response echo this op’s resulting value back to the client?

Exactly the five ops in _sanitizeDatabaseResult’s allow-list (DatabaseController.js:2140). Delete is not one of them, which is why deleting a field produces {updatedAt} and nothing else.

Trait Implementations§

Source§

impl Clone for Op

Source§

fn clone(&self) -> Op

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Op

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Op

§

impl RefUnwindSafe for Op

§

impl Send for Op

§

impl Sync for Op

§

impl Unpin for Op

§

impl UnsafeUnpin for Op

§

impl UnwindSafe for Op

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V