---
title: "Shared functions (FunctionDecl)"
description: "Generated from the doc schema (CatalogDocSchema, @canonify/kernel-catalog/doc): each field’s type, default and description are the schema’s own, and each example is a bundle file that readBundle…"
order: 7
id: "model/function"
---

# Shared functions (FunctionDecl)

Generated from the doc schema (`CatalogDocSchema`, @canonify/kernel-catalog/doc): each field’s type, default and description are the schema’s own, and each example is a bundle file that readBundle decodes. A field’s Example is its value in one of those examples.

## FunctionDecl {#functiondecl}

A shared function: a CX value function or a runtime effects function (C34).

The `functions` slot of the doc holds these, keyed by id. In a bundle each is one file, `functions/<name>.json`, named by its `name`, which the file then leaves out.

Type: [ValueFunctionDecl](function.md#valuefunctiondecl) | [EffectsFunctionDecl](function.md#effectsfunctiondecl).

## ValueFunctionDecl {#valuefunctiondecl}

A shared value function.

| Field | Type | Required | Default | Example | Description |
|---|---|---|---|---|---|
| `kind` | `"value"` | no | `"value"` | `"value"` | A value function (the default kind): its body is one CX expression. |
| `id` | [FnId](shapes.md#fnid) | yes (propose assigns it; a new declaration leaves it out) | — | — | A shared function id (`fn_…`); renames keep it. |
| `name` | [Ident](shapes.md#ident) | yes | — | `"vat"` | The function name CX calls it by. |
| `label` | [Text](shapes.md#text) | no | — | `"VAT"` | The words shown for the function. |
| `params` | [ParamDecl](function.md#paramdecl)[] | yes | — | `[{"name":"amount","type":"money<DKK>"}]` | The parameters, in call order. |
| `returns` | string | no | — | `"money<DKK>"` | The asserted return type as typeref text; checked against the inferred type. |
| `body` | [Expr](shapes.md#expr) | yes | — | `"amount * 0.25"` | The CX expression it returns. |

`functions/vat.json`

```json
{
  "kind": "value",
  "label": "VAT",
  "params": [{ "name": "amount", "type": "money<DKK>" }],
  "returns": "money<DKK>",
  "body": "amount * 0.25"
}
```

## EffectsFunctionDecl {#effectsfunctiondecl}

A shared effects function (runtime).

| Field | Type | Required | Default | Example | Description |
|---|---|---|---|---|---|
| `kind` | `"effects"` | yes | — | `"effects"` | An effects function: its body is a list of effects (runtime). |
| `id` | [FnId](shapes.md#fnid) | yes (propose assigns it; a new declaration leaves it out) | — | — | A shared function id (`fn_…`); renames keep it. |
| `name` | [Ident](shapes.md#ident) | yes | — | `"close_order"` | The function name. |
| `label` | [Text](shapes.md#text) | no | — | `"Close order"` | The words shown for the function. |
| `params` | [ParamDecl](function.md#paramdecl)[] | yes | — | `[{"name":"order","type":"ref<order>"}]` | The parameters, in call order. |
| `body` | [EffectDecl](effect.md#effectdecl)[] | yes | — | (see the example) | The effects it runs, in order. |

`functions/close_order.json`

```json
{
  "kind": "effects",
  "label": "Close order",
  "params": [{ "name": "order", "type": "ref<order>" }],
  "body": [
    {
      "op": "transition",
      "target": "order",
      "lifecycle": "lc_2k4m6p8r0t",
      "transition": "tn_6s8v0x2z4b"
    }
  ]
}
```

## ParamDecl {#paramdecl}

A parameter: its name and type.

| Field | Type | Required | Default | Example | Description |
|---|---|---|---|---|---|
| `name` | [Ident](shapes.md#ident) | yes | — | `"day"` | The parameter name, as CX reads it. |
| `type` | string | yes | — | `"date"` | The parameter type as typeref text, e.g. date or ref<customer> (cx.md §2.10). |

An item of `params` in a function file or a derived property.

```json
{ "name": "day", "type": "date" }
```
