Skip to main content

Module transform

Module transform 

Source
Expand description

Field transforms (serverTimestamp, increment, maximum, minimum, arrayUnion, arrayRemove).

Semantics as measured on the official emulator v1.22.0 (tools/oracle/transforms.py):

  • REQUEST_TIME is the commit’s time truncated to milliseconds, the same for every field of the commit.
  • increment: a missing or non-numeric field becomes the operand; two integers add with saturation at i64::MIN / i64::MAX; otherwise both are added as doubles.
  • maximum / minimum: a missing or non-numeric field becomes the operand; equal values (3 and 3.0, -0.0 and 0.0) keep the stored value and its type; NaN on either side gives NaN.
  • arrayUnion appends operand elements not already present; arrayRemove removes every element equal to an operand. Equality is Firestore value equality (1 == 1.0, NaN equals NaN, maps and arrays compare element-wise). A field that is not an array starts empty, so arrayRemove on it leaves an empty array.
  • Transforms run after the write’s update, in order; several may target the same field, and a path through a non-map value replaces that value with a map.

Functions§

apply
Applies transform to fields and returns its transform result. Errors are the official INVALID_ARGUMENT messages.
apply_at
Applies transform at path rather than at its own field path, for a caller that maps the path first (a transform of __name__ writes the field __key__ on the official emulator).
request_time
REQUEST_TIME has millisecond precision.