Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now in beta. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. |
function.definition
To look up a definition using an alias, use
|
Get or update a function’s definition, represented as a
Function
document.
Description
The definition
property is a
user-defined functions (UDFs)'s
schema, represented as a
Function
document with the FunctionDef type. The document is an FQL version of the FSL
function schema.
You access the property using an existing UDF’s name.
Definition properties
You can use dot or bracket notation to access specific fields in the definition. See Access definition properties.
Definition methods
The definition
property supports
function instance methods.
Return value
Type | Description |
---|---|
Definition for the UDF, represented as a
|
Examples
Basic example
// Get the definition for
// the `getOrCreateCart()` UDF.
getOrCreateCart.definition
{
name: "getOrCreateCart",
coll: Function,
ts: Time("2099-10-03T20:30:59.360Z"),
body: <<-END
(id) => {
let customer = Customer.byId(id)!
if (customer!.cart == null) {
Order.create({
status: "cart",
customer: Customer.byId(id),
createdAt: Time.now(),
payment: {
}
})
} else {
customer!.cart
}
}
END
}
Access definition properties
Use dot or bracket notation to access specific fields in the definition:
// Access the `body` field for
// the `getOrCreateCart()` UDF.
getOrCreateCart.definition.body
// Only returns the `body` field.
<<-END
(id) => {
let customer = Customer.byId(id)!
if (customer!.cart == null) {
Order.create({
status: "cart",
customer: Customer.byId(id),
createdAt: Time.now(),
payment: {
}
})
} else {
customer!.cart
}
}
END
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!