AppSpring Docs

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

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 | EffectsFunctionDecl.

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 yes (propose assigns it; a new declaration leaves it out) — — A shared function id (fn_…); renames keep it.
name Ident yes — "vat" The function name CX calls it by.
label Text no — "VAT" The words shown for the function.
params 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 yes — "amount * 0.25" The CX expression it returns.

functions/vat.json

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

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 yes (propose assigns it; a new declaration leaves it out) — — A shared function id (fn_…); renames keep it.
name Ident yes — "close_order" The function name.
label Text no — "Close order" The words shown for the function.
params ParamDecl[] yes — [{"name":"order","type":"ref<order>"}] The parameters, in call order.
body EffectDecl[] yes — (see the example) The effects it runs, in order.

functions/close_order.json

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

ParamDecl

A parameter: its name and type.

Field Type Required Default Example Description
name 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 (cx.md §2.10).

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

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

This page as Markdown