import { Keys, Partial } from "./common"; import { FieldLevelQueryOperators } from "./filter"; export interface PushModifiers { /** * Modifies the $push and $addToSet operators to append multiple items for array updates. * { ($addToSet|$push): { : { $each: [ , ... ] } } } */ $each: V[]; /** * Modifies the $push operator to limit the size of updated arrays. * {$push: {: {$each: [ , , ... ],$slice: }}} */ $slice?: number; /** * The $sort modifier orders the elements of an array during a $push operation. To use the $sort modifier, it must appear with the $each modifier. * You can pass an empty array [] to the $each modifier such that only the $sort modifier has an effect. * {$push: {: {$each: [ , , ... ],$sort: }}} */ $sort?: 1 | -1 | Partial<{ [Key in Keys]: 1 | -1; }>; /** * The $position modifier specifies the location in the array at which the $push operator insert elements. Without the $position modifier, the $push operator inserts elements to the end of the array. */ $position?: number; } export interface UpsertOperators extends UpdateOperators { /** * If an update operation with upsert: true results in an insert of a document, then $setOnInsert assigns the specified values to the fields in the document. If the update operation does not result in an insert, $setOnInsert does nothing. * { $setOnInsert: { : , ... } }, * */ $setOnInsert: S; } export interface UpdateOperators { /** * Increments the value of the field by the specified amount. * { $inc: { : , : , ... } } */ $inc?: Partial<{ [Key in Keys]: S[Key] extends number ? number : never; }>; /** * Multiplies the value of the field by the specified amount. * { $mul: { field: } } */ $mul?: Partial<{ [Key in Keys]: S[Key] extends number ? number : never; }>; /** * Renames a field. * {$rename: { : , : , ... } } */ $rename?: UpdateOperatorsOnSchema; /** * Sets the value of a field in a document. * { $set: { : , ... } } */ $set?: Partial; /** * Removes the specified field from a document. * { $unset: { : "", ... } } */ $unset?: Partial<{ [key in Keys]: ""; } & { $deep: { [key: string]: ""; }; }>; /** * Only updates the field if the specified value is less than the existing field value. * { $min: { : , ... } } */ $min?: Partial<{ [Key in Keys]: S[Key] extends number ? S[Key] : S[Key] extends Date ? S[Key] : never; }>; /** * Only updates the field if the specified value is greater than the existing field value. * { $max: { : , ... } } */ $max?: Partial<{ [Key in Keys]: S[Key] extends number ? S[Key] : S[Key] extends Date ? S[Key] : never; }>; /** * Sets the value of a field to current date, either as a Date or a Timestamp. * { $currentDate: { : , ... } } */ $currentDate?: Partial<{ [Key in Keys]: S[Key] extends Date ? true | { $type: "date"; } : S[Key] extends number ? { $type: "timestamp"; } : never; }>; /** * Adds elements to an array only if they do not already exist in the set. * { $addToSet: { : , ... } } */ $addToSet?: Partial<{ [Key in Keys]: S[Key] extends Array ? U | { $each: U[]; } : never; }>; /** * The $pop operator removes the first or last element of an array. Pass $pop a value of -1 to remove the first element of an array and 1 to remove the last element in an array. * { $pop: { : <-1 | 1>, ... } } */ $pop?: Partial<{ [Key in Keys]: S[Key] extends Array ? -1 | 1 : never; }>; /** * Removes all array elements that match a specified query. * { $pull: { : , : , ... } } */ $pull?: Partial<{ [Key in Keys]: S[Key] extends Array ? Partial | FieldLevelQueryOperators : never; }>; /** * The $pullAll operator removes all instances of the specified values from an existing array. Unlike the $pull operator that removes elements by specifying a query, $pullAll removes elements that match the listed values. * { $pullAll: { : [ , ... ], ... } } */ $pullAll?: Partial<{ [Key in Keys]: S[Key] extends Array ? U[] : never; }>; /** * The $push operator appends a specified value to an array. * { $push: { : , ... } } */ $push?: Partial<{ [Key in Keys]: S[Key] extends Array ? U | PushModifiers : never; }>; } export declare type UpdateOperatorsOnSchema = Partial<{ [key in Keys]: V; }>;