Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/37529-skills-data-model-publish-checks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@objectstack/skills': patch
---

docs(skills): the data and automation skills teach three data-model checks publish now runs

Clause-②: no
Metadata-protocol: none

Published prose and evals only; the checks already run.

- `objectstack-data` `rules/relationships.md`: a roll-up whose child object has no `lookup` or `master_detail` field referencing the parent, or whose `relationshipField` is no field of the child, is refused at publish (`rollup/child-without-parent-reference`).
- `objectstack-data` `rules/field-types.md`: only `lookup`, `master_detail`, `user` and `tree` read `reference`; on any other type but `summary`, publish refuses it (`field/reference-on-non-reference-type`).
- `objectstack-automation` `references/state-machines-and-approvals.md`: `lockRecord` locks the record and its `master_detail` child rows only; a `lookup` child drawn as a body table stays editable while pending, reported as the warning `approval-detail-editable-while-pending`.

No file grew past its ceiling: each addition is paid for by shorter wording in the same file.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@
},
{
"id": 3,
"prompt": "Build an autolaunched flow `crm_budget_approval` on `project`: when `budget` increases past 100000, route to a manager who can approve, reject, or send it back to the submitter for revision; a resubmission returns to the manager. Cap it at two send-backs.",
"expected_output": "The ADR-0044 shape: an `approval` node (`type: 'approval'`, `approvers: [{ type: 'position', value: 'crm_manager' }]`, `lockRecord: true`, `maxRevisions: 2`) with `approve` / `reject` out-edges plus a `revise` out-edge to an `approval_revise` node, and a resubmit edge back into the approval node typed `type: 'back'` — what legalises the cycle for `registerFlow`. The flow lives in `flows` (no `approvals` collection).",
"prompt": "Build an autolaunched flow `crm_budget_approval` on `project`: when `budget` increases past 100000, route to a manager who can approve, reject, or send it back to the submitter for revision; a resubmission returns to the manager. Cap it at two send-backs. The project page draws its `budget_line` rows as a body table through the lookup `budget_line.project`; those lines must not change while the request is pending.",
"expected_output": "The ADR-0044 shape: an `approval` node (`type: 'approval'`, `approvers: [{ type: 'position', value: 'crm_manager' }]`, `lockRecord: true`, `maxRevisions: 2`) with `approve` / `reject` out-edges plus a `revise` out-edge to an `approval_revise` node, and a resubmit edge back into the approval node typed `type: 'back'` — what legalises the cycle for `registerFlow`. The flow lives in `flows` (no `approvals` collection). `budget_line.project` becomes a `master_detail`: `lockRecord` locks the record and its `master_detail` child rows only, and a `lookup` child drawn as a body table stays editable while pending (the warning `approval-detail-editable-while-pending`, which refuses nothing).",
"files": [],
"assertions": {
"must_contain": [
"type: 'approval'",
"approval_revise",
"type: 'back'",
"maxRevisions",
"revise"
"revise",
"master_detail"
],
"must_not_contain": [
"approvals: [",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const rule: StateMachineValidation = {
open: ['escalated', 'resolved'],
escalated: ['open', 'resolved'],
resolved: ['open', 'closed'],
closed: [], // final — no outgoing transitions
closed: [], // final
},
};
```
Expand Down Expand Up @@ -123,15 +123,15 @@ the same literal goes inside `defineFlow(...)`, and `` cel`…` `` builds each

### Send-back for revision (ADR-0044)

Approval centers also model **send back for revision** — distinct from
`reject` (terminate) and from a comment thread (which keeps the request pending).
**Send back for revision** is distinct from `reject` (terminate) and from a
comment thread (the request stays pending).
Send-back is a **flow movement**: the request finalizes as `returned`, the run
walks a **`revise`** out-edge to an **`approval_revise`** node (the *revise
window*) where the record unlocks and the submitter reworks it, and an explicit
*resubmit* re-enters the approval node over a **declared back-edge**, opening
round N+1 with a fresh approver slate.

Three pieces author it:
Three pieces:

1. **`revise` out-edge** — a third branch label alongside `approve` / `reject`,
targeting an **`approval_revise`** node. It must be that node type: the window
Expand All @@ -140,7 +140,7 @@ Three pieces author it:
`resumeAuthority: 'any'`, so a raw run-resume would walk the back-edge
unchecked. The node takes **no config** — there is no signal to wait on.
2. **`type: 'back'` resubmit edge** — the edge from the revise window back into
the approval node MUST be typed `'back'`. This is the *only* thing that
the approval node MUST be typed `'back'`. Only this
legalizes the cycle: `registerFlow` validates the graph **minus `back` edges**
as a DAG, so an **unmarked** cycle is rejected. At
run time a back-edge traverses normally.
Expand Down Expand Up @@ -339,7 +339,7 @@ Object-hook `ctx` is a different vocabulary — see **objectstack-data**
| `approvers` | Who may act (≥ 1 — see Approver Types above). Each approver may carry an optional **`group`** label (e.g. `{ type: 'position', value: 'crm_auditor', group: 'finance' }`) — with `behavior: 'per_group'`, approvers sharing a label form one group; unlabelled approvers each form their own |
| `behavior` | `first_response` (first approver decides), `unanimous` (all must approve), `quorum` (`minApprovals` of N — M-of-N collective sign-off), or `per_group` (EACH approver `group` must reach `minApprovals` — one-from-each-group sign-off). In every mode a single rejection finalizes the node as `rejected`. Default `first_response` |
| `minApprovals` | Approvals required — total for `quorum`, per group for `per_group`. Omitted ⇒ ALL resolvable approvers under `quorum`, `1` per group; clamped at runtime so a misconfiguration can never deadlock |
| `lockRecord` | Lock the triggering record from edits while pending. Default `true` |
| `lockRecord` | Lock the record while pending. Default `true` |
| `approvalStatusField` | Business-object field to mirror `pending`/`approved`/`rejected`/`returned`/`recalled` onto (should be readonly) |
| `onEmptyApprovers` | What an EMPTY resolved slate does: `admin_rescue` (default — request opens on the organization's administrators; never waves through, never kills the run), `fail` (node fails — treat an empty slate as a config bug), `auto_approve` (skip the request, continue down `approve` with `output.autoApproved = true` — opt-in because it silently waves the record through), `fallback` (request opens on the sibling `fallbackApprovers` instead — same shape as `approvers`, required by this policy and refused under any other; a fallback that itself resolves to nobody degrades to `admin_rescue`). Declare it explicitly on any node with an `expression` approver (linted) |
| `excludeSubmitter` | `true` drops the run's submitter (`submitter_id`) from the resolved slate, whatever approver type produced them — segregation of duties; a slate it empties takes the `onEmptyApprovers` route, never a silent pass. `onEmptyApprovers: 'auto_approve'` is **refused** beside it (it would approve exactly the request this exists to stop): use `admin_rescue`, `fail` or `fallback`. Default `false` |
Expand Down Expand Up @@ -367,10 +367,12 @@ These are wired on the **graph**, not in node config:

### Approval Best Practices

1. **Set `approvalStatusField`** to mirror status onto the row — views and
formulas can then filter on it without joining `sys_approval_request`.
2. **Keep `lockRecord: true`** unless you have a strong reason to allow
edits while pending — otherwise approvers chase a moving target.
1. **Set `approvalStatusField`**: views and formulas filter on status
without joining `sys_approval_request`.
2. **Keep `lockRecord: true`**, or approvers chase a moving target. It locks
the record and its `master_detail` child rows only: a `lookup` child shown
in the record's details (`relatedList: 'primary'`, or a parent field group)
stays editable (warning `approval-detail-editable-while-pending`).
3. **Notify the submitter from downstream nodes** wired to the `approve` /
`reject` edges. Opening already tells each resolved approver
(`approval.requested`); ⛔ no `notify` node for the opening: it tells
Expand Down
21 changes: 18 additions & 3 deletions skills/objectstack-data/evals/objects-fields-relationships.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,16 @@
},
{
"id": 12,
"prompt": "项目上要显示「已完成任务数」「任务总数」和「完成率」。",
"expected_output": "Three fields on `project`: `completed_task_count` and `task_count` are `type: 'summary'` fields over the `task` child with `function: 'count'` (and `summaryOperations.object: 'task'`), the completed one carrying the qualifier in `filter: { status: 'completed' }` — keyed by a CHILD field and the option VALUE, never the label `已完成`; dropped, the field counts every task and shows a plausible wrong total. `completion_rate` is a `type: 'formula'` field over the two summaries, authored after them (it computes only once they do). If `project` rows already exist, says the recompute runs only on a child write, so the backfill is `os migrate summary-nulls --apply` — not editing a task to trigger it.",
"prompt": "项目上要显示「已完成任务数」「任务总数」和「完成率」。`task` 现在没有指向项目(`project`)的字段。",
"expected_output": "Three fields on `project`: `completed_task_count` and `task_count` are `type: 'summary'` fields over the `task` child with `function: 'count'` (and `summaryOperations.object: 'task'`), the completed one carrying the qualifier in `filter: { status: 'completed' }` — keyed by a CHILD field and the option VALUE, never the label `已完成`; dropped, the field counts every task and shows a plausible wrong total. `completion_rate` is a `type: 'formula'` field over the two summaries, authored after them (it computes only once they do). If `project` rows already exist, says the recompute runs only on a child write, so the backfill is `os migrate summary-nulls --apply` — not editing a task to trigger it. `task` gets a field pointing back at `project` (`master_detail` or `lookup`, `reference: 'project'`): a roll-up whose child has none is refused at publish (`rollup/child-without-parent-reference`).",
"files": [],
"assertions": {
"must_contain": [
"type: 'summary'",
"function: 'count'",
"filter:",
"type: 'formula'"
"type: 'formula'",
"reference: 'project'"
],
"must_not_contain": [
"filter: { status: '已完成' }",
Expand Down Expand Up @@ -501,6 +502,20 @@
"deleteBehavior: 'cascade'"
]
}
},
{
"id": 29,
"prompt": "On `ticket` a colleague wrote `contact_name: { type: 'text', reference: 'contact' }` so the form offers a contact picker while the column stays text. Will that publish? Write the field as it should be.",
"expected_output": "No: only `lookup`, `master_detail`, `user` and `tree` read `reference`; on a `text` field publish refuses it (`field/reference-on-non-reference-type`). To link a contact the field is `{ type: 'lookup', reference: 'contact' }`; a plain text name drops `reference`.",
"files": [],
"assertions": {
"must_contain": [
"type: 'lookup'",
"reference: 'contact'",
"field/reference-on-non-reference-type"
],
"must_not_contain": []
}
}
]
}
33 changes: 18 additions & 15 deletions skills/objectstack-data/rules/field-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const fields = {
};
```

> **Config columns list only real `FieldSchema` keys.** Per-type display knobs
> beyond these do **not** exist — an unknown field key is REFUSED at parse
> **Config columns list only real `FieldSchema` keys.** No other per-type display
> knob exists — an unknown field key is REFUSED at parse
> (`unrecognized_keys`), so don't invent `theme`, `rows`,
> `vectorConfig` or `fileAttachmentConfig`.

Expand All @@ -35,12 +35,12 @@ const fields = {
|:-----|:------------|:-------|
| `text` | Single-line strings (names, codes, titles) | `maxLength`, `minLength`, `defaultValue` |
| `textarea` | Multi-line plain text (notes, descriptions) | `maxLength`, `minLength` |
| `email` | Email addresses — built-in format validation | `required`, `unique` |
| `url` | Web URLs — built-in format validation | `required` |
| `email` | Email addresses — format validated | `required`, `unique` |
| `url` | Web URLs — format validated | `required` |
| `phone` | Phone numbers | `format` |
| `password` | ⚠️ Masked-on-read input. On a generic object the value is stored **PLAINTEXT at rest**. Prefer `secret` for credentials; a generic `password` field triggers a build warning | `minLength`, `maxLength` |
| `secret` | Reversible **encrypted-at-rest** credential (DB password, API key, token) — encrypted on write via `ICryptoProvider`, masked on read, fail-closed (ADR-0100) | — |
| `markdown` | Markdown content | `maxLength` |
| `markdown` | Markdown | `maxLength` |
| `html` | Raw HTML | `maxLength` |
| `richtext` | WYSIWYG editor | `maxLength` |

Expand All @@ -65,15 +65,15 @@ const fields = {
| Type | When to Use | Config |
|:-----|:------------|:-------|
| `boolean` | Checkbox | `defaultValue` |
| `toggle` | Toggle switch (distinct UI from checkbox) | `defaultValue` |
| `toggle` | Switch (distinct UI from checkbox) | `defaultValue` |

## Selection

| Type | When to Use | Config |
|:-----|:------------|:-------|
| `select` | Single-choice dropdown | `options` (value, label, color, default) |
| `multiselect` | Tag-style multi-choice | `options`, `max` |
| `radio` | Radio button group (fewer choices, always visible) | `options` |
| `radio` | Radio group (fewer choices, always visible) | `options` |
| `checkboxes` | Checkbox group | `options` |

**Critical:** Every option must have lowercase `value` and human-readable `label`.
Expand All @@ -94,6 +94,9 @@ options: [
| `tree` | Hierarchical self-reference | `reference` — optional; when written, this object's own name (any other object is refused at parse) |
| `user` | Person picker — a lookup specialized to `sys_user` (reviewer, watchers). Stored identically to `lookup` | `multiple` (collaborators), `defaultValue: 'current_user'`, `deleteBehavior` (no default; declared, as on `lookup`: relationships.md → Delete Behaviors) |

Only these four read `reference`; on any other type but `summary`, publish
refuses it (`field/reference-on-non-reference-type`).

**`lookupAutofill: [{ target, source, overwrite? }]`** (single-value only): a
pick copies the picked record's `source` into this object's `target`
(`unit_price` from a product's `list_price`), in the form and the line-item
Expand All @@ -110,15 +113,15 @@ is converted.

| Type | When to Use | Config |
|:-----|:------------|:-------|
| `image` | Image files (PNG, JPG, GIF, WebP) | `multiple` |
| `file` | File attachments | `multiple` |
| `image` | Images (PNG, JPG, GIF, WebP) | `multiple` |
| `file` | Attachments | `multiple` |
| `avatar` | Profile picture | — |
| `video` | Video files | — |
| `audio` | Audio files | — |
| `video` | Video | — |
| `audio` | Audio | — |

## Embedded (JSON sub-objects)

Stored as JSON on the parent row, no separate table/FK:
JSON on the parent row, no separate table/FK:

| Type | When to Use |
|:-----|:------------|
Expand All @@ -141,15 +144,15 @@ Stored as JSON on the parent row, no separate table/FK:
| `location` | Coordinates (lat/lng) | — |
| `address` | Structured address (street, city, country) | — |
| `code` | Syntax-highlighted code editor | `language` |
| `json` | JSON data (untyped escape hatch) | — (validate with a `json_schema` validation rule on the object) |
| `json` | JSON (untyped escape hatch) | — (validate with a `json_schema` validation rule on the object) |
| `color` | Color picker | — |
| `rating` | Star/heart rating | `max` (default 5) |
| `slider` | Slider | `min`, `max`, `step` |
| `signature` | Signature pad | — |
| `qrcode` | QR code / barcode | — |
| `progress` | Progress bar | `min`, `max` |
| `tags` | Free-form tags | — |
| `vector` | AI/ML embeddings (semantic search, RAG) | `dimensions` (flat sibling, e.g. `1536`) |
| `vector` | Embeddings (semantic search, RAG) | `dimensions` (flat sibling, e.g. `1536`) |

## Common Field Configurations

Expand Down Expand Up @@ -264,7 +267,7 @@ The `format` is literal text interleaved with `{...}` tokens:

**Rules — get these wrong and records mis-number silently or fail to save:**

1. **Every `{field}` you interpolate must be `required: true`** and set before the record is created. An empty interpolated field makes the record number generation *throw* (the compile lint flags a non-existent field as an error, an optional one as a warning).
1. **Every `{field}` you interpolate must be `required: true`** and set before the record is created. An empty one makes number generation *throw* (the compile lint flags a non-existent field as an error, an optional one as a warning).
2. **Put a delimiter between adjacent variable tokens** — `{section}-{zone}{000}`, not `{section}{zone}{000}`. Without one, `('AB','C')` and `('A','BC')` both render prefix `ABC` and share a counter (to keep numbers unique).
3. **Pad width is a MINIMUM, not a cap.** `{000}` → `001`…`999`, then `1000`.
4. **Only known tokens are interpolated.** Date tokens are **case-sensitive** — `{yyyy}` parses as a `{field}` reference and renders **empty** (rule 1 applies). Only a spelling no field could have — `{ YYYY }`, `{YYYY-MM}` — is emitted **literally**.
14 changes: 8 additions & 6 deletions skills/objectstack-data/rules/relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

| Type | Lifecycle | Required | Sharing | Roll-ups | Use Case |
|:-----|:----------|:---------|:--------|:---------|:---------|
| `lookup` | Independent | Optional by default | Independent | Supported via `summary` | "Related to" |
| `master_detail` | Coupled (cascade delete) | Forced only under `controlled_by_parent`, unless the optional master (below); else lint-warned | Inherits parent; read-on-master opt-ins (below) | Supported via `summary` | "Owned by" |
| `lookup` | Independent | Optional by default | Independent | Via `summary` | "Related to" |
| `master_detail` | Coupled (cascade delete) | Forced only under `controlled_by_parent`, unless the optional master (below); else lint-warned | Inherits parent; read-on-master opt-ins (below) | Via `summary` | "Owned by" |
| `tree` | Self-reference | Optional — and so is `reference`, which when written must name this object itself; any other object is refused at parse, not lint-warned | N/A | Not available | Hierarchical |

## Patterns
Expand Down Expand Up @@ -185,8 +185,8 @@ or a child not offering Change Owner itself (a `controlled_by_parent` detail).
## Roll-up Summaries

A parent `summary` field aggregates a child collection. The engine recomputes it
**server-side** whenever a child is inserted/updated/deleted (inside the same
transaction as the write, so it's consistent).
**server-side** on every child insert/update/delete, in the write's
transaction.

```json
{
Expand All @@ -197,8 +197,10 @@ transaction as the write, so it's consistent).

`object` is the child object to aggregate, `field` its field (ignored for
`count`), `function` one of `count` / `sum` / `min` / `max` / `avg`. Optional:
`relationshipField` (auto-detected from the child's `master_detail`/`lookup`
field referencing this parent when omitted) and `filter` (below).
`filter` (below) and `relationshipField` (omitted: the child's `lookup` /
`master_detail` referencing this parent). Refused at publish when omitted and the
child has neither, or naming no child field
(`rollup/child-without-parent-reference`).

Empty collections roll up to `0` for `count`/`sum`, `null` for `min`/`max`/`avg`.

Expand Down
Loading