add a built-in function called Omit
. What it does is return the object back BUT removes specified keys,
So if you have:
Get(
Match(
Index("userByEmail"),
"user@email.com"
)
)
Which returned:
{
// ... other meta values
data: {
email: "user@email.com",
name: "Juan Dela Cruz",
hashedPassword: "asdasd12312radgadgvadfasfr12esa" // pretend it's a hashed string :)
}
}
Applying the omit function like so:
Omit(
["hashedPassword"],
Select(
["data"],
Get(
Match(
Index("userByEmail"),
"user@email.com"
)
)
)
);
Should return
{
email: "user@email.com",
name: "Juan Dela Cruz"
}
furthermore, the first argument can accept a 2d array, like so:
Omit(
[
["data", "hashedPassword"] // remove the data.hashedPassword from the object
],
Get(
Match(
Index("userByEmail"),
"user@email.com"
)
)
);
Resulting to the following:
{
// ... other meta values
data: {
email: "user@email.com",
name: "Juan Dela Cruz"
}
}
So to summarize, the function would be:
Omit(paths, fromObject)
-
Paths
: Array of paths to the keys to be omitted. -
fromObject
: Target object to derive the result from.
Omit
must be a pure function, that is, it doesn’t mutate the fromObject
parameter, so you can do:
Let(
{
result: Select(
["data"],
Get(
Match(
Index("userByEmail"),
"user@email.com"
)
)
),
removedResult: Omit(
[
["data", "hashedPassword"] // remove the data.hashedPassword from the object
],
Var("result")
)
},
// rest of the code
)
and Var("result")
should still be the original object prior to Omit
call.