{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://daana.dev/schemas/dar-spec/v1.0.json",
  "title": "dar-spec v1.0",
  "description": "Machine-readable schema for dar-spec v1.0 documents. Purpose: in-editor validation/autocomplete for humans; mechanical self-checking for agents before human review. This schema validates shape only. The meaning of each field, what Daana does with it today, is the field's `description` here; it also says where Daana accepts a value it does not support. Stays within the keyword subset that `daana dar check` implements (no `not`, no unevaluatedProperties).",
  "type": "object",
  "required": [
    "spec",
    "anchor",
    "outputs"
  ],
  "additionalProperties": false,
  "patternProperties": {
    "^x_": {
      "description": "Daana accepts any top level key that starts with `x_` and does not read it, so it can hold notes for people or other tools."
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "anchor": {
            "required": [
              "consumer"
            ]
          }
        },
        "required": [
          "anchor"
        ]
      },
      "then": {
        "properties": {
          "outputs": {
            "additionalProperties": {
              "properties": {
                "kind": {
                  "pattern": "^serve\\."
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "anchor": {
            "required": [
              "entity"
            ]
          }
        },
        "required": [
          "anchor"
        ]
      },
      "then": {
        "properties": {
          "outputs": {
            "additionalProperties": {
              "properties": {
                "kind": {
                  "pattern": "^(dimension|bridge|entity_assembly|fact\\.|reference\\.)"
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "anchor": {
            "required": [
              "process"
            ]
          }
        },
        "required": [
          "anchor"
        ]
      },
      "then": {
        "properties": {
          "outputs": {
            "additionalProperties": {
              "properties": {
                "kind": {
                  "pattern": "^(dimension|bridge|entity_assembly|fact\\.|reference\\.)"
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "anchor": {
            "required": [
              "reference"
            ]
          }
        },
        "required": [
          "anchor"
        ]
      },
      "then": {
        "properties": {
          "outputs": {
            "additionalProperties": {
              "properties": {
                "kind": {
                  "pattern": "^(dimension|bridge|entity_assembly|fact\\.|reference\\.)"
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "anchor": {
            "required": [
              "validation"
            ]
          }
        },
        "required": [
          "anchor"
        ]
      },
      "then": {
        "required": [
          "lifecycle"
        ],
        "properties": {
          "outputs": {
            "additionalProperties": {
              "properties": {
                "kind": {
                  "pattern": "^(dimension|bridge|entity_assembly|fact\\.|reference\\.)"
                }
              }
            }
          }
        }
      }
    }
  ],
  "properties": {
    "spec": {
      "description": "Names the version of the DAR specification that the document follows. `daana dar check` shows it on its `Spec:` line; Daana reads nothing else from it.",
      "type": "string",
      "pattern": "^dar/v1\\.0$"
    },
    "anchor": {
      "description": "Names what the document declares its outputs on, with exactly one key. Daana keeps one revision per anchor in its ledger, and default object names contain the anchor's name, such as `dim__customer`. Documents on the same anchor share one set of output keys.",
      "type": "object",
      "minProperties": 1,
      "maxProperties": 1,
      "properties": {
        "entity": {
          "description": "Anchors the document on an entity of the DAB model, by name. Outputs read the entity that `source.dab` names, or else the anchor's entity, also found as `<name>_entity`. `daana dar check` refuses an anchor whose entity the model lacks, with the error `DAR012`.",
          "type": "string"
        },
        "process": {
          "description": "Anchors the document on a named process instead of a DAB entity. Outputs that read DAB views still read the entity that `source.dab`, the anchor's name or `<name>_entity` names. `daana dar check` reports neither a missing anchor entity nor an unknown `source.dab`, but still applies `DAR017` and `DAR018` to `source.dab`.",
          "type": "string"
        },
        "consumer": {
          "description": "Anchors the document on a named consumer of published data. Its outputs must be `serve.view` or `serve.table`, and `daana dar generate` writes them to the dataset `serve_<name>`, which `workspace.yaml` must declare.",
          "type": "string"
        },
        "reference": {
          "description": "Anchors the document on named reference data instead of a DAB entity. Outputs that read DAB views still read the entity that `source.dab`, the anchor's name or `<name>_entity` names. `daana dar check` reports neither a missing anchor entity nor an unknown `source.dab`, but still applies `DAR017` and `DAR018` to `source.dab`.",
          "type": "string"
        },
        "validation": {
          "description": "Anchors the document on a named validation. The document must have a `lifecycle` block, a union or unified star is named `<name>_<output key>` instead of `fct__<name>`, and `daana dar generate` writes the outputs to the dataset `<name>`, which `workspace.yaml` must declare.",
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "source": {
      "description": "Names what the document reads: the DAB entity in `dab` and, for projections, computed references and external references, an existing table in `table` with its columns in `attributes`.",
      "$ref": "#/$defs/source"
    },
    "provides": {
      "description": "`fx` marks the document as the source of exchange rates. A leg with `fx` converts amounts with the rates of this document's `daily` output, and compile then refuses a second document with `provides: fx` or one that has no `daily` output.",
      "enum": [
        "fx"
      ]
    },
    "lifecycle": {
      "description": "States whether the whole document is temporary and when it is to be removed. Daana accepts this block but does not read it. A document anchored on `validation` must have it.",
      "$ref": "#/$defs/lifecycle"
    },
    "scopes": {
      "description": "Names reusable SQL row conditions. Where an output's, variant's, stream's or `fact.union` leg's `scope`, a bridge's `to_scope`, or a rollup's `where.scope`, names an entry, Daana uses its condition; any other value is used as SQL itself.",
      "type": "object",
      "additionalProperties": {
        "type": "string",
        "minLength": 1
      }
    },
    "relationships": {
      "description": "Relates the anchor entity to other entities, one entry per role name. The role name is also the related entity unless the entry's `entity` names another, and facts carry the key as `<role>_key`. Daana keeps the links in relationship objects, such as `intm__rel_order`, which `keys` reads. A document with an `entity_assembly` gets none: the assembly carries each key as `<entity>_key`. `daana dar check` refuses a fact's `keys` in that document, and another document's `via` key through it (`DAR021`), unless a document on the same anchor without an `entity_assembly`, checked together with it, declares that relationship: only then does a relationship object hold the key, and otherwise the SQL would read an object or a column that does not exist.",
      "type": "object",
      "propertyNames": {
        "minLength": 1
      },
      "additionalProperties": {
        "$ref": "#/$defs/relationship"
      }
    },
    "stream": {
      "description": "Declares the anchor's event stream: conditions, guards, and flags evaluated on each row of the entity's history. The document's event, snapshot, and lifecycle outputs read it, and when two or more outputs name `from: stream`, Daana computes it once in `intm__<anchor>_event`.",
      "$ref": "#/$defs/stream"
    },
    "outputs": {
      "description": "The reporting outputs of the document, keyed by a name the author chooses. The key appears in references such as `<anchor>.<key>` and in some default names, such as `fct__<anchor>_<key>` for a consolidated fact. `daana dar check` refuses the same key on one anchor in two files, with `DAR009`.",
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "$ref": "#/$defs/output"
      }
    }
  },
  "$defs": {
    "expr": {
      "type": "string",
      "minLength": 1
    },
    "described_expr": {
      "type": "object",
      "required": [
        "expr",
        "description"
      ],
      "properties": {
        "expr": {
          "description": "The SQL expression. Under `flags`, it is the condition that sets the flag to 1 on a row; under `derive` or `derived_milestones`, it computes the column.",
          "$ref": "#/$defs/expr"
        },
        "description": {
          "description": "Describes the flag or column for readers of the document. Daana does not read it.",
          "type": "string"
        },
        "ai_context": {
          "description": "Holds hints for AI assistants about the flag or column. Daana does not read it.",
          "$ref": "#/$defs/ai_context"
        }
      },
      "additionalProperties": false
    },
    "ai_context": {
      "type": "object",
      "properties": {
        "synonyms": {
          "description": "Other names for the item, for AI assistants. Daana does not read it.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "instructions": {
          "description": "Guidance for AI assistants on how to use the item. Daana does not read it.",
          "type": "string"
        },
        "examples": {
          "description": "Examples of the item for AI assistants. Daana does not read it.",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "flag": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "from"
          ],
          "properties": {
            "from": {
              "description": "Names the condition under `conditions` that sets the flag to 1 on a row; compile refuses a name that is not a condition. In an output's `flags`, Daana reads a flag's keys only when the document's `stream` declares no flags; `daana dar check` refuses a `fact.event` flag that the stream does not compute (`DAR021`), and `from` on a `fact.state` (`DAR019`).",
              "type": "string"
            },
            "and": {
              "description": "An extra SQL condition that the row must also meet. With `dedupe`, Daana tests it on the row that `dedupe` picks, so a first or last row that fails it leaves the flag at 0 rather than moving it to another row.",
              "$ref": "#/$defs/expr"
            },
            "dedupe": {
              "description": "`first` sets the flag only on the entity's first row on which the `from` condition holds, and `last` only on the last such row. Without it, the flag is 1 on every such row.",
              "enum": [
                "first",
                "last"
              ]
            },
            "unless": {
              "description": "Names a guard under the document's `stream.guards`. The flag is 0 on a row when any later row of the same entity meets the guard; `daana dar check` refuses a name that is not such a guard (`DAR019`) when an output computes the flag.",
              "type": "string"
            },
            "description": {
              "description": "Describes the flag for readers of the document. Daana does not read it.",
              "type": "string"
            },
            "ai_context": {
              "description": "Holds hints for AI assistants about the flag. Daana does not read it.",
              "$ref": "#/$defs/ai_context"
            },
            "unless_prior": {
              "description": "Daana accepts this key but does not read it, so it suppresses nothing.",
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        {
          "$ref": "#/$defs/described_expr"
        }
      ]
    },
    "flags_block": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/flag"
      }
    },
    "conditions_block": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/expr"
      }
    },
    "descriptions_block": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "derive_block": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/described_expr"
      }
    },
    "checks_block": {
      "type": "object",
      "additionalProperties": {
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "object",
            "required": [
              "expr"
            ],
            "properties": {
              "expr": {
                "description": "The SQL condition that the output must meet, evaluated once over the whole output, so it is built from aggregates such as `COUNT` or `SUM`. The check passes only when it is `TRUE`; `NULL` fails. `{self}` names this output, and `{<anchor>.<output>}` names another one.",
                "type": "string"
              },
              "description": {
                "description": "Describes the check. Daana stores it with the check in the ledger but shows it in no apply message, and changing it gives the anchor a new revision.",
                "type": "string"
              },
              "over": {
                "description": "Only `output` works: the condition runs once over the whole output. `rows` is the default when `over` is omitted or the check is a plain string, and `daana dar check` refuses it (`DAR019`): write `over: output`.",
                "enum": [
                  "rows",
                  "output"
                ]
              },
              "severity": {
                "description": "`error`, the default, makes `daana dar apply` fail when the condition does not hold: the new outputs are already in place, and the ledger keeps the previously active revision. `warn` prints a warning, and the apply continues.",
                "enum": [
                  "warn",
                  "error"
                ]
              }
            },
            "additionalProperties": false
          }
        ]
      }
    },
    "additivity": {
      "oneOf": [
        {
          "enum": [
            "additive",
            "non_additive"
          ]
        },
        {
          "type": "object",
          "required": [
            "semi_additive"
          ],
          "properties": {
            "semi_additive": {
              "description": "Names which value within a period counts, the last or the first. Daana does not implement it: on a measure it is not read, and on an aggregate neither value changes the generated SQL. Compile refuses `first_within_period` on an aggregate of a `fact.consolidated` leg.",
              "enum": [
                "last_within_period",
                "first_within_period"
              ]
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "aggregate": {
      "type": "object",
      "required": [
        "expr",
        "agg"
      ],
      "properties": {
        "expr": {
          "description": "Gives the column or SQL expression that Daana aggregates, read from the leg's source. For a `reference.computed` leg that reads `dab`, `daana dar check` can report `DAR015` when a bare column name is not a column of that entity.",
          "$ref": "#/$defs/expr"
        },
        "agg": {
          "description": "Names the function Daana applies to `expr` within the leg, grouped by the leg's grain. A `fact.consolidated` then sums the leg results to its own grain, and sums the values of an unaggregated leg directly. `daana dar check` refuses `count_distinct` (`DAR019`): Daana does not build it.",
          "enum": [
            "sum",
            "count",
            "count_distinct",
            "min",
            "max",
            "avg"
          ]
        },
        "filters": {
          "description": "Lists conditions on the leg's rows. On a `fact.consolidated` leg that Daana aggregates, a row that fails a condition is left out of the aggregate, whatever its `agg`, and a group in which no row passes gives 0 for `sum` and `count`, and `NULL` for `min`, `max`, and `avg`. A bare column name means the column equals 1; `market_matches_spine` keeps the leg unaggregated, each value only on the spine row with the leg's market. On a leg kept unaggregated, by `market_matches_spine` or by `grain_keys`, Daana does not apply `agg`: the fact sums the leg's values, and a row that fails a condition adds 0. A `reference.computed` leg does not apply `filters`, and `daana dar check` refuses them there (`DAR019`): write the condition into `expr`.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "fx": {
          "description": "`none` keeps this aggregate unconverted when its leg has `fx`; an aggregate other than `sum` on a converting leg needs it. `daana dar check` refuses the object form (`DAR019`).",
          "oneOf": [
            {
              "const": "none"
            },
            {
              "$ref": "#/$defs/fx"
            }
          ]
        },
        "hidden": {
          "description": "Computes the aggregate but leaves it out of the output columns, so `derive` can still use it.",
          "type": "boolean"
        },
        "additivity": {
          "description": "In a `fact.consolidated`, compile refuses every value except `{semi_additive: last_within_period}`, and that value does not change the SQL. A `reference.computed` does not use it in the SQL.",
          "$ref": "#/$defs/additivity"
        },
        "description": {
          "description": "Describes the column for readers of the document. Daana does not read it.",
          "type": "string"
        },
        "ai_context": {
          "description": "Holds hints for AI assistants about the column. Daana does not read it.",
          "$ref": "#/$defs/ai_context"
        }
      },
      "additionalProperties": false
    },
    "fx": {
      "type": "object",
      "required": [
        "rate",
        "currency"
      ],
      "properties": {
        "rate": {
          "description": "Picks the rate that converts the leg: Daana multiplies each converting `sum` by the rate table's column `rate_<rate>`. With `daily`, the rate row has the leg's date; with `monthly_average` or `end_of_month`, it is the last observed row of that date's month.",
          "enum": [
            "monthly_average",
            "end_of_month",
            "daily"
          ]
        },
        "currency": {
          "description": "Names the leg column that holds each row's source currency, or gives an SQL expression for it. Daana matches it to the rate table's `from_currency_code`.",
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "key_part": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "object",
          "required": [
            "expr"
          ],
          "properties": {
            "expr": {
              "description": "A SQL expression for one key part. In `lookups`, Daana compares its value with the target's `grain` column at the same position, and `{axis}` stands for `axis.name`. In a `reference.computed` leg, it computes the grain column that the entry names. A `fact.consolidated` leg does not use it: Daana reads each grain column under its own name, but changing it gives the anchor a new revision.",
              "$ref": "#/$defs/expr"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "via"
          ],
          "properties": {
            "via": {
              "description": "Reads an attribute of a related entity, written `<relationship>.latest.<attribute>`: its current value on the entity that the document's relationship reaches, through that relationship's `via` steps where it has them. Compile refuses a middle part other than `latest` and a `keys_only` relationship. A `fact.consolidated` leg does not use it, but changing it gives the anchor a new revision.",
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "keys": {
      "oneOf": [
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "required": [
              "expr"
            ],
            "properties": {
              "expr": {
                "description": "The SQL expression for the key column that the entry names. A `fact.projection` without `from` adds it as a column before the others, and its `wide` view takes the first entry as the anchor key. Other kinds, and a projection with `from`, do not compile a map of `keys`, but changing it gives the anchor a new revision; on a projection with `from` and `wide`, `daana dar check` refuses a key the projection does not select (`DAR021`), which the wide view would read.",
                "$ref": "#/$defs/expr"
              },
              "description": {
                "description": "Describes the key column for readers of the document. Daana does not read it.",
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        }
      ]
    },
    "keys_at": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "required": [
          "at"
        ],
        "properties": {
          "at": {
            "description": "Lists the `fact.lifecycle` milestones at whose time Daana reads the role's key, adding a column `<role>_key_at_<milestone>` for each, `NULL` until the milestone is reached. A tracked step reads the key valid at that time, a `changes: never` step the current key. Daana ignores a name that is not a milestone, but changing it gives the anchor a new revision. `daana dar check` refuses `keys_at` on a lifecycle with an `attribute` or `rollup` milestone or a flag `rollup` (`DAR019`).",
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "additionalProperties": false
      }
    },
    "lookups_block": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "required": [
          "from",
          "key"
        ],
        "properties": {
          "from": {
            "description": "Names the output to join, as `<anchor>.<output>`, which must declare `grain`, or `key` on a `reference.external`. The lookup joins its published object, or the source table of a `reference.external`, on those columns. `daana dar check` on a directory refuses a name that does not resolve (`DAR007`). Only a `fact.state` and the `post` block of a `fact.consolidated` compile lookups.",
            "type": "string"
          },
          "key": {
            "description": "Lists one key part for each `grain` column of the target, in order, and the lookup joins the row where every part equals its column. A name is a column of the row that this output reads, `expr` is a SQL expression, and `via` reads an attribute of a related entity. Compile fails when the number of parts and grain columns differ.",
            "type": "array",
            "items": {
              "$ref": "#/$defs/key_part"
            }
          },
          "on_miss": {
            "description": "With `default(<literal>)`, Daana replaces a `NULL` value of the lookup's columns, as when the lookup finds no row, wherever `derive` reads them as `{name.column}`. `null`, or no `on_miss`, leaves them `NULL`.",
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "string",
                "pattern": "^default\\(.*\\)$"
              }
            ]
          }
        },
        "additionalProperties": false
      }
    },
    "measures": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "object",
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "description": "Names the column that holds the measure. A `fact.state` or `fact.event` selects it as it selects `columns`, and a `fact.unified_star` stage selects it from its source, with `NULL` in stages that lack it. A `fact.projection` does not select its measures; only its `wide` view lists them.",
                "type": "string"
              },
              "additivity": {
                "description": "States how the measure adds up. Daana accepts this key on a measure but does not read it.",
                "$ref": "#/$defs/additivity"
              },
              "description": {
                "description": "Describes the measure for readers of the document. Daana does not read it.",
                "type": "string"
              },
              "ai_context": {
                "description": "Holds hints for AI assistants about the measure. Daana does not read it.",
                "$ref": "#/$defs/ai_context"
              }
            },
            "additionalProperties": false
          }
        ]
      }
    },
    "columns_list": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "wide": {
      "type": "object",
      "required": [
        "dims"
      ],
      "properties": {
        "dims": {
          "description": "Names, under each key, an entity whose dimension Daana joins into the wide view, with the columns to add. The key is the anchor or an entity whose key column, such as `customer_key`, the fact carries. A list gives the columns with a `pit` join; an object sets `pick` and `join`. `daana dar check` on a directory refuses a `keys_only` entity (`DAR004`).",
          "type": "object",
          "additionalProperties": {
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              {
                "type": "object",
                "required": [
                  "pick"
                ],
                "properties": {
                  "pick": {
                    "description": "Lists the dimension's columns to add to the wide view, in order. `daana dar check` refuses a name that the dimension does not publish (`DAR015`). On a `fact.state` or `fact.event`, a pick replaces the fact column of the same name; on the other kinds, the duplicate name fails compile.",
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "join": {
                    "description": "`pit`, the default, joins the dimension version valid at the row's axis time, such as `fact_ts` on a `fact.event`. `latest` joins the entity's current version from `dim__<entity>__latest` on the key alone. That view exists only when the dimension sets `latest`: `daana dar check` on a directory refuses a `latest` join when the entity's dimension there has none, and any join of a dimension renamed with `publish.name` (`DAR021`).",
                    "enum": [
                      "pit",
                      "latest"
                    ]
                  },
                  "alias": {
                    "description": "Daana accepts this key but does not read it: the wide view keeps the name of each picked column.",
                    "$ref": "#/$defs/descriptions_block"
                  },
                  "descriptions": {
                    "description": "Describes the picked columns. Daana accepts this key but does not read it.",
                    "$ref": "#/$defs/descriptions_block"
                  }
                },
                "additionalProperties": false
              }
            ]
          }
        },
        "drop_keys": {
          "description": "Removes the named key columns, such as `order_key`, from the wide view, while its joins still use them. On a `fact.lifecycle`, the `keys_at` columns count as key columns. Compile fails on a name that is not a key column of the wide view.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "drop": {
          "description": "Removes the named fact columns that follow the picked columns, such as measures, columns, derived columns, and flags, from the wide view. Compile fails on a name that the wide view does not carry there.",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "axis": {
      "type": "object",
      "properties": {
        "name": {
          "description": "Names the axis column. On a `fact.state` it holds `expr`, or is an existing column when `expr` is omitted; with `expr` alone it is `fact_ts`. On a `fact.projection` it is an existing column; reading an `entity_assembly`, it defaults to the assembly's attribute ending in `_start_ts`. A `fact.unified_star` names its time column with it, `fact_ts` by default. A `fact.event` keeps `fact_ts`, and `daana dar check` refuses another name (`DAR021`) when its `wide` view or generate's default partition would read it.",
          "type": "string"
        },
        "expr": {
          "description": "The SQL expression that dates each row of a `fact.state`, which Daana selects as the axis column. When it uses the effective timestamp, `eff_tmstp` by default, the state reads the anchor's history view and keeps each entity's latest row. Other kinds do not compile it. An expression other than a column name or `end_of_day(column)` needs an explicit `exclude_today`, or `daana dar check` refuses it (`DAR002`).",
          "$ref": "#/$defs/expr"
        },
        "description": {
          "description": "Describes the axis for readers of the document. Daana does not read it.",
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "scope": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      ]
    },
    "exclude_today": {
      "oneOf": [
        {
          "type": "boolean"
        },
        {
          "type": "string",
          "minLength": 1
        }
      ]
    },
    "partition": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "object",
          "properties": {
            "month_of": {
              "description": "In `daana dar generate`, partitions the table by the month of this column, but only when it is `fact_ts`; otherwise the kind's default applies. On a `fact.lifecycle`, it names the milestone that dates each row, and Daana drops rows whose milestone is missing, today, or later. Daana does not read it under a snapshot variant.",
              "type": "string"
            },
            "day_of": {
              "description": "Names a timestamp column whose day partitions the table in `daana dar generate`. On an `entity_assembly` with `incremental`, it is also the column that the lookback and the full refresh floor filter on. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and Daana does not read it under a snapshot variant.",
              "type": "string"
            },
            "nulls": {
              "description": "`keep` keeps the rows of a `fact.lifecycle` whose axis milestone is missing, which its today cut otherwise drops. Daana reads it only on a lifecycle whose milestones all come from flags, and `daana dar check` refuses it on a lifecycle built from history (`DAR019`). On other outputs it does not change the SQL, but changing it gives the anchor a new revision.",
              "enum": [
                "keep"
              ]
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "cluster": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "materialize": {
      "enum": [
        "table",
        "view"
      ]
    },
    "publish": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "description": "Replaces the output's default object name, and a `__latest` or `__wide` companion takes it as its prefix. On a `fact.periodic_snapshot`, `daana dar check` accepts it only as the default name of the snapshot's one grain, on a snapshot without variants (`DAR019`). On the three `reference` kinds, `daana dar check` refuses it (`DAR019`): Daana would plan the object without SQL. Under a snapshot variant, Daana does not read it.",
          "type": "string"
        },
        "dataset": {
          "description": "Names the `workspace.yaml` target that `daana dar generate` writes the output to, and generate fails when `workspace.yaml` does not declare it. Without it, generate writes to `data_mart`, or `intermediate` for an `intm__` object, when `workspace.yaml` has targets, and a `consumer` or `validation` anchor has its own default. `daana dar apply` does not use it, but changing it gives the anchor a new revision.",
          "type": "string"
        },
        "description": {
          "description": "Describes the published object for readers of the document. Daana does not read it.",
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "lifecycle": {
      "type": "object",
      "required": [
        "temporary",
        "sunset"
      ],
      "properties": {
        "temporary": {
          "description": "States whether the output or document is temporary. Daana accepts this key but does not read it.",
          "type": "boolean"
        },
        "sunset": {
          "description": "States, as free text, when or why the output or document is to be removed. Daana accepts this key but does not read it.",
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "source_attributes": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "required": [
          "description"
        ],
        "properties": {
          "from": {
            "description": "Names the source column when it differs from the attribute's name; Daana selects it under the attribute's name. Without it, the column has the attribute's name. Daana does not read it under a leg's `attributes`.",
            "type": "string"
          },
          "description": {
            "description": "Describes the column for readers of the document. Daana does not read it.",
            "type": "string"
          },
          "ai_context": {
            "description": "Holds hints for AI assistants about the column. Daana does not read it.",
            "$ref": "#/$defs/ai_context"
          }
        },
        "additionalProperties": false
      }
    },
    "source": {
      "type": "object",
      "properties": {
        "dab": {
          "description": "Names the DAB entity, by name or id, whose views the document reads. Without it, Daana reads the entity named like the anchor, or `<anchor>_entity`. `daana dar check` refuses a name the model lacks on an entity anchor (`DAR014`), documents on one anchor that resolve to different entities (`DAR018`), and another entity than the anchor's in a document with an `entity_assembly`, a bridge, a lifecycle rollup or `relationships` (`DAR017`). Daana does not read it under an output's `source`.",
          "type": "string"
        },
        "table": {
          "description": "Names an existing table, as `<schema>.<table>`, that Daana selects from instead of a DAB view. A `fact.projection` without `from` reads its own `source.table` or else the document's; a `reference.computed` without `legs`, and lookups on a `reference.external` output, read the document's. Other outputs do not read it. A projection with its own `source` gets an object only with `publish.name`.",
          "type": "string"
        },
        "attributes": {
          "description": "The columns that Daana selects from `table`, keyed by the name they get in the output; an entry's `from` names the source column when it differs. Daana reads them in the same places as `table`.",
          "$ref": "#/$defs/source_attributes"
        }
      },
      "additionalProperties": false
    },
    "relationship": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "via"
          ],
          "properties": {
            "via": {
              "description": "Reaches the entity through another relationship of this document, named by its role. Daana reads the second step as the document anchored on the middle entity declares the relationship of the same name, so apply the documents together. `daana dar check` refuses a role that this document does not declare, with `DAR003`.",
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "changes"
          ],
          "properties": {
            "changes": {
              "description": "`never` states that the anchor keeps one related entity. Daana reads one related key for each anchor, on the anchor's key alone, whatever the time of the fact, and compile refuses it unless the model relationship gives each anchor at most one related entity.",
              "const": "never"
            },
            "sentinel": {
              "description": "A key value that the source uses to mean no reference. Daana turns it into `NULL` in the relationship objects that facts read their keys from, and in the key that an `entity_assembly` publishes. In an incremental assembly with `preserve: keys`, a newer link that holds the sentinel sets the key to `NULL`, as a full refresh does; the key that the table already holds is kept only when the run reads no newer link for the entity.",
              "type": "string"
            },
            "on_multiple": {
              "description": "Daana accepts this key but does not read it.",
              "enum": [
                "first_observed",
                "any"
              ]
            },
            "entity": {
              "description": "Names the related DAB entity when it differs from the role name, which is the default. Facts still name the key column `<role>_key`, while an `entity_assembly` names it `<entity>_key`, and so do the projections of the assembly and their `wide` views. `daana dar check` refuses an entity that the model lacks, with `DAR012`, or that the model does not relate to the anchor, with `DAR016`.",
              "type": "string"
            },
            "keys_only": {
              "description": "`true` makes the related entity keys only: outputs carry its key, and `daana dar check` asks for no dimension of it. Check on a directory then refuses picks from it in `wide`, with `DAR004`, and compile refuses lookups that read its attributes.",
              "type": "boolean"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "changes"
          ],
          "properties": {
            "changes": {
              "description": "`tracked` states that the related entity can change. Daana keeps the link's validity intervals and reads the related key that holds at the fact's time, so a fact dated before the link became valid gets no key.",
              "const": "tracked"
            },
            "sentinel": {
              "description": "A key value that the source uses to mean no reference. Daana turns it into `NULL` in the relationship objects that facts read their keys from, and in the key that an `entity_assembly` publishes. In an incremental assembly with `preserve: keys`, a newer link that holds the sentinel sets the key to `NULL`, as a full refresh does; the key that the table already holds is kept only when the run reads no newer link for the entity.",
              "type": "string"
            },
            "entity": {
              "description": "Names the related DAB entity when it differs from the role name, which is the default. Facts still name the key column `<role>_key`, while an `entity_assembly` names it `<entity>_key`, and so do the projections of the assembly and their `wide` views. `daana dar check` refuses an entity that the model lacks, with `DAR012`, or that the model does not relate to the anchor, with `DAR016`.",
              "type": "string"
            },
            "keys_only": {
              "description": "`true` makes the related entity keys only: outputs carry its key, and `daana dar check` asks for no dimension of it. Check on a directory then refuses picks from it in `wide`, with `DAR004`, and compile refuses lookups that read its attributes.",
              "type": "boolean"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "stream": {
      "type": "object",
      "properties": {
        "source": {
          "description": "`history` reads the anchor entity's history view, one row per version. Daana also reads the history view when `source` is omitted.",
          "enum": [
            "history"
          ]
        },
        "scope": {
          "description": "Filters the history rows that the stream reads, by a name under `scopes` or an SQL condition. It replaces a snapshot's own `scope`, and an event's or lifecycle's when fewer than two outputs name `from: stream`. A snapshot variant's `scope` applies on top of it: the variant reads the rows that meet both. Daana ignores the list form.",
          "$ref": "#/$defs/scope"
        },
        "columns": {
          "description": "Names the history view columns that the stream selects and carries into its outputs. Columns used only in conditions need not be listed. `daana dar check` refuses a name that is not a column of the view, with `DAR015`.",
          "$ref": "#/$defs/columns_list"
        },
        "conditions": {
          "description": "Named SQL conditions tested on every history row, which flags name in `from`. `{prev.<column>}` stands for the column's value on the entity's previous row, `'NONE'` on its first. The conditions stay internal: only flags reach the outputs.",
          "$ref": "#/$defs/conditions_block"
        },
        "guards": {
          "description": "Named SQL conditions that flags name in `unless`: a flag is 0 on a row when any later row of the same entity meets the guard. A guard that no flag names has no effect.",
          "$ref": "#/$defs/conditions_block"
        },
        "flags": {
          "description": "Named columns of 0 or 1, computed on each history row from a condition or from an SQL expression. The outputs that read the stream carry all of them or the ones they list.",
          "$ref": "#/$defs/flags_block"
        },
        "descriptions": {
          "description": "Holds descriptions by flag name. Daana accepts this block but does not read it.",
          "$ref": "#/$defs/descriptions_block"
        },
        "keep_rows": {
          "description": "`any_flag` keeps only the rows on which at least one flag is 1, in a `fact.event` that reads the stream and in the shared `intm__<anchor>_event`. Daana applies no other value here. With two or more readers, snapshots and lifecycles read only the kept rows too, so a snapshot's state at the period end comes from the last kept row.",
          "type": "string",
          "minLength": 1
        },
        "prior_guards": {
          "description": "Daana accepts this block but does not read it.",
          "$ref": "#/$defs/conditions_block"
        }
      },
      "patternProperties": {
        "^x_": {
          "description": "Daana accepts any stream key that starts with `x_` and does not read it."
        }
      },
      "additionalProperties": false
    },
    "incremental": {
      "type": "object",
      "required": [
        "watermark"
      ],
      "properties": {
        "watermark": {
          "description": "Names the load timestamp column that Daana reads from the entity's attribute table, such as `customer_desc`, and from its relationship tables, in place of `ver_tmstp`. The output holds each entity's newest value in this column. An incremental run in Dataform reads only rows above the newest value already in the table.",
          "type": "string"
        },
        "lookback": {
          "description": "Sets, as a number of days such as `30d`, how far back an incremental Dataform run updates: Daana merges only the entities whose partition column falls within that many days before the run. Incremental mode needs a value above zero, so `daana dar check` refuses `0d` or a missing value on an incremental `entity_assembly` (`DAR020`). `daana dar apply` does not use it, but changing it gives the anchor a new revision.",
          "type": "string",
          "pattern": "^[0-9]+d$"
        },
        "full_refresh_floor": {
          "description": "Sets the earliest date that the output keeps. In Dataform, a full refresh keeps the entities whose partition column is on or after it, and incremental mode requires it. `daana dar apply` keeps the entities whose first listed `START_TIMESTAMP` attribute is on or after it, and compile fails when no listed attribute has that type.",
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "preserve": {
          "description": "With `keys`, an incremental Dataform run keeps an entity's relationship key from its row already in the table only when it reads no newer link for that entity. A newer link decides the key, also when it holds the relationship's `sentinel`: the key then becomes `NULL`, as in a full refresh. With `none`, the default, a key without a newer link becomes `NULL`. `daana dar apply` reads every link, so this key does not change its output.",
          "enum": [
            "keys",
            "none"
          ]
        }
      },
      "additionalProperties": false
    },
    "rollup": {
      "type": "object",
      "required": [
        "from",
        "via"
      ],
      "properties": {
        "from": {
          "description": "Names the child rows to aggregate, as `<child>.stream` or `<child>.history`; `daana dar check` refuses any other form (`DAR019`). `stream` reads the child's events from its shared `intm__<child>_event`, which Daana builds when two or more of the child's outputs set `from: stream`: `daana dar check` refuses a milestone's rollup from a stream that fewer outputs read (`DAR021`) when the child's document is checked together with this one, in a directory or in the same file, and a flag's rollup from any stream (`DAR019`). `history` reads the child's DAB history view. The child's document must be in the same `daana dar apply` or `daana dar generate` as this one: both refuse an input that holds the lifecycle without it, and name the child.",
          "type": "string"
        },
        "via": {
          "description": "Names the child's relationship to this anchor as `<child>.<role>`, with the same child as `from`. `daana dar check` on a directory refuses a relationship that is not `changes: never` (`DAR006`) or does not lead to this anchor (`DAR008`). Daana links each child to its anchor through the model's relationship between the two entities.",
          "type": "string"
        },
        "where": {
          "description": "Limits the child's stream rows before Daana aggregates them. Daana uses it only with `from: <child>.stream`; otherwise changing it gives the anchor a new revision and nothing else.",
          "type": "object",
          "properties": {
            "flag": {
              "description": "Keeps only the child's stream rows where this stream flag is 1. Daana does not use it with `from: <child>.history`, but changing it gives the anchor a new revision.",
              "type": "string"
            },
            "scope": {
              "description": "Names a scope of the child document, or an SQL condition, that limits the child's stream rows. Daana does not use it with `from: <child>.history`, but changing it gives the anchor a new revision.",
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "agg": {
          "description": "Chooses how Daana combines the child values: `min` keeps the smallest and `max` the largest, first per child and then per anchor. `daana dar check` refuses a rollup without `agg` (`DAR020`).",
          "enum": [
            "min",
            "max"
          ]
        },
        "of": {
          "description": "With `from: <child>.history`, names the child's column that `agg` aggregates, and `daana dar check` refuses such a rollup without it (`DAR020`). With `from: <child>.stream`, Daana aggregates the event time and does not use `of`, but changing it gives the anchor a new revision.",
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "milestone": {
      "type": "object",
      "properties": {
        "flag": {
          "description": "Names a stream flag. The milestone is the latest time the flag is 1, so a flag that fires once gives the time it fired. With `keys`, `keys_at`, `derived_milestones`, `partition.month_of`, or a shared `intm__<anchor>_event`, Daana also adds a column named after the flag, 1 when the milestone is set, and the lifecycle's `wide` view carries it. `daana dar check` refuses it in a lifecycle built from history (`DAR019`), which reads no stream rows.",
          "type": "string"
        },
        "attribute": {
          "description": "Names an attribute of the anchor's DAB entity; the milestone takes its value from the entity's latest history row. Such a milestone makes Daana build the lifecycle from history, as `milestones` describes. `daana dar check` refuses a name that is not a column of that entity's history view (`DAR015`).",
          "type": "string"
        },
        "rollup": {
          "description": "Takes the milestone from a child entity related to this anchor: Daana aggregates the child's event times, or a column of its history, per child and then per anchor with `agg`. Such a milestone makes Daana build the lifecycle from history, as `milestones` describes.",
          "$ref": "#/$defs/rollup"
        },
        "flag_name": {
          "description": "Adds a column with this name, 1 when the milestone has a value and 0 otherwise, in a lifecycle built from history: one with an `attribute` or `rollup` milestone or a `rollup` flag. A lifecycle built from the stream gets no such column, in its table or in its `wide` view, and only the revision changes with `flag_name`.",
          "type": "string"
        },
        "description": {
          "description": "Describes the milestone for readers of the document. Daana does not read it.",
          "type": "string"
        },
        "ai_context": {
          "description": "Holds hints for AI assistants about the milestone. Daana does not read it.",
          "$ref": "#/$defs/ai_context"
        }
      },
      "additionalProperties": false,
      "oneOf": [
        {
          "required": [
            "flag"
          ]
        },
        {
          "required": [
            "attribute"
          ]
        },
        {
          "required": [
            "rollup"
          ]
        }
      ]
    },
    "lifecycle_flags": {
      "oneOf": [
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "rollup": {
                "description": "Adds a column with the rollup's value from a child entity, 0 when the anchor has none. Use `from: <child>.history` with `of`: `daana dar check` refuses a rollup flag from a stream (`DAR019`), which would hold the child's event time and not 0 or 1. For a 0/1 column from the child's events, give a `rollup` milestone a `flag_name`. A rollup flag makes Daana build the lifecycle from history, as `milestones` describes.",
                "$ref": "#/$defs/rollup"
              },
              "expr": {
                "description": "Defines a flag that is 1 on each of the entity's history rows where this SQL condition holds, for `flag` milestones to name. Daana uses it only in a lifecycle built from the stream, when the document's `stream` declares no flags and fewer than two outputs set `from: stream`. Daana adds no column for it, and `daana dar check` refuses a `flag` milestone that names it where it is not computed (`DAR021`). `daana dar check` refuses it in a lifecycle built from history (`DAR019`), and so beside a `rollup`, which makes the lifecycle one. Elsewhere, where it is not used, changing it gives the anchor a new revision.",
                "$ref": "#/$defs/expr"
              },
              "description": {
                "description": "Describes the flag for readers of the document. Daana does not read it.",
                "type": "string"
              },
              "ai_context": {
                "description": "Holds hints for AI assistants about the flag. Daana does not read it.",
                "$ref": "#/$defs/ai_context"
              }
            },
            "additionalProperties": false
          }
        }
      ]
    },
    "spine_period": {
      "type": "object",
      "required": [
        "start",
        "period"
      ],
      "properties": {
        "start": {
          "description": "Sets the date the calendar starts at: the first row is for the period that contains it. Daana leaves out the current period, so the last row is for the last complete period before today. On Snowflake, the calendar covers at most 5,000 days from `start` for `day`, 800 days for `isoweek`, and 600 months for `month`, so a longer calendar stops early.",
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "period": {
          "description": "Sets the length of one row's period and its column: `day` adds `snapshot_dt` with the date, `isoweek` adds `snapshot_week` with the Monday that starts the week, and `month` adds `snapshot_month` with the last day of the month. `snapshot_ts` holds the last moment of the period.",
          "enum": [
            "day",
            "isoweek",
            "month"
          ]
        }
      },
      "additionalProperties": false
    },
    "grains_block": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "spine": {
            "description": "Sets the calendar of this grain: Daana writes a row for each entity and each `period` from `start` to the last complete period, beginning with the entity's first stream row. The schema does not require `spine`, but `daana dar check` refuses a grain without it (`DAR020`).",
            "$ref": "#/$defs/spine_period"
          }
        },
        "additionalProperties": false
      }
    },
    "state_flags": {
      "oneOf": [
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        {
          "type": "object",
          "additionalProperties": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "required": [
                  "expr"
                ],
                "properties": {
                  "expr": {
                    "description": "Holds the SQL condition on the entity's state at the period end: the state flag's column is 1 when it holds and 0 otherwise.",
                    "type": "string"
                  },
                  "description": {
                    "description": "Describes the state flag for readers of the document. Daana does not read it.",
                    "type": "string"
                  }
                },
                "additionalProperties": false
              }
            ]
          }
        }
      ]
    },
    "snapshot_variant": {
      "type": "object",
      "properties": {
        "grains": {
          "description": "Lists the output's grains this variant is built for: Daana creates `fct__<anchor>_<grain>_snapshot__<variant>` for each, and compile refuses a grain the output does not declare. Without it, the variant covers every grain. Daana reads only the list form here: a map is accepted, but the variant then covers every grain.",
          "oneOf": [
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            {
              "$ref": "#/$defs/grains_block"
            }
          ]
        },
        "scope": {
          "description": "Limits the stream rows this variant reads: a name from the document's `scopes`, or an SQL condition. It replaces the output's `scope`. A `scope` on the document's `stream` still applies: the variant reads the rows that meet both conditions, whatever the number of outputs that set `from: stream`. Without it, the variant reads the rows the snapshot reads. Daana reads only a single string here; a list is accepted but not read.",
          "$ref": "#/$defs/scope"
        },
        "state_flags": {
          "description": "Lists the output's state flags this variant keeps; without it, the variant keeps all of them. Daana reads only the list form here: a map is accepted, but the variant then keeps all of the output's state flags with their own conditions.",
          "$ref": "#/$defs/state_flags"
        },
        "previous_of": {
          "description": "Replaces the output's `previous_of` for this variant, and `null` removes the previous column. Without it, the variant uses the output's setting.",
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "transition_counts": {
          "description": "Replaces the output's `transition_counts` for this variant, and an empty list removes them. Without it, the variant uses the output's list.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "keep_rows": {
          "description": "Replaces the output's `keep_rows` for this variant, with the same values. Without it, the variant uses the output's setting.",
          "type": "string"
        },
        "keys": {
          "description": "Replaces the output's `keys` for this variant. Without it, the variant uses the output's keys. Daana reads only the list form here: a map is accepted but gives the variant no key columns.",
          "$ref": "#/$defs/keys"
        },
        "wide": {
          "description": "Adds a `__wide` view for each of the variant's tables, as `wide` does on the output. A variant does not inherit the output's `wide`: without its own, it has no wide view.",
          "$ref": "#/$defs/wide"
        },
        "exclude_today": {
          "description": "Daana accepts this key in a variant but does not read it.",
          "$ref": "#/$defs/exclude_today"
        },
        "partition": {
          "description": "Daana accepts this key in a variant but does not read it: the variant's tables use the output's `partition`.",
          "$ref": "#/$defs/partition"
        },
        "cluster": {
          "description": "Daana accepts this key in a variant but does not read it: the variant's tables use the output's `cluster`.",
          "$ref": "#/$defs/cluster"
        },
        "publish": {
          "description": "Daana accepts this key in a variant but does not read it: the variant keeps the name `fct__<anchor>_<grain>_snapshot__<variant>`.",
          "$ref": "#/$defs/publish"
        }
      },
      "patternProperties": {
        "^x_": {
          "description": "Daana accepts any variant key that starts with `x_` and does not read it."
        }
      },
      "additionalProperties": false
    },
    "con_spine": {
      "type": "object",
      "properties": {
        "keys": {
          "description": "Lists the spine columns of a `fact.consolidated`, `grain` by default: Daana collects their distinct values from every leg and left joins each leg to them, and clusters generated Dataform SQLX by the first two unless `cluster` is set. A `reference.computed` does not use it in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "floor": {
          "description": "Maps a spine column to its lowest value: Daana drops spine rows below it. A `YYYY-MM-DD` value is a date; any other value is an SQL expression. A `reference.computed` does not use it in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "ceiling": {
          "description": "Daana accepts this key but does not read it, so no upper bound applies to the spine.",
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "null_safe": {
          "description": "Lists spine columns that Daana joins with `IS NOT DISTINCT FROM`, so a `NULL` in a leg matches a `NULL` in the spine. A template adds the `%{dimension}` column when it is a spine key. A `reference.computed` does not use it in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "driving": {
          "description": "On a `reference.computed` with `legs`, names the leg whose rows make the output: Daana takes the grain columns from it and left joins the other legs on the grain, and compile requires it. On a `fact.consolidated`, Daana does not use it in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "alignment": {
      "type": "object",
      "properties": {
        "b2b": {
          "description": "With `exclude`, a `fact.consolidated` drops from each leg every key of its one spine `*_key` entity that any version of the entity's dimension flags `<entity>_is_b2b = 1`; a leg reading a fact with `scope: b2c` is exempt. A `reference.computed` does not use it in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
          "enum": [
            "exclude"
          ]
        },
        "market_resolution": {
          "description": "Daana supports only `per_source_account_latest`: each leg of a `fact.consolidated` reads the spine's market column from the current row of the `account` dimension, joined on the leg's `account_key`, and compile refuses other values. A `reference.computed` does not use it in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
          "type": "string"
        },
        "currency": {
          "description": "Names the target currency of the output's `fx` conversions, and replaces the output's `currency` when both are set.",
          "type": "string"
        },
        "description_note": {
          "description": "Holds a note for readers of the document. Daana does not read it.",
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "leg_dab": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "object",
          "required": [
            "entity"
          ],
          "properties": {
            "entity": {
              "description": "Names the DAB entity whose latest view a `reference.computed` leg reads. `daana dar check` reports `DAR012` when the model has no such entity, or when the entity has no views of its own. Daana does not use `dab` on other legs.",
              "type": "string"
            },
            "latest": {
              "description": "Daana supports only `true`: a `reference.computed` leg reads only the entity's latest view, and `daana dar check` refuses `false` or a missing `latest` in this form (`DAR019`). The plain name form of `dab` means `true`.",
              "type": "boolean"
            },
            "delete_filter": {
              "description": "When `true`, a `reference.computed` leg keeps only rows that the entity's tombstone column does not mark as deleted; compile refuses it when the entity has no tombstone column. Default `false`.",
              "type": "boolean"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "leg": {
      "type": "object",
      "properties": {
        "fact": {
          "description": "In a `fact.consolidated`, names the published fact the leg reads, as `<anchor>.<output>`; add `.wide` for its wide companion or a grain name for a periodic snapshot. No other third part and no fourth part is read: `daana dar check` on a directory and compile refuse them, `.latest` and `.Wide` among them (`DAR007`). `table` takes precedence. `daana dar check` refuses `fact` on a `reference.computed` leg (`DAR019`).",
          "type": "string"
        },
        "from": {
          "description": "In a `fact.consolidated`, Daana reads it like `fact`, which takes precedence, except that a periodic snapshot read with `from` gives its `grain_keys` from the snapshot itself. In a `reference.computed`, it names a published output of the same document, and the leg reads it instead of `dab`.",
          "type": "string"
        },
        "dab": {
          "description": "In a `reference.computed`, names the DAB entity the leg reads from its latest view, and Daana drops rows dated today or later by the leg's `date`, as `exclude_today` describes. A `fact.consolidated` does not use `dab` in the SQL, and `daana dar check` refuses a leg there without `fact`, `from`, or `table` (`DAR020`).",
          "$ref": "#/$defs/leg_dab"
        },
        "table": {
          "description": "In a `fact.consolidated`, names an external table, such as `<dataset>.<table>`, that the leg reads directly; it takes precedence over `fact` and `from`. A `reference.computed` does not use it in the SQL, and `daana dar check` refuses a leg there without `from` or `dab` (`DAR020`).",
          "type": "string"
        },
        "attributes": {
          "description": "Daana accepts this block but does not read it.",
          "$ref": "#/$defs/source_attributes"
        },
        "at": {
          "description": "On a `fact.consolidated` or `reference.computed` leg, Daana does not use `at` in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
          "type": "string"
        },
        "scope": {
          "description": "On a `fact.consolidated` or `reference.computed` leg, Daana does not use `scope` in the SQL, so it filters no rows, but changing it gives the anchor a new revision on the next `daana dar apply`.",
          "$ref": "#/$defs/scope"
        },
        "map": {
          "description": "On a `fact.consolidated` or `reference.computed` leg, Daana does not use `map` in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "date": {
          "description": "Gives the SQL expression for the leg's date, which `fx` uses for its rate; without it, Daana uses the leg's one `month` or `*_month` grain column. In a `fact.consolidated`, it fills the first grain column that is also a spine key. On a `reference.computed` leg that reads `dab`, it decides the cut of `exclude_today`, which Daana reads from a column name, alone or inside one or more of parentheses, `CAST(<column> AS DATE)`, `CAST(<column> AS TIMESTAMP)`, `CAST(<column> AS DATETIME)`, `DATE(<column>)`, `LAST_DAY(<column>)`, and `END_OF_DAY(<column>)`; one name may qualify the column, as in `<name>.<column>`. `daana dar check` refuses a date it cannot read that way while `exclude_today` is on (`DAR019`).",
          "$ref": "#/$defs/expr"
        },
        "fx": {
          "description": "Converts the leg's `sum` aggregates to the output `currency` with rates from the `daily` output of the one document that declares `provides: fx`. Compile refuses it without an output currency or a date, and on an unaggregated leg.",
          "$ref": "#/$defs/fx"
        },
        "grain_keys": {
          "description": "In a `fact.consolidated`, lists grain columns only this leg carries; Daana keeps its rows unaggregated, and at most one leg may do this. From a periodic snapshot that the leg names with `fact`, a name without `_key` comes from its anchor's dimension at `snapshot_ts`. A `reference.computed` does not use it in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "aggregates": {
          "description": "Names the leg's aggregates; each key is an output column name unless the aggregate is `hidden`.",
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/aggregate"
          }
        }
      },
      "patternProperties": {
        "^x_": {
          "description": "Daana accepts any key that starts with `x_` as an extension and does not read it: it binds no grain column, and changing it gives the anchor no new revision."
        }
      },
      "additionalProperties": {
        "description": "Binds a grain column of the output, named by the key, to a value of the leg: a column of its source, an SQL expression in `expr`, or an attribute of a related entity in `via`. A `reference.computed` computes the grain column from it, matching the key to the grain column with that name or a unique suffix of it. A `fact.consolidated` does not use the value: it selects each spine column under its own name, but changing it gives the anchor a new revision.",
        "$ref": "#/$defs/key_part"
      }
    },
    "union_leg": {
      "type": "object",
      "properties": {
        "fact": {
          "description": "Names the published output the leg reads, as `<anchor>.<output>`; add `.wide` for its wide companion or a grain name for a periodic snapshot. No other third part and no fourth part is read: `daana dar check` on a directory and compile refuse them, `.latest` and `.Wide` among them (`DAR007`). `table` takes precedence.",
          "type": "string"
        },
        "from": {
          "description": "Daana reads it like `fact`, which takes precedence when both are set.",
          "type": "string"
        },
        "dab": {
          "description": "Daana does not use `dab` on a union leg in the SQL, and `daana dar check` refuses a leg without `fact`, `from`, or `table` (`DAR020`).",
          "$ref": "#/$defs/leg_dab"
        },
        "table": {
          "description": "Names an external table, such as `<dataset>.<table>`, that the leg reads directly; it takes precedence over `fact` and `from`.",
          "type": "string"
        },
        "attributes": {
          "description": "Daana accepts this block but does not read it.",
          "$ref": "#/$defs/source_attributes"
        },
        "scope": {
          "description": "Filters the leg's rows, by a name under `scopes` or an SQL condition. `daana dar check` refuses a list here: write one condition, with `AND` between its parts.",
          "type": "string",
          "minLength": 1
        },
        "at": {
          "description": "Names the leg's timestamp column, which `cutoff` compares. When the output sets `cutoff`, `daana dar check` refuses a leg without it (`DAR020`) or with a value that is not a column name (`DAR019`). Without `cutoff`, Daana does not use it in the SQL.",
          "type": "string"
        },
        "map": {
          "description": "Maps a contract column to the SQL expression that fills it in this leg, in place of the output's `leg_map`. A column without one reads the leg's column of the same name.",
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        }
      },
      "patternProperties": {
        "^x_": {
          "description": "Daana accepts any key that starts with `x_` as an extension and does not read it: changing it gives the anchor no new revision."
        }
      },
      "additionalProperties": false
    },
    "union_legs": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "members"
          ],
          "properties": {
            "members": {
              "description": "Makes one leg for each output of a family instead of named legs; each leg's name is the output's key. With `via`, the legs are the outputs that one member template creates; without it, the outputs that declare the family.",
              "type": "object",
              "required": [
                "family"
              ],
              "properties": {
                "family": {
                  "description": "Names the family whose outputs become the legs; with `via`, it must be the family of that template.",
                  "oneOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "object",
                      "required": [
                        "name",
                        "as"
                      ],
                      "properties": {
                        "name": {
                          "description": "Names the family.",
                          "type": "string"
                        },
                        "as": {
                          "description": "Daana does not read this key. With `via`, each output of the template supplies `%{metric}`; without `via`, nothing supplies it, even when the members declare `family.as`, and `daana dar check` refuses `%{metric}` in `leg_map` (`DAR019`).",
                          "type": "string"
                        }
                      },
                      "additionalProperties": false
                    }
                  ]
                },
                "via": {
                  "description": "Names the key of a templated `fact.consolidated`: every output it creates becomes a leg, and Daana fills `%{metric}` and `%{dimension}` in `leg_map` from each. With `members` and no `via`, the legs are the family's own outputs, nothing fills those tokens, and `daana dar check` refuses them in `leg_map` (`DAR019`).",
                  "type": "string"
                }
              },
              "additionalProperties": false
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/union_leg"
          }
        }
      ]
    },
    "members": {
      "type": "object",
      "required": [
        "family"
      ],
      "properties": {
        "family": {
          "description": "Names the family a template expands over: each output in the documents that declares `family` with this name, and each must declare `family.as`. `daana dar check` refuses `members` on a `fact.union` or `reference.computed` (`DAR019`).",
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "object",
              "required": [
                "name",
                "as"
              ],
              "properties": {
                "name": {
                  "description": "Names the family.",
                  "type": "string"
                },
                "as": {
                  "description": "Daana accepts this key but does not read it; each member's own `family.as` supplies `%{metric}`.",
                  "type": "string"
                }
              },
              "additionalProperties": false
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "windows": {
      "type": "object",
      "required": [
        "partition",
        "columns"
      ],
      "properties": {
        "partition": {
          "description": "Lists the columns or SQL expressions that split the rows into partitions; Daana computes each window column and the anchor flag within one partition.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "order": {
          "description": "Gives the column or SQL expression that orders rows within a partition. Daana uses it for `first_value`, `last_value`, and `anchor_flag`, and compile refuses `anchor_flag` without it.",
          "type": "string"
        },
        "columns": {
          "description": "Names the window columns Daana adds; every source row stays in the output.",
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "required": [
              "fn",
              "of"
            ],
            "properties": {
              "fn": {
                "description": "Names the window function Daana applies to `of` within the partition. `first_value` and `last_value` follow `order` across the whole partition; the other functions use every row of the partition.",
                "enum": [
                  "sum",
                  "count",
                  "min",
                  "max",
                  "avg",
                  "first_value",
                  "last_value"
                ]
              },
              "of": {
                "description": "Gives the column or SQL expression that the window function reads.",
                "type": "string"
              },
              "hidden": {
                "description": "Computes the window column but leaves it out of the output columns, so `derive` can still use it.",
                "type": "boolean"
              },
              "description": {
                "description": "Describes the column for readers of the document. Daana does not read it.",
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "anchor_flag": {
          "description": "Adds a true or false column that marks one row in each partition: the first or the last by `order`.",
          "type": "object",
          "required": [
            "name",
            "pick"
          ],
          "properties": {
            "name": {
              "description": "Names the flag column.",
              "type": "string"
            },
            "pick": {
              "description": "`first` marks the row with the lowest `order` value in each partition, and `last` the row with the highest.",
              "enum": [
                "first",
                "last"
              ]
            },
            "description": {
              "description": "Describes the flag column for readers of the document. Daana does not read it.",
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "weight": {
      "type": "object",
      "required": [
        "policy",
        "description"
      ],
      "properties": {
        "policy": {
          "description": "Says how Daana computes the weight. `equal` gives each row 1 divided by the number of rows of its anchor entity in the bridge, and `within_group` weighs the pairs of one group. Daana does not build `shares` and `expr`, and `daana dar check` refuses them (`DAR019`).",
          "oneOf": [
            {
              "const": "equal"
            },
            {
              "type": "object",
              "required": [
                "within_group"
              ],
              "properties": {
                "within_group": {
                  "description": "Weighs only the pairs whose `to` entity has the value `equals` in the column `by`. Each such pair gets 1 divided by the number of the anchor entity's pairs with that value, and every other pair gets 0.",
                  "type": "object",
                  "required": [
                    "by",
                    "equals"
                  ],
                  "properties": {
                    "by": {
                      "description": "Names the column of the `to` entity's latest dimension, `dim__<to>__latest`, whose value groups the pairs. Write the plain column name or `{to.latest.<column>}`.",
                      "type": "string"
                    },
                    "equals": {
                      "description": "Holds the value of `by` that selects the weighted pairs, as a string or a number. `daana dar check` refuses another type, such as `true`, `null`, a list or a map, and a string that contains a single quote or a backslash (`DAR019`)."
                    }
                  },
                  "additionalProperties": false
                }
              },
              "additionalProperties": false
            },
            {
              "type": "object",
              "required": [
                "shares"
              ],
              "properties": {
                "shares": {
                  "description": "Daana does not build this policy, and `daana dar check` refuses it (`DAR019`).",
                  "type": "object",
                  "required": [
                    "by",
                    "values"
                  ],
                  "properties": {
                    "by": {
                      "description": "Daana does not read this key: it does not build the `shares` policy, which `daana dar check` refuses (`DAR019`).",
                      "type": "string"
                    },
                    "values": {
                      "description": "Daana does not read this key: it does not build the `shares` policy, which `daana dar check` refuses (`DAR019`).",
                      "type": "object"
                    },
                    "normalize": {
                      "description": "Daana does not read this key: it does not build the `shares` policy, which `daana dar check` refuses (`DAR019`).",
                      "enum": [
                        "present_groups",
                        "none"
                      ]
                    }
                  },
                  "additionalProperties": false
                }
              },
              "additionalProperties": false
            },
            {
              "type": "object",
              "required": [
                "expr"
              ],
              "properties": {
                "expr": {
                  "description": "Daana does not build this policy, and `daana dar check` refuses it (`DAR019`).",
                  "$ref": "#/$defs/expr"
                }
              },
              "additionalProperties": false
            }
          ]
        },
        "description": {
          "description": "Describes the weight for readers of the document. Daana does not read it.",
          "type": "string"
        },
        "assert": {
          "description": "`daana dar check` accepts this key, but Daana does not read it and adds no check that the weights sum to one.",
          "enum": [
            "sum_to_one",
            "sum_to_one_within_group",
            "none"
          ]
        }
      },
      "additionalProperties": false
    },
    "ea_attribute": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "required": [
            "type_key",
            "cell"
          ],
          "properties": {
            "type_key": {
              "description": "No field of a DAR document uses this definition, so Daana never reads this key. An `entity_assembly` lists attribute names in `attributes`, and Daana takes each type key from the DAB model.",
              "type": "integer"
            },
            "cell": {
              "description": "No field of a DAR document uses this definition, so Daana never reads this key. Daana chooses the value column of each `entity_assembly` attribute from the attribute's type in the DAB model.",
              "enum": [
                "val_str",
                "val_num",
                "sta_tmstp",
                "end_tmstp"
              ]
            },
            "description": {
              "description": "No field of a DAR document uses this definition, so Daana never reads this text.",
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "description": {
              "description": "No field of a DAR document uses this definition, so Daana never reads this text.",
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "stage": {
      "type": "object",
      "properties": {
        "fact": {
          "description": "Names the published fact the stage reads, as `<anchor>.<output>`; add `.wide` for its wide companion or a grain name for a periodic snapshot. No other third part and no fourth part is read: `daana dar check` on a directory and compile refuse them, `.latest` and `.Wide` among them (`DAR007`). `daana dar check` refuses a stage without it (`DAR020`), and on a directory reports `DAR007` when it does not resolve.",
          "type": "string"
        },
        "from": {
          "description": "Daana accepts this key but does not read it; `daana dar check` refuses a stage without `fact` (`DAR020`).",
          "type": "string"
        },
        "axis": {
          "description": "Names the stage's time column, which Daana selects under the output's axis name. Without it, Daana reads the column with the output's axis name, or `fact_ts` from a `fact.event`.",
          "type": "string"
        },
        "keys": {
          "description": "Lists the stage's key columns, and Daana adds `_key` to a name without it. The output has every stage's keys; a stage gives `NULL` for keys it does not list.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "measures": {
          "description": "Lists the stage's measure columns; other stages give `NULL` for them. Daana reads only each measure's `name`.",
          "$ref": "#/$defs/measures"
        },
        "columns": {
          "description": "Lists other columns the stage carries; other stages give `NULL` for them.",
          "$ref": "#/$defs/columns_list"
        }
      },
      "patternProperties": {
        "^x_": {
          "description": "Daana accepts any stage key that starts with `x_` and does not read it."
        }
      },
      "additionalProperties": false
    },
    "output": {
      "type": "object",
      "required": [
        "kind"
      ],
      "patternProperties": {
        "^x_": {
          "description": "Daana accepts any output key that starts with `x_` and does not read it."
        }
      },
      "properties": {
        "kind": {
          "description": "Selects what the output is, which decides the object Daana creates and the other keys the output takes. A document anchored on `consumer` takes only the `serve` kinds, and documents on other anchors take every other kind.",
          "enum": [
            "dimension",
            "fact.event",
            "fact.state",
            "fact.projection",
            "fact.periodic_snapshot",
            "fact.lifecycle",
            "fact.consolidated",
            "fact.union",
            "fact.unified_star",
            "bridge",
            "entity_assembly",
            "reference.computed",
            "reference.static",
            "reference.external",
            "serve.view",
            "serve.table"
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "dimension"
              }
            }
          },
          "then": {
            "properties": {
              "kind": {
                "description": "Makes the output a type 2 dimension: one row per version of the anchor entity, with `valid_from` and `valid_to`. Daana names it `dim__<anchor>`."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "backdated": {
                "description": "With `true`, each entity's first version in the dimension starts at `0001-01-01 00:00:00`, or at the `history_start` constant of `workspace.yaml`, instead of at its effective timestamp, so a query at an earlier time finds that version. The default, `false`, starts it at its effective timestamp.",
                "type": "boolean"
              },
              "dedup": {
                "description": "With `true`, Daana keeps one row for each entity and effective timestamp before it builds the versions, so a duplicate load of one instant gives one version. Which of the duplicates it keeps is not defined. The default, `false`, keeps every row. The latest object is not affected.",
                "type": "boolean"
              },
              "delete_handling": {
                "description": "With `true`, Daana drops the versions in which the entity's deletion attribute, by default the one ending in `_is_deleted_in_source`, is not `0`, in the dimension and its latest object, and leaves that attribute out of the columns. Without this key, Daana does this whenever the entity has such an attribute. `daana dar check` refuses it, set to either value, on an entity without one (`DAR019`).",
                "type": "boolean"
              },
              "latest": {
                "description": "`view` adds a second object with each entity's current version, named like the dimension with `__latest` appended, and `table` creates that object as a table. `none`, the default, adds no such object. `daana dar check` on a directory refuses a reference to `<anchor>.<output>.latest` when it has none, with `DAR007`. Bridges, and `wide` picks with `join: latest`, read that object, and `daana dar check` on a directory refuses them when the entity's dimension there has none (`DAR021`).",
                "enum": [
                  "none",
                  "view",
                  "table"
                ]
              },
              "attributes": {
                "description": "Selects the attributes that become columns of the dimension and its latest object. `all`, the default, takes every attribute of the DAB entity, and a list takes the named attributes in its order. `daana dar check` refuses a listed name that is not an attribute of the entity named by `source.dab`, with `DAR015`.",
                "oneOf": [
                  {
                    "const": "all"
                  },
                  {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                ]
              },
              "scope": {
                "description": "Daana does not use this key on a dimension, which holds every version of every entity, but changing it gives the anchor a new revision on the next `daana dar apply`.",
                "$ref": "#/$defs/scope"
              },
              "describe": {
                "description": "Holds descriptions of the output's columns by column name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "describe_extra": {
                "description": "Holds additional descriptions of the output's columns by column name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "descriptions": {
                "description": "Holds descriptions by column or flag name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "checks": {
                "description": "Data quality checks on the output, by check name. `daana dar apply` runs them on DuckDB after it creates the outputs, on the output's main object and not on a `__latest` or `__wide` companion. Apply on another target and `daana dar generate` refuse a document that has checks.",
                "$ref": "#/$defs/checks_block"
              },
              "publish": {
                "description": "Overrides where Daana publishes the output. `name` replaces `dim__<anchor>`, and the `latest` companion becomes `<name>__latest`; `dataset` sets the `workspace.yaml` target that `daana dar generate` writes to. Bridges and `wide` views still join the dimension under its default names, in the default dataset: `daana dar check` on a directory refuses a bridge or `wide` view of a dimension renamed with `name` (`DAR021`).",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              },
              "hide": {
                "description": "`daana dar check` accepts this list, but Daana does not read it: every attribute that `attributes` selects stays a column.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "pattern": "^fact\\.(event|state|projection)$"
              }
            }
          },
          "then": {
            "properties": {
              "kind": {
                "description": "`fact.event` gives one row per history row of the stream, with its flags, in `fct__<anchor>_event`. `fact.state` gives one row per entity at its axis timestamp, in `fct__<anchor>`. `fact.projection` selects columns from the output in `from` or from a `source` table."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "from": {
                "description": "On a `fact.projection`, names an output of the same document to select from. Without `publish.name`, the projection takes that output's name, so `daana dar check` refuses it (`DAR020`) unless the output is an `entity_assembly`. Check on a directory refuses another document's output (`DAR021`), which Daana would plan without SQL. On a `fact.event`, two or more outputs with `from: stream`, a `fact.state` included although it does not read the stream, make Daana compute the stream once in `intm__<anchor>_event`.",
                "type": "string"
              },
              "source": {
                "description": "On a `fact.projection` without `from`, names the table to select from and its columns, in place of the document's `source`, but only when it has `table`: without `table`, Daana reads the document's `source` and ignores these `attributes`; Daana creates the projection only when `publish.name` names it. Daana does not read `dab` here. A `fact.event` or `fact.state` does not compile `source`; changing it only gives the anchor a new revision.",
                "$ref": "#/$defs/source"
              },
              "scope": {
                "description": "Filters the output's rows, by a name under `scopes` or an SQL condition. A `fact.event` filters its stream rows and a `fact.projection` its source rows; a `fact.state` does not use it, but changing it gives the anchor a new revision. A stream `scope` replaces an event's when fewer than two outputs name `from: stream`. Daana ignores the list form.",
                "$ref": "#/$defs/scope"
              },
              "axis": {
                "description": "The time that dates each row. A `fact.state` adds it as a column, reads its `keys` at it, and by default leaves out rows dated today; with `keys` it needs one, as `keys` describes. A `fact.projection` names an existing column with it for `exclude_today` and its `wide` view. A `fact.event` is always dated by `fact_ts`, the effective timestamp of its stream row; it reads `name` only for its `wide` view and generate's default partition, so `daana dar check` refuses another name there (`DAR021`).",
                "$ref": "#/$defs/axis"
              },
              "conditions": {
                "description": "On a `fact.event`, names SQL conditions on each entity's stream rows in time order, where `{prev.column}` reads the entity's previous row; a flag with `from` fires where its condition holds. Daana uses them only when the document's `stream` declares no `conditions` and fewer than two outputs read `from: stream`. A `fact.state` or `fact.projection` does not compile them.",
                "$ref": "#/$defs/conditions_block"
              },
              "guards": {
                "description": "Daana does not read `guards` on an output: a flag's `unless` reads only the guards of the document's `stream`, and `daana dar check` refuses an `unless` that names an output guard (`DAR019`).",
                "$ref": "#/$defs/conditions_block"
              },
              "flags": {
                "description": "On a `fact.event`, chooses the 0/1 flag columns: `all` or no `flags` takes every flag of the document's `stream`, a list the named ones, and a map defines flags when the `stream` has none and fewer than two outputs read `from: stream`. `daana dar check` refuses a named flag that nothing computes (`DAR021`), and an event with no flag or condition (`DAR020`) unless two or more outputs read `from: stream`. A `fact.state` computes map entries with `expr` on the entity's current row, check refuses `from` entries (`DAR019`), and Daana ignores a list or `all`. A `fact.projection` ignores `flags`.",
                "oneOf": [
                  {
                    "const": "all"
                  },
                  {
                    "$ref": "#/$defs/flags_block"
                  },
                  {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                ]
              },
              "derive": {
                "description": "Adds named columns computed from SQL expressions. On a `fact.state`, `{axis}` stands for the axis column and `{lookup.column}` for a column of a lookup. On a `fact.event`, Daana computes them on each stream row, where `{prev.column}` reads the entity's previous row. On a `fact.projection`, the derived columns come before the listed `columns`, or after the source's columns when `columns` is omitted.",
                "$ref": "#/$defs/derive_block"
              },
              "measures": {
                "description": "Lists the output's measures. A `fact.state` or `fact.event` selects them as it selects `columns` and lists them first among the fact columns of its `wide` view. A `fact.projection` does not select them; only its `wide` view lists them. On a `fact.event` whose document `stream` lists no `columns`, `daana dar check` refuses a measure that is not also among its `columns` (`DAR021`), unless two or more outputs read `from: stream`.",
                "$ref": "#/$defs/measures"
              },
              "columns": {
                "description": "Lists the columns to select. A `fact.state` reads them from the anchor entity's current row, and a `fact.event` from each stream row, so with a document `stream` they must be among its `columns`, and `daana dar check` refuses one that is not (`DAR021`) unless two or more outputs read `from: stream`; `daana dar check` refuses a name the entity lacks (`DAR015`). On a `fact.projection`, omitted `columns` select every column except `drop`, and without `from`, `source.attributes` replaces them when present.",
                "$ref": "#/$defs/columns_list"
              },
              "drop": {
                "description": "On a `fact.projection`, removes the named columns: from `columns`, or, without `columns`, from every column of its source. A `fact.event` or `fact.state` does not compile it; changing it only gives the anchor a new revision.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "keys": {
                "description": "Lists relationship roles whose keys Daana adds as `<role>_key` columns: for `changes: never` the current key, for `tracked` the key valid at the row's time. A `via` role is read in two steps, each as its own document declares it, or at the row's time without the middle document. A `fact.state` with `keys` needs an `axis`, the time it reads them at: `daana dar check` refuses one without (`DAR020`), unless the document's relationships are all `changes: never` and it has a `fact.state` with `lookups` or a `wide` view with `join: latest`, which makes Daana read the keys on the anchor's key alone. In a document with an `entity_assembly`, `daana dar check` refuses the `keys` of a `fact.state` and a `fact.event` (`DAR021`), as `relationships` describes. On a `fact.projection`, a list adds no column, and a map adds computed keys only without `from`.",
                "$ref": "#/$defs/keys"
              },
              "lookups": {
                "description": "On a `fact.state`, each entry joins another output on that output's `grain`, and `derive` reads the joined row as `{name.column}`. A `fact.event` or `fact.projection` does not compile lookups, but `daana dar check` on a directory refuses a `from` that does not resolve (`DAR007`).",
                "$ref": "#/$defs/lookups_block"
              },
              "wide": {
                "description": "Adds the view `<fact>__wide`: the fact's rows with dimension columns joined on their keys. The axis, the anchor key, and the relationship keys come first, then the picked columns, then the other fact columns. A `fact.state` needs an `axis`; a `fact.projection` needs an `axis`, an anchor key, and its column list, from `columns`, `source.attributes`, or an `entity_assembly`.",
                "$ref": "#/$defs/wide"
              },
              "describe": {
                "description": "Holds descriptions of the output's columns by column name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "describe_extra": {
                "description": "Holds additional descriptions of the output's columns by column name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "descriptions": {
                "description": "Holds descriptions by column or flag name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "checks": {
                "description": "Data quality checks on the output, by check name. `daana dar apply` runs them on DuckDB after it creates the outputs, on the output's main object and not on a `__latest` or `__wide` companion. Apply on another target and `daana dar generate` refuse a document that has checks.",
                "$ref": "#/$defs/checks_block"
              },
              "grain": {
                "description": "Lists the columns that identify one row of this output. Daana reads it only when a `lookups` entry names this output: the lookup joins on these columns, in order. It changes nothing in this output's own SQL.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "exclude_today": {
                "description": "Drops the rows dated today or later by the time axis. A `fact.event` does so by default, a `fact.state` by default when it has an `axis`, and a `fact.projection` only with `true`, which needs `axis.name`, or by default when it reads an `entity_assembly`. A string counts as `false`. `daana dar check` requires the key when `axis` is derived, with `DAR002`.",
                "$ref": "#/$defs/exclude_today"
              },
              "delete_handling": {
                "description": "On a `fact.state`, `true` keeps only rows not deleted in the source, and `false` keeps them all. Without it, Daana filters when the entity has a deletion attribute, by default one ending in `_is_deleted_in_source`; when it has none, `daana dar check` refuses either value (`DAR019`). A `fact.event` or `fact.projection` does not compile it; changing it only gives the anchor a new revision.",
                "type": "boolean"
              },
              "partition": {
                "description": "Sets the BigQuery partitioning of the table that `daana dar generate` writes. Without it, generate partitions an event fact by the month of `axis.name`, `fact_ts` by default, a state fact by month only when its `axis.expr` uses `eff_tmstp` or `end_of_day`, and a projection of an `entity_assembly` by the assembly's partitioning. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/partition"
              },
              "cluster": {
                "description": "Sets the BigQuery clustering columns of the table that `daana dar generate` writes. Without it, generate clusters an event or state fact by `<anchor>_key`, and a projection of an `entity_assembly` takes the assembly's declared `cluster`, if any. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/cluster"
              },
              "materialize": {
                "description": "`table` makes the output a table and `view` a view; without it, `daana dar apply` makes a view and `daana dar generate` a Dataform table. Apply treats a `__wide` companion the same way; generate always writes it as a view. An applied table holds what the last apply wrote. `daana dar apply` refuses to change a published view to a table, or a table to a view, on every database: set this before the output's first apply, or drop the published object and apply again.",
                "$ref": "#/$defs/materialize"
              },
              "publish": {
                "description": "Overrides where Daana publishes the output. `name` replaces the default object name, and a `__wide` companion becomes `<name>__wide`; `dataset` sets the `workspace.yaml` target that `daana dar generate` writes to. Daana creates an object for a `fact.projection` with its own `source` and no `from` only when it has `name`.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              },
              "prior_guards": {
                "description": "Daana accepts this key but does not read it.",
                "$ref": "#/$defs/conditions_block"
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "fact.periodic_snapshot"
              }
            }
          },
          "then": {
            "properties": {
              "kind": {
                "description": "Makes the output a periodic snapshot: for each entity and period, its state at the period end and its flag counts within the period. Daana creates `fct__<anchor>_<grain>_snapshot` for each grain and `fct__<anchor>_<grain>_snapshot__<variant>` for each variant."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "from": {
                "description": "A snapshot reads the document's `stream`, or the anchor's history without one, whether or not it sets `from`. When two or more outputs set `from: stream`, Daana builds the stream once as `intm__<anchor>_event`, with the stream's `keep_rows` applied, and the snapshot reads that. `daana dar check` refuses `stream` without a `stream` block (`DAR007`).",
                "type": "string"
              },
              "scope": {
                "description": "Filters the stream rows that the snapshot reads, by a name under `scopes` or an SQL condition. A `scope` on the document's `stream` replaces this one. A variant's `scope` replaces it for that variant, and applies on top of the stream's `scope`. Daana ignores the list form.",
                "$ref": "#/$defs/scope"
              },
              "grains": {
                "description": "Names each grain with its calendar. Daana creates one fact `fct__<anchor>_<grain>_snapshot` per grain, plus a `__wide` view for each when the output has `wide`. The schema does not require `grains`, but `daana dar check` refuses a snapshot without it (`DAR020`).",
                "$ref": "#/$defs/grains_block"
              },
              "state_flags": {
                "description": "Adds one column per entry: 1 when its SQL condition holds for the entity's state at the period end, taken from its latest stream row at or before that moment, and 0 otherwise. Daana reads only the map form here: a list is accepted but adds no columns.",
                "$ref": "#/$defs/state_flags"
              },
              "previous_of": {
                "description": "Names one of the state flags. Daana adds `<flag>_previous_day`, `<flag>_previous_week`, or `<flag>_previous_month`, after the grain's period, with that flag's value for the entity's previous period, 0 for its first period. Without it, or with `null`, there is no such column. For a name that is not a state flag, Daana adds no column, and `daana dar check` refuses it when `keep_rows` is `any_flag` or `any_flag_or_state`, which would filter on that column (`DAR021`).",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "transition_counts": {
                "description": "Lists flags of the document's `stream`. Daana adds one column per flag with the number of the entity's stream rows in the period where the flag is 1, and 0 when there are none.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "keep_rows": {
                "description": "Chooses which rows Daana keeps. `any_flag` and `any_flag_or_state`, the default, both keep a row when a state flag, the previous column, or a transition count is above 0, and keep every row when the output has none of these. Any other value is an SQL condition on the row's columns.",
                "type": "string",
                "minLength": 1
              },
              "keys": {
                "description": "Lists relationships of the document. Daana adds `<role>_key` for each: the related key valid at the period end, or the current key for a `changes: never` relationship. Daana reads only the list form for a snapshot: a map is accepted but adds no columns. `daana dar check` refuses a role the document does not declare (`DAR011`), and `keys` in a document with an `entity_assembly` (`DAR021`), as `relationships` describes.",
                "$ref": "#/$defs/keys"
              },
              "wide": {
                "description": "Adds a `__wide` view for each grain that joins the listed dimension attributes, by default the version valid at `snapshot_ts`, the end of the period. Variants do not inherit it.",
                "$ref": "#/$defs/wide"
              },
              "variants": {
                "description": "Declares more snapshot facts from this output, each under a variant name. Daana creates `fct__<anchor>_<grain>_snapshot__<variant>` for each of the variant's grains, from the output's settings with the variant's changes. A variant has a wide view only when it declares its own `wide`.",
                "type": "object",
                "additionalProperties": {
                  "$ref": "#/$defs/snapshot_variant"
                }
              },
              "descriptions": {
                "description": "Holds descriptions by column or flag name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "checks": {
                "description": "Data quality checks on the output, by check name. `daana dar apply` runs them on DuckDB after it creates the outputs, on every grain's snapshot and on every variant's snapshot, not on `__wide` companions. `{self}` in a check names the snapshot the check runs on. Apply on another target and `daana dar generate` refuse a document that has checks.",
                "$ref": "#/$defs/checks_block"
              },
              "exclude_today": {
                "description": "Daana does not use this key on a periodic snapshot: the snapshot's SQL is the same with `true`, `false`, or no value, but changing it gives the anchor a new revision.",
                "$ref": "#/$defs/exclude_today"
              },
              "partition": {
                "description": "Sets the BigQuery partitioning of the tables that `daana dar generate` writes. Without it, generate partitions each snapshot by its period column. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/partition"
              },
              "cluster": {
                "description": "Sets the BigQuery clustering columns of the table that `daana dar generate` writes. Without it, generate clusters the table by `<anchor>_key`. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/cluster"
              },
              "materialize": {
                "description": "`table` makes the output a table and `view` a view; without it, `daana dar apply` makes a view and `daana dar generate` a Dataform table. Apply treats a `__wide` companion the same way; generate always writes it as a view. An applied table holds what the last apply wrote. `daana dar apply` refuses to change a published view to a table, or a table to a view, on every database: set this before the output's first apply, or drop the published object and apply again.",
                "$ref": "#/$defs/materialize"
              },
              "publish": {
                "description": "Overrides where Daana publishes the output. `daana dar check` accepts `name` only on a snapshot with one grain and no variants, as that grain's default name `fct__<anchor>_<grain>_snapshot`, followed by `__` and a suffix only when the output has no `wide`; it refuses any other name, and a name on a snapshot with more grains or with variants, of which Daana would create only the named table (`DAR019`). `dataset` sets the `workspace.yaml` target that `daana dar generate` writes to.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              },
              "columns": {
                "description": "Lists columns of the stream that Daana adds to each snapshot row, with their values from the entity's latest stream row at or before the period end. `daana dar check` refuses a name that the anchor's DAB view lacks (`DAR015`). When the document's `stream` lists `columns`, each name must be among them, or `daana dar check` refuses it (`DAR021`).",
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "fact.lifecycle"
              }
            }
          },
          "then": {
            "properties": {
              "kind": {
                "description": "Makes the output a lifecycle fact: one row per entity, with a `<anchor>_<milestone>_ts` timestamp for each milestone. Daana names it `fct__<anchor>_lifecycle`."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "from": {
                "description": "A lifecycle built from the stream reads the document's `stream`, or the anchor's history without one, whether or not it sets `from`. When two or more outputs set `from: stream`, Daana builds the stream once as `intm__<anchor>_event`, with the stream's `keep_rows` applied, and the lifecycle reads that. `daana dar check` refuses `stream` without a `stream` block (`DAR007`).",
                "type": "string"
              },
              "scope": {
                "description": "Filters the stream rows that the lifecycle's flag milestones read, by a name under `scopes` or an SQL condition. A stream `scope` replaces it when fewer than two outputs name `from: stream`. A lifecycle built from history, one with attribute or rollup milestones or flag rollups, does not read it, and `daana dar check` refuses it there (`DAR019`). Daana ignores the list form.",
                "$ref": "#/$defs/scope"
              },
              "keep_rows": {
                "description": "`any_milestone` keeps only the entities that reached at least one `flag` milestone. Without it, Daana keeps every entity in the stream. Daana reads no other value. A lifecycle built from history keeps every entity, and `daana dar check` refuses `any_milestone` there (`DAR019`).",
                "type": "string",
                "minLength": 1
              },
              "milestones": {
                "description": "Each entry adds a timestamp column `<anchor>_<name>_ts`. A milestone with `attribute` or `rollup`, or a flag with `rollup`, makes Daana build the lifecycle from history: one row per entity, without rows whose axis milestone is empty, today, or later. Such a lifecycle holds only `attribute` and `rollup` milestones and `rollup` flags: `daana dar check` refuses its `flag` milestones, `keys`, `keys_at`, `derived_milestones`, `keep_rows: any_milestone`, listed `flags` and `expr` flags (`DAR019`), which belong in a second `fact.lifecycle` output; that output needs a `publish.name` of its own, since both would otherwise be named `fct__<anchor>_lifecycle`. It also refuses `scope`, `partition.nulls: keep` and an `expr` beside a flag's `rollup` there (`DAR019`), which such a lifecycle does not read. The axis is the milestone `partition.month_of` names, else the first `attribute` milestone. `daana dar check` refuses a lifecycle without milestones (`DAR020`), which Daana would plan without SQL.",
                "type": "object",
                "additionalProperties": {
                  "$ref": "#/$defs/milestone"
                }
              },
              "derived_milestones": {
                "description": "Adds a timestamp column `<anchor>_<name>_ts` per entry from its `expr`, in which `{name}` stands for that milestone's timestamp and `{flag}` for a flag listed in `flags`. It also leaves out rows whose first milestone, or the one `partition.month_of` names, is empty, today, or later, unless `partition` sets `nulls: keep`. `daana dar check` refuses it in a lifecycle built from history (`DAR019`).",
                "$ref": "#/$defs/derive_block"
              },
              "flags": {
                "description": "As a list, names stream flags, and Daana adds a column per flag: 1 when the flag is 1 on any of the entity's stream rows. As a map, a `rollup` entry adds a column from a child entity, and an `expr` entry defines a flag that `flag` milestones can name, only when the document's `stream` declares no flags and fewer than two outputs read `from: stream`; otherwise `daana dar check` refuses a `flag` milestone that names it (`DAR021`). A lifecycle built from history holds only `rollup` entries: `daana dar check` refuses the list and every `expr` there, also one beside a `rollup` (`DAR019`).",
                "$ref": "#/$defs/lifecycle_flags"
              },
              "keys": {
                "description": "Lists relationships of the document. Daana adds `<role>_key` for each with its current key, whatever its `changes`, and reads a `via` role through both steps. It also leaves out rows whose first milestone, or the one `partition.month_of` names, is empty, today, or later, unless `partition` sets `nulls: keep`. A map adds no keys. `daana dar check` refuses `keys` in a lifecycle built from history (`DAR019`), and in a document with an `entity_assembly` (`DAR021`), as `relationships` describes.",
                "$ref": "#/$defs/keys"
              },
              "keys_at": {
                "description": "For each relationship, lists milestones. Daana adds `<role>_key_at_<milestone>` with the key valid at that milestone, or the current key for a `changes: never` relationship, empty when the milestone is. It also leaves out rows whose first milestone, or the one `partition.month_of` names, is empty, today, or later, unless `partition` sets `nulls: keep`. `daana dar check` refuses it in a lifecycle built from history (`DAR019`), and in a document with an `entity_assembly` (`DAR021`), as `relationships` describes.",
                "$ref": "#/$defs/keys_at"
              },
              "wide": {
                "description": "Adds a `__wide` view that joins the listed dimension attributes, by default the version valid at the axis milestone: the one `partition.month_of` names, else the first `attribute` milestone, else the first milestone. After the picked columns come the lifecycle's other milestones and its flag columns. For a lifecycle built from the stream, those are the flags that `flags` lists and the column that a milestone's `flag` adds, where it adds one; the view has no column for `flag_name` or for a flag that the lifecycle does not carry.",
                "$ref": "#/$defs/wide"
              },
              "descriptions": {
                "description": "Holds descriptions by column or flag name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "describe": {
                "description": "Holds descriptions of the output's columns by column name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "describe_extra": {
                "description": "Holds additional descriptions of the output's columns by column name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "checks": {
                "description": "Data quality checks on the output, by check name. `daana dar apply` runs them on DuckDB after it creates the outputs, on the output's main object and not on a `__latest` or `__wide` companion. Apply on another target and `daana dar generate` refuse a document that has checks.",
                "$ref": "#/$defs/checks_block"
              },
              "exclude_today": {
                "description": "Daana does not use this key on a lifecycle fact, but changing it gives the anchor a new revision. Instead, Daana drops rows whose axis milestone is missing, today, or later whenever the lifecycle has attribute or rollup milestones, flag rollups, `keys`, `keys_at`, `derived_milestones`, or `partition.month_of`. On a lifecycle whose milestones all come from flags, `partition.nulls: keep` keeps the missing ones.",
                "$ref": "#/$defs/exclude_today"
              },
              "partition": {
                "description": "With `month_of`, names the milestone that dates each row: Daana drops rows whose milestone is missing, today, or later, unless `nulls: keep` keeps the missing ones, and generate partitions by that milestone's month. A lifecycle built from history always drops the missing ones, and `daana dar check` refuses `nulls: keep` there (`DAR019`). Other forms only set the partitioning that `daana dar generate` writes. Generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/partition"
              },
              "cluster": {
                "description": "Sets the BigQuery clustering columns of the table that `daana dar generate` writes. Without it, generate clusters the table by `<anchor>_key`. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/cluster"
              },
              "materialize": {
                "description": "`table` makes the output a table and `view` a view; without it, `daana dar apply` makes a view and `daana dar generate` a Dataform table. Apply treats a `__wide` companion the same way; generate always writes it as a view. An applied table holds what the last apply wrote. `daana dar apply` refuses to change a published view to a table, or a table to a view, on every database: set this before the output's first apply, or drop the published object and apply again.",
                "$ref": "#/$defs/materialize"
              },
              "publish": {
                "description": "Overrides where Daana publishes the output. `name` replaces `fct__<anchor>_lifecycle`, and a `__wide` companion becomes `<name>__wide`; `dataset` sets the `workspace.yaml` target that `daana dar generate` writes to.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "pattern": "^(fact\\.consolidated|reference\\.computed)$"
              }
            }
          },
          "then": {
            "properties": {
              "kind": {
                "description": "`fact.consolidated` aggregates its legs to one row per combination of the `grain` columns, in `fct__<anchor>_<key>` after the output key. `reference.computed` computes a reference table from its legs or from the document's `source.table`, in `intm__<anchor>_<key>`."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "grain": {
                "description": "Lists the output's grain columns. A `fact.consolidated` groups the combined legs by them, uses them as the default spine keys, and takes a grain column outside the spine from a leg's `grain_keys`. In a `reference.computed`, each leg groups by them and binds each one by a key with its name or a unique suffix of it.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "currency": {
                "description": "Names the target currency of every leg `fx` conversion, as a text value. Compile refuses a leg with `fx` when the output has no currency. `alignment.currency` replaces it.",
                "type": "string"
              },
              "spine": {
                "description": "Sets how a `fact.consolidated` builds its spine: the distinct key combinations that every leg is joined to. A `reference.computed` reads only `driving`, which it requires when it has `legs`.",
                "$ref": "#/$defs/con_spine"
              },
              "alignment": {
                "description": "Holds rules for a `fact.consolidated` that apply across its legs: B2B exclusion, market resolution, and the target currency. A `reference.computed` uses only its `currency`.",
                "$ref": "#/$defs/alignment"
              },
              "legs": {
                "description": "Names the sources the output combines, each by a leg name. A `fact.consolidated` aggregates each leg to the spine keys, left joins all legs to the spine, and sums each aggregate to the grain; compile refuses it without legs. A `reference.computed` groups each leg by the grain and left joins the others to the `spine.driving` leg; without legs, it computes `windows`.",
                "type": "object",
                "additionalProperties": {
                  "$ref": "#/$defs/leg"
                }
              },
              "post": {
                "description": "Holds the `lookups` and `derive` that Daana applies after it combines the legs. Its `derive` replaces the output's `derive` when both are set.",
                "type": "object",
                "properties": {
                  "lookups": {
                    "description": "In a `fact.consolidated`, joins other outputs to the aggregated rows, matching each `key` to the target output's grain; `derive` reads their columns as `{lookup.column}`. A `reference.computed` does not use it in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
                    "$ref": "#/$defs/lookups_block"
                  },
                  "derive": {
                    "description": "Adds named SQL expressions as columns like the output's `derive`, and replaces that block when both are set.",
                    "$ref": "#/$defs/derive_block"
                  }
                },
                "additionalProperties": false
              },
              "windows": {
                "description": "On a `reference.computed` without `legs`, adds window columns over the rows of the document's `source.table`; every source row stays in the output. On a `fact.consolidated`, or a `reference.computed` with legs, Daana does not use it in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
                "$ref": "#/$defs/windows"
              },
              "derive": {
                "description": "Adds named SQL expressions as columns after the others. In a `fact.consolidated`, they read the aggregated rows and a lookup column as `{lookup.column}`; in a `reference.computed`, the leg results or the window columns. `post.derive` replaces this block when both are set.",
                "$ref": "#/$defs/derive_block"
              },
              "drop": {
                "description": "On a `fact.consolidated` or `reference.computed`, Daana does not use `drop` in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "descriptions": {
                "description": "Holds descriptions by column or flag name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "checks": {
                "description": "Data quality checks on the output, by check name. `daana dar apply` runs them on DuckDB after it creates the outputs, on the output's main object and not on a `__latest` or `__wide` companion. Apply on another target and `daana dar generate` refuse a document that has checks.",
                "$ref": "#/$defs/checks_block"
              },
              "members": {
                "description": "Makes a `fact.consolidated` a template: Daana creates one output for each member of the family and each `dimensions` value, and publishes no object for the template itself. A bare `%{metric}` as a leg's `fact` or `from` reads the member. `daana dar check` refuses `members` on a `reference.computed` (`DAR019`).",
                "$ref": "#/$defs/members"
              },
              "name_template": {
                "description": "Names each output that a template creates, and its object: `%{metric}` becomes the member's `family.as` and `%{dimension}` a `dimensions` value, and the result must be an identifier. Compile refuses a template without `members`, `name_template`, and `dimensions` together, and `daana dar check` refuses `name_template` on a `reference.computed` (`DAR019`).",
                "type": "string"
              },
              "dimensions": {
                "description": "Lists the values of `%{dimension}`: a template creates one output for each member and value. Without `members` and `name_template`, Daana does not use it in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. An output that has `members` itself does not read its own `family`.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              },
              "exclude_today": {
                "description": "On a `fact.consolidated`, Daana does not use it in the SQL, but changing it gives the anchor a new revision. On a `reference.computed`, each leg that reads `dab` drops rows whose leg `date` is today or later by default, and `false` or any string turns that off. Daana reads the cut from that date as a column name, alone or inside one or more of parentheses, `CAST(<column> AS DATE)`, `CAST(<column> AS TIMESTAMP)`, `CAST(<column> AS DATETIME)`, `DATE(<column>)`, `LAST_DAY(<column>)`, and `END_OF_DAY(<column>)`; one name may qualify the column, as in `<name>.<column>`. It compares the column itself. `daana dar check` refuses a date it cannot read that way while the cut is on (`DAR019`): set `exclude_today: false`, or write the date in one of those forms. A leg without a date has no cut.",
                "$ref": "#/$defs/exclude_today"
              },
              "partition": {
                "description": "Sets the BigQuery partitioning of the table that `daana dar generate` writes. Without it, generate partitions a `fact.consolidated` by the first grain column that is a spine key and does not end in `_key`, other than `account_market`, whatever its type, and leaves a `reference.computed` unpartitioned. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/partition"
              },
              "cluster": {
                "description": "Sets the BigQuery clustering columns of the table that `daana dar generate` writes. Without it, generate clusters a `fact.consolidated` by its first two spine or grain columns and leaves a `reference.computed` unclustered. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/cluster"
              },
              "materialize": {
                "description": "`table` makes the output a table and `view` a view; without it, `daana dar apply` makes a view and `daana dar generate` a Dataform table. On a `validation` anchor, generate writes the outputs of a `members` template as views. An applied table holds what the last apply wrote. `daana dar apply` refuses to change a published view to a table, or a table to a view, on every database: set this before the output's first apply, or drop the published object and apply again.",
                "$ref": "#/$defs/materialize"
              },
              "publish": {
                "description": "Overrides where Daana publishes the output. On a `fact.consolidated`, `name` replaces `fct__<anchor>_<key>`. On a `reference.computed`, `daana dar check` refuses `name` (`DAR019`): Daana would plan the object without SQL. `dataset` sets the `workspace.yaml` target that `daana dar generate` writes to.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "fact.union"
              }
            }
          },
          "then": {
            "properties": {
              "kind": {
                "description": "Makes the output a union: the rows of every leg, mapped onto the `contract` columns and stacked with `UNION ALL`. Daana names it `fct__<anchor>`, or `<anchor>_<key>` after the output key on a `validation` anchor."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              },
              "contract": {
                "description": "Lists the union's columns: each key is a column that every leg fills, and Daana orders them by name. Compile refuses a union without `contract`.",
                "type": "object",
                "additionalProperties": {
                  "type": "object",
                  "required": [
                    "description"
                  ],
                  "properties": {
                    "description": {
                      "description": "Describes the column for readers of the document. Daana does not read it.",
                      "type": "string"
                    },
                    "ai_context": {
                      "description": "Holds hints for AI assistants about the column. Daana does not read it.",
                      "$ref": "#/$defs/ai_context"
                    }
                  },
                  "additionalProperties": false
                }
              },
              "discriminator": {
                "description": "Adds a column that holds each row's leg name. Without it, the union has no such column.",
                "type": "object",
                "required": [
                  "column"
                ],
                "properties": {
                  "column": {
                    "description": "Names the column that holds each row's leg name.",
                    "type": "string"
                  },
                  "values_from": {
                    "description": "Daana does not read this key: the discriminator column always holds the leg names.",
                    "const": "leg_names"
                  }
                },
                "additionalProperties": false
              },
              "cutoff": {
                "description": "Gives a `YYYY-MM-DD` date: each leg keeps only rows whose `at` column falls on an earlier date. `daana dar check` refuses another format (`DAR019`), a leg without `at` (`DAR020`), and `cutoff` together with `legs.members`, whose legs have no `at` (`DAR019`).",
                "type": "string"
              },
              "legs": {
                "description": "Names the legs that Daana stacks with `UNION ALL`, or holds `members` to make one leg for each output of a family. Compile refuses a union without legs.",
                "$ref": "#/$defs/union_legs"
              },
              "leg_map": {
                "description": "Maps a contract column to the SQL expression that fills it in every leg; a leg's own `map` takes precedence. With `legs.members` and its `via`, Daana fills `%{metric}` and `%{dimension}` from each output the template creates. With `legs.members` and no `via`, `daana dar check` refuses the two tokens (`DAR019`). With legs listed by name, nothing fills the tokens and Daana writes them into the SQL as they stand.",
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              },
              "members": {
                "description": "`daana dar check` refuses `members` on a `fact.union` (`DAR019`): only a `fact.consolidated` can be a template.",
                "$ref": "#/$defs/members"
              },
              "name_template": {
                "description": "`daana dar check` refuses `name_template` on a `fact.union` (`DAR019`): only a `fact.consolidated` can be a template.",
                "type": "string"
              },
              "dimensions": {
                "description": "Daana does not use `dimensions` on a `fact.union` in the SQL, but changing it gives the anchor a new revision on the next `daana dar apply`.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "descriptions": {
                "description": "Holds descriptions by column or flag name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "checks": {
                "description": "Data quality checks on the output, by check name. `daana dar apply` runs them on DuckDB after it creates the outputs, on the output's main object and not on a `__latest` or `__wide` companion. Apply on another target and `daana dar generate` refuse a document that has checks.",
                "$ref": "#/$defs/checks_block"
              },
              "exclude_today": {
                "description": "Daana does not use this key on a union, but changing it gives the anchor a new revision; each leg brings its rows as its source has them.",
                "$ref": "#/$defs/exclude_today"
              },
              "partition": {
                "description": "Sets the BigQuery partitioning of the table that `daana dar generate` writes; without it, generate does not partition the table. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/partition"
              },
              "cluster": {
                "description": "Sets the BigQuery clustering columns of the table that `daana dar generate` writes; without it, generate does not cluster the table. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/cluster"
              },
              "materialize": {
                "description": "`table` makes the output a table and `view` a view; without it, `daana dar apply` makes a view and `daana dar generate` a Dataform table. On a `validation` anchor, generate decides itself: a view, or a table when `legs.members` has `via`. An applied table holds what the last apply wrote. `daana dar apply` refuses to change a published view to a table, or a table to a view, on every database: set this before the output's first apply, or drop the published object and apply again.",
                "$ref": "#/$defs/materialize"
              },
              "publish": {
                "description": "Overrides where Daana publishes the output. `name` replaces the default object name; `dataset` sets the `workspace.yaml` target that `daana dar generate` writes to.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "fact.unified_star"
              }
            }
          },
          "then": {
            "required": [
              "stages"
            ],
            "properties": {
              "kind": {
                "description": "Makes the output a unified star: the rows of each stage's fact stacked on one shared time axis, with a column that names the stage. Daana names it `fct__<anchor>`, or `<anchor>_<key>` after the output key on a `validation` anchor."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "axis": {
                "description": "Names the output's time column, `fact_ts` by default; each stage's time column appears under this name. Daana uses only the axis `name` in the SQL.",
                "$ref": "#/$defs/axis"
              },
              "discriminator": {
                "description": "Names the column that holds each row's stage name. Without it, Daana names that column `stage`.",
                "type": "object",
                "required": [
                  "column"
                ],
                "properties": {
                  "column": {
                    "description": "Names the column that holds each row's stage name.",
                    "type": "string"
                  }
                },
                "additionalProperties": false
              },
              "stages": {
                "description": "Names the facts that Daana stacks with `UNION ALL`, one stage each; the stage name fills the discriminator column, and a column that a stage lacks is `NULL`.",
                "type": "object",
                "minProperties": 1,
                "additionalProperties": {
                  "$ref": "#/$defs/stage"
                }
              },
              "include_dimensions": {
                "description": "Daana accepts this key but does not read it: the unified star includes no dimension stages.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "descriptions": {
                "description": "Holds descriptions by column or flag name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "checks": {
                "description": "Data quality checks on the output, by check name. `daana dar apply` runs them on DuckDB after it creates the outputs, on the output's main object and not on a `__latest` or `__wide` companion. Apply on another target and `daana dar generate` refuse a document that has checks.",
                "$ref": "#/$defs/checks_block"
              },
              "exclude_today": {
                "description": "Daana does not use this key on a unified star, but changing it gives the anchor a new revision. `daana dar check` still requires it, with `DAR002`, when `axis` is a derived expression.",
                "$ref": "#/$defs/exclude_today"
              },
              "partition": {
                "description": "Sets the BigQuery partitioning of the table that `daana dar generate` writes; without it, generate does not partition the table. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/partition"
              },
              "cluster": {
                "description": "Sets the BigQuery clustering columns of the table that `daana dar generate` writes; without it, generate does not cluster the table. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/cluster"
              },
              "materialize": {
                "description": "`table` makes the output a table and `view` a view; without it, `daana dar apply` makes a view and `daana dar generate` a Dataform table. An applied table holds what the last apply wrote. `daana dar apply` refuses to change a published view to a table, or a table to a view, on every database: set this before the output's first apply, or drop the published object and apply again.",
                "$ref": "#/$defs/materialize"
              },
              "publish": {
                "description": "Overrides where Daana publishes the output. `name` replaces the default object name; `dataset` sets the `workspace.yaml` target that `daana dar generate` writes to.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "bridge"
              }
            }
          },
          "then": {
            "required": [
              "to",
              "weights"
            ],
            "properties": {
              "kind": {
                "description": "Makes the output a bridge: one row per pair of an anchor entity and a related entity in `to`, with a weight column for each entry under `weights`. Daana names it `brg__<anchor>_<to>`, or `brg__<to>` when `to` already starts with `<anchor>_`."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "to": {
                "description": "Names the entity that each row pairs with the anchor entity. Daana reads the pairs from the DAB relationship between them, adds `<anchor>_key` and `<to>_key`, and names the output `brg__<anchor>_<to>`, or `brg__<to>` when `to` begins with the anchor's name and an underscore. `daana dar check` refuses an entity the model lacks or does not relate to the anchor, with `DAR012` or `DAR016`.",
                "type": "string"
              },
              "weights": {
                "description": "Adds one weight column for each entry, named by the entry's key, after the two key columns and in alphabetical order.",
                "type": "object",
                "additionalProperties": {
                  "$ref": "#/$defs/weight"
                }
              },
              "to_scope": {
                "description": "Filters `dim__<to>__latest`, the `to` entity's latest dimension, by a name under `scopes` or an SQL condition on its columns. Pairs whose `to` entity fails it are treated like pairs without a `to` row, as `on_missing_to` says. `daana dar check` refuses a list here: write one condition, with `AND` between its parts.",
                "type": "string",
                "minLength": 1
              },
              "on_missing_to": {
                "description": "Says what happens to a pair whose `to` entity has no row in `dim__<to>__latest` or fails `to_scope`. `drop`, the default, removes the pair. `keep` keeps it with `within_group` weights of 0, and `equal` weights count it.",
                "enum": [
                  "drop",
                  "keep"
                ]
              },
              "materialize": {
                "description": "`table` makes the output a table and `view` a view; without it, `daana dar apply` makes a view and `daana dar generate` a Dataform table. An applied table holds what the last apply wrote. `daana dar apply` refuses to change a published view to a table, or a table to a view, on every database: set this before the output's first apply, or drop the published object and apply again.",
                "$ref": "#/$defs/materialize"
              },
              "publish": {
                "description": "Overrides where Daana publishes the output. `name` replaces `brg__<anchor>_<to>`; `dataset` sets the `workspace.yaml` target that `daana dar generate` writes to.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "entity_assembly"
              }
            }
          },
          "then": {
            "properties": {
              "kind": {
                "description": "Makes the output an entity assembly: one row per anchor entity with the current value of each listed attribute and its relationship keys, read from the DAB's own tables. Daana names it `intm__<anchor>`."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "scope": {
                "description": "Keeps only the entities whose assembled attributes meet this condition, given as a name under `scopes` or as SQL. Daana ignores the list form.",
                "$ref": "#/$defs/scope"
              },
              "keys": {
                "description": "Adds a column `<entity>_key` for each named relationship, with the related entity's key from the anchor entity's most recent link. Each name must be a relationship of this document, or `daana dar check` reports `DAR011`, and the model must relate the two entities (`DAR016`). A relationship's `sentinel` value becomes `NULL` in the column. `daana dar check` refuses two names that lead to the same entity (`DAR019`), which would be one column name. Daana accepts the map form here but adds no columns for it.",
                "$ref": "#/$defs/keys"
              },
              "incremental": {
                "description": "Makes the output an incremental table in the Dataform SQLX that Daana generates for BigQuery: each run reads only rows recorded after the newest `watermark` value in the table and merges them by `<anchor>_key`. Incremental mode needs `lookback`, `full_refresh_floor`, and `partition` with `day_of` naming a listed attribute, and `daana dar check` refuses an incremental assembly without them (`DAR020`), even for `daana dar apply`. `daana dar apply` builds the whole object every time, but still keeps only the entities on or after `full_refresh_floor`, as that key describes.",
                "$ref": "#/$defs/incremental"
              },
              "attributes": {
                "description": "Names the attributes of the anchor's entity, by name or id, that become columns after `<anchor>_key` and the `watermark` column, in list order. Each holds the attribute's latest value from the entity's attribute table, such as `customer_desc`, or `NULL` when its latest row is an end. `daana dar check` refuses an output without one (`DAR020`); `daana dar check` refuses an unknown name with `DAR015`.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "checks": {
                "description": "Data quality checks on the output, by check name. `daana dar apply` runs them on DuckDB after it creates the outputs, on the output's main object and not on a `__latest` or `__wide` companion. Apply on another target and `daana dar generate` refuse a document that has checks.",
                "$ref": "#/$defs/checks_block"
              },
              "descriptions": {
                "description": "Holds descriptions by column or flag name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "partition": {
                "description": "Sets the BigQuery partitioning of the table that `daana dar generate` writes. With `incremental`, generate requires `day_of`, the column that the lookback and the full refresh floor filter on. A projection of the assembly without its own partitioning takes this one. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/partition"
              },
              "cluster": {
                "description": "Sets the BigQuery clustering columns of the table that `daana dar generate` writes. Without it, generate clusters the table by `<anchor>_key`, and a projection of the assembly without its own clustering takes this one. `daana dar apply` does not use it, but changing it gives the anchor a new revision, and generate refuses it with `materialize: view`.",
                "$ref": "#/$defs/cluster"
              },
              "materialize": {
                "description": "`table` makes the output a table and `view` a view; without it, `daana dar apply` makes a view and `daana dar generate` a Dataform table. With `incremental`, generate writes an incremental table whatever this says. An applied table holds what the last apply wrote. `daana dar apply` refuses to change a published view to a table, or a table to a view, on every database: set this before the output's first apply, or drop the published object and apply again.",
                "$ref": "#/$defs/materialize"
              },
              "publish": {
                "description": "Overrides where Daana publishes the output. `name` replaces `intm__<anchor>`; `dataset` sets the `workspace.yaml` target that `daana dar generate` writes to.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "pattern": "^serve\\."
              }
            }
          },
          "then": {
            "required": [
              "tier",
              "version",
              "from"
            ],
            "properties": {
              "kind": {
                "description": "Makes the output a versioned serving object over the output in `from`: a view for `serve.view` and a table for `serve.table`. Daana names it `<source>__<anchor>_v<version>`, such as `dim__customer__latest__<anchor>_v1`."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "tier": {
                "description": "Sets which source the serve object may read, and compile refuses any other: `modeled` reads a `data_mart` output that is not a `__wide` companion, `raw` reads an output outside `data_mart`, and `experimental` reads any output.",
                "enum": [
                  "modeled",
                  "raw",
                  "experimental"
                ]
              },
              "version": {
                "description": "Holds the version of the serve contract. Without `publish.name`, Daana ends the object's name with `_v` and this number, after the source and anchor names.",
                "type": "integer",
                "minimum": 1
              },
              "from": {
                "description": "Names the published output that the serve object reads: `<anchor>.<output>` reads the output's main object, `<anchor>.<output>.latest` the `__latest` object of a dimension that sets `latest`, and `<anchor>.<output>.wide` the `__wide` view of an output that has `wide`. The third part is matched as written: `daana dar check` and compile refuse `.Wide`, any other third part, and any fourth part (`DAR007`). `daana dar check` on a directory and compile refuse `.latest` or `.wide` on an output that has no such companion (`DAR007`). `daana dar check` also accepts a name without a dot when it is the key of an output of the same document. Without `publish.name`, Daana builds a valid object name from `from` only when the output key is `dim`, and `daana dar check` refuses the others (`DAR020`).",
                "type": "string"
              },
              "columns": {
                "description": "Lists the source columns that the serve object selects. `daana dar check` refuses a serve object with neither `columns` nor `derive` (`DAR020`); with only `derive`, Daana selects every source column.",
                "$ref": "#/$defs/columns_list"
              },
              "derive": {
                "description": "Adds named SQL expressions as columns over the source, placed before the listed columns; `{name}` stands for the column `name`.",
                "$ref": "#/$defs/derive_block"
              },
              "describe": {
                "description": "Holds descriptions of the output's columns by column name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "describe_extra": {
                "description": "Holds additional descriptions of the output's columns by column name. Daana accepts this block but does not read it, so the texts reach no generated object.",
                "$ref": "#/$defs/descriptions_block"
              },
              "publish": {
                "description": "Overrides where Daana publishes the output. `name` replaces `<source>__<anchor>_v<version>`; `dataset` sets the `workspace.yaml` target that `daana dar generate` writes to instead of `serve_<anchor>`.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "reference.static"
              }
            }
          },
          "then": {
            "required": [
              "columns",
              "rows"
            ],
            "properties": {
              "kind": {
                "description": "Makes the output a small reference table whose rows are written in the document under `rows`. Daana names it `intm__<anchor>_<key>` after the output key."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "columns": {
                "description": "Names the output's columns: each key is a column name and its value describes the column. Daana creates the columns in alphabetical order and does not read the descriptions.",
                "$ref": "#/$defs/descriptions_block"
              },
              "rows": {
                "description": "Holds one map per row, from column name to value. Each row needs a value for every column in `columns`, and `daana dar check` refuses a row without one (`DAR020`); Daana ignores other keys. A value that reads as a number, quoted or not, becomes a number; any other value becomes a string. `daana dar check` refuses a value that contains a single quote or a backslash (`DAR019`). A `null` value (`null` or `~`) becomes SQL `NULL`.",
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "publish": {
                "description": "`daana dar check` refuses `name` (`DAR019`): Daana would leave the reference table without SQL. Without `publish`, Daana creates `intm__<anchor>_<key>`.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "reference.external"
              }
            }
          },
          "then": {
            "required": [
              "key"
            ],
            "properties": {
              "kind": {
                "description": "Declares an existing table, the document's `source.table`, keyed by `key`, that other outputs' `lookups` read. Daana creates no object for it."
              },
              "description": {
                "description": "Describes the output in prose. `daana dar check` warns and `daana dar lint` fails when an output has none. Daana does not put it in the generated SQL, and changing only this text gives the anchor no new revision.",
                "type": "string"
              },
              "key": {
                "description": "Names the columns that identify a row of the table in the document's `source.table`. A lookup whose `from` names this output matches its `key` entries to these columns in order. Daana creates no table or view for this output.",
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "source": {
                "description": "Daana reads this block only for the revision digest. A lookup on this output reads the table and columns of the document's top-level `source`, and does not resolve without it.",
                "$ref": "#/$defs/source"
              },
              "publish": {
                "description": "A `reference.external` output gets no object, and `daana dar check` refuses `name` (`DAR019`), under which Daana would plan one without SQL.",
                "$ref": "#/$defs/publish"
              },
              "lifecycle": {
                "description": "States whether the output is temporary and when it is to be removed. Daana accepts this block but does not read it.",
                "$ref": "#/$defs/lifecycle"
              },
              "family": {
                "description": "Puts the output in a named family, given as a string or as `name` with `as`. A `fact.consolidated` with `members` creates one output per member and dimension, and a `fact.union` with `legs.members` adds one leg per member. Without such a reader, it does not change the SQL, but changing it gives the anchor a new revision.",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "required": [
                      "name",
                      "as"
                    ],
                    "properties": {
                      "name": {
                        "description": "Names the family that the output belongs to, as the string form of `family` does.",
                        "type": "string"
                      },
                      "as": {
                        "description": "The value that `%{metric}` takes when a `members` template expands for this output, as in its `name_template`. Compile refuses a template whose family has a member without `as`; Daana never derives the value from the output key.",
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              }
            },
            "patternProperties": {
              "^x_": {
                "description": "Daana accepts any output key that starts with `x_` and does not read it."
              }
            },
            "additionalProperties": false
          }
        }
      ]
    }
  }
}
