diff --git a/.changeset/38655-skills-save-refusals.md b/.changeset/38655-skills-save-refusals.md new file mode 100644 index 00000000000..b8d4af3897c --- /dev/null +++ b/.changeset/38655-skills-save-refusals.md @@ -0,0 +1,22 @@ +--- +'@objectstack/skills': patch +--- + +docs(skills): the published skills teach three refusals the save door makes: a grid grouping field the engine does not group by, a hook body call without its capability token, and `updateById` under `api.write` + +Clause-②: no +Metadata-protocol: none + +Text only: no schema, rule or runtime behaviour changes here. Each sentence follows the rule's own explanation (`os explain RULE`). + +`skills/objectstack-ui/rules/list-views.md`, Grouping: on a grid (the default `type`) a grouping level's `field` is a stored single-valued field of the object. A multi-valued field (`multiselect`, `checkboxes`, `tags`, `multiple: true`), a JSON-stored one (`json`, `address` and the like) or a `formula` field is refused at validate and publish as `list-view-group-field-ungroupable`; the fix is to show the field as a column. A dotted path (`account.name`) is refused as `list-view-field-dotted`; the fix is to group by the lookup itself. + +`skills/objectstack-data/references/data-hooks.md`, Capabilities: a hook body call whose token is missing from `body.capabilities` is refused at save as `hook-body-capability-undeclared`, an error from `os validate`, `os build`, `os lint` and a runtime save (`422 INVALID_METADATA`); the fix is to add the token the message names, or remove the call. The paragraph says which spellings the rule reads (a call on `ctx`, on a local bound once to it, on a handle bound once to `.object(…)`) and that a call spelled another way still throws in the sandbox. The `api.write` row lists every write leaf the sandbox gates: `insert`, `update`, `updateById(id, patch)`, `delete`, `updateMany`, `deleteMany`, `upsert`. + +`skills/objectstack-ui/rules/actions.md`, opening paragraph: an action body writes through `ctx.api.object(X).update(...)` or `.updateById(id, patch)`, both under `api.write`, and without that grant the write is refused at save (`action-body-write-capability-undeclared`). + +No file grows: each addition is paid for by deletion in its own file, so the three token counts stay 4509, 10120 and 3918. + +- `list-views.md`: the view-switcher consequence of a bare flat view object; the lead-in sentence of Data Source; two words of each Columns comment; "still ANDed with the elements beside it" (the paragraph opens with "elements must all match"); the `userFilters` lead-in's list of elements (the block under it names them); the comment over `appearance`; that the list-view-mode lint also reports a `tabs` element the parse rejects; the second pointer to objectstack-data Search Fields and to Inline Editing (each is named a few lines above); "you almost never need a custom page" (item 2 says when a page is used). +- `data-hooks.md`: the "Reference companion" line under the contents list; the "What Are Hooks?" heading and its one sentence (the two tables under it say when a hook runs); the Status row of the `body` / `handler` table (its header marks `handler` deprecated); a comment in the `input` example; "the layout both real hook modules in the repo use". +- `actions.md`: the new-tab warning no longer names the `ActionParam[]` type, and keeps "user input only". diff --git a/skills/objectstack-data/references/data-hooks.md b/skills/objectstack-data/references/data-hooks.md index 2843973a6ca..225e5fd1fcb 100644 --- a/skills/objectstack-data/references/data-hooks.md +++ b/skills/objectstack-data/references/data-hooks.md @@ -6,8 +6,6 @@ - [Hook Context API](#hook-context-api) · [Common Patterns](#common-patterns) · [Registration Methods](#registration-methods) - [Best Practices](#best-practices) · [Error Handling](#error-handling) · [References](#references) -Reference companion to `objectstack-data/SKILL.md`, and the catalog's anchor for -data hooks. `check:skill-examples` skips the unmarked blocks: fragments, shapes, and pattern 4's bare `any`. @@ -15,11 +13,6 @@ data hooks. ## Core Concepts -### What Are Hooks? - -Hooks are **event handlers** in the ObjectQL data access lifecycle, run before or -after an operation — see [Before vs After](#before-vs-after-hooks). - ### Hook Lifecycle Events | Event | When It Fires | Use Cases | @@ -188,7 +181,6 @@ CEL has no overload for does **not** degrade to "the hook did not fire" — it |:--|:--|:--| | Shape | `body: { language, source, capabilities }` (pure metadata) | `handler: async (ctx) => { … }` | | Runs in | An isolated **QuickJS VM** (edge-safe, capability-gated) | The host process (**full Node**) | -| Status | **Preferred for new code** | **Deprecated** (`HookSchema`: *"prefer `body`"*) | | Both present? | Runtime uses **`body`** and ignores `handler` | — | ### The `body` shape @@ -287,15 +279,21 @@ An unpredicated `find` / `count` is fine: every row is an honest answer. ### Capabilities — the complete list -A body may only touch a `ctx` API it declared in `capabilities`. Calling an -undeclared one **throws inside the VM** — `capability '' not granted to -hook '' …` — which surfaces as a hook error (see Troubleshooting). The legal -tokens (`HookBodyCapability`) are exactly seven: +A body may only touch a `ctx` API it declared in `capabilities`. A call in the +table below whose token is missing is refused at save +(`hook-body-capability-undeclared`: an **error** from `os validate`, +`os build`, `os lint` and a runtime save, `422 INVALID_METADATA`): add the +token the message names, or remove the call. The rule reads a call on `ctx`, +on a local bound once to it (`const log = ctx.log`) or on a handle bound once +to `.object(…)`; one spelled another way **throws inside the VM** — +`capability '' not granted to hook '' …` — which surfaces as a +hook error (see Troubleshooting). The legal tokens (`HookBodyCapability`) are +exactly seven: | Token | Unlocks | |:--|:--| | `api.read` | `ctx.api.object(n).find` / `findOne` / `count` / `aggregate`; also `ctx.title('')`. | -| `api.write` | `ctx.api.object(n).insert` / `update` / `delete` | +| `api.write` | `ctx.api.object(n).insert` / `update` / `updateById(id, patch)` / `delete` / `updateMany` / `deleteMany` / `upsert` | | `api.transaction` | `ctx.api.transaction(async () => { … })` — runs the callback's `ctx.api` ops in **one transaction on the default datasource**: commit on return, rollback on throw. A write in it to an object on another datasource is refused before it runs (`400 ERR_CROSS_DATASOURCE_TRANSACTION_WRITE`), except an append-only ledger (`lifecycle.class` `audit` / `telemetry` / `event`), written outside the unit and surviving its rollback. Inside a unit already open (the hook's write's, a caller's, or one an action body opened with `ctx.api.transaction`) it **joins** that unit: its return is no commit and its throw no rollback; the outer unit commits or rolls back all of it, so a throw the body catches keeps the callback's writes. Hooks of a write made inside a body's transaction run in that unit, and their `ctx.api` writes and own `ctx.api.transaction` join it. One level per body: a nested call is refused ("nested ctx.api.transaction is not supported"). On PostgreSQL and a MongoDB replica set a failed statement aborts the whole unit, even when caught. A driver with no transactions runs the callback with none and no warning: each write is stored as made, and a throw undoes none. Pair it with `api.write`. | | `crypto.uuid` | `ctx.crypto.randomUUID()` | | `log` | `ctx.log.debug` / `info` / `warn` / `error(msg, data?)` | @@ -479,7 +477,6 @@ const org = ctx.user?.organizationId ?? ctx.session?.organizationId; ```typescript // beforeInsert, afterInsert { - // All field values being inserted name: 'Acme Corp', industry: 'Technology', ... @@ -729,8 +726,7 @@ ctx.ql.registerHook('beforeInsert', async (hookCtx) => { /* ... */ }, ``` **3. Hook files — `src/objects/{object}.hook.ts`.** One `defineHook({ ... })` per -file, default-exported, then listed in the stack's `hooks` array (method 1). This is -the layout both real hook modules in the repo use. +file, default-exported, then listed in the stack's `hooks` array (method 1). --- diff --git a/skills/objectstack-ui/rules/actions.md b/skills/objectstack-ui/rules/actions.md index a3dc51ffd91..1f4000af972 100644 --- a/skills/objectstack-ui/rules/actions.md +++ b/skills/objectstack-ui/rules/actions.md @@ -9,10 +9,10 @@ is refused at validate and publish (`action-no-object-binding`; set it, or `locations: []` if headless). With neither `locations` nor a view naming it in `rowActions` / `bulkActionDefs` it renders nowhere (`action-no-placement`). A body that returns or assigns values writes nothing -(`action-record-write-discarded`): it calls `ctx.api.object(...).update(...)` -in `language: 'js'` (an `expression` body has no I/O) with -`capabilities: ['api.write']`; without that grant, a write is refused too -(`action-body-write-capability-undeclared`). +(`action-record-write-discarded`): it calls `ctx.api.object(X).update(...)` +or `.updateById(id, patch)` in `language: 'js'` (an `expression` body has no +I/O) with `capabilities: ['api.write']`; without it, a write is refused at +save (`action-body-write-capability-undeclared`). ## Where Actions Appear (`locations`) @@ -213,9 +213,8 @@ export const OpenInvoicePdfAction = defineAction({ > A printable document (an invoice) is a page that declares `print` — [Print pages](./pages.md#print-pages). -> ⚠️ **Never express new-tab behavior via `params`** — it is `ActionParam[]` for -> **user input** only: `params: [{ name: 'newTab', type: 'checkbox' }]` draws a -> checkbox. +> ⚠️ **Never express new-tab behavior via `params`**, which is **user input** +> only: `params: [{ name: 'newTab', type: 'checkbox' }]` draws a checkbox. ## Action Parameter Patterns diff --git a/skills/objectstack-ui/rules/list-views.md b/skills/objectstack-ui/rules/list-views.md index 2e11a57663d..965c9dca4f6 100644 --- a/skills/objectstack-ui/rules/list-views.md +++ b/skills/objectstack-ui/rules/list-views.md @@ -31,11 +31,11 @@ export const CaseViews = defineView({ ``` > **Never export a bare flat view object** (`{ name, label, type, columns }` -> at top level): nothing registers and no view appears in the switcher. +> at top level): nothing registers. ### Data Source (`data`) -Every view connects to data via one of two providers: +Two providers: ```typescript data: { provider: 'object', object: 'support_case' } @@ -48,10 +48,10 @@ data: { provider: 'value', items: [...] } ### Columns ```typescript -// Simple — field names only +// Field names only columns: ['subject', 'status', 'priority', 'owner_id', 'due_date'] -// Enhanced — full control +// Per-column settings columns: [ { field: 'subject', link: true, width: 300 }, { field: 'status', width: 120, align: 'center' }, @@ -92,7 +92,7 @@ by nature — a log, an audit trail, a history, a report roll-up — declares `filter` is a list whose elements must **all** match. An element is a rule `{ field, operator, value }` or an any-of group `{ or: [rule, ...] }` that -matches when **any** of its rules does — still ANDed with the elements beside it: +matches when **any** of its rules does: ```typescript filter: [ @@ -117,9 +117,8 @@ it read-only. ### End-User Quick Filters (`userFilters`, ADR-0047) -`filter` is the always-on base criteria. For the *end-user-facing* filter bar -use `userFilters` — dropdowns, filter tabs, or -toggles the user combines at runtime: +`filter` is the always-on base criteria; `userFilters` is the filter bar the +user combines at runtime: ```typescript userFilters: { @@ -130,7 +129,6 @@ userFilters: { ], }, -// Runtime visualization whitelist: appearance: { allowedVisualizations: ['grid', 'kanban', 'gallery'] }, // one entry = locked, no switcher ``` @@ -142,9 +140,8 @@ Rules: entry, rendered as a tab in the object's saved-view switcher. - **On an object list view (`*.view.ts` `list` / `listViews`), only `element: 'dropdown'` (value chips) is allowed — `tabs` is page-only** - (ADR-0047 amendment): the saved-view switcher already owns the tab bar, so - `ObjectUserFiltersSchema` **rejects** `tabs` at parse (not dropped) and the - `validate` list-view-mode lint reports it. + (ADR-0047 amendment): the saved-view switcher owns the tab bar, so + `ObjectUserFiltersSchema` **rejects** `tabs` at parse (not dropped). - **Omit `userFilters` when unsure — omission means a clean toolbar.** Nothing is auto-derived. - `userFilters: { element: 'dropdown' }` (no `fields`) is valid shorthand: @@ -198,12 +195,12 @@ ingress gate refuses any entry outside the allowed set before the engine runs. | a renamed / mistyped column, or a dotted path (`account_id.name`) | `searchable-field-unknown` | `400 INVALID_FIELD` | | a real column outside the allowed set, or a virtual `formula` column | `searchable-field-unsearchable` | `400 INVALID_FIELD` | -Both diagnostics are **errors**: `os validate` fails the build. +Both are **errors**: `os validate` fails. To remove the search box instead: `userActions: { search: false }` on the list. **Searching by a related record's title:** mirror it into a **stored** field -and narrow to that (objectstack-data → Search Fields). +and narrow to that. ### Sorting @@ -221,7 +218,13 @@ sort: [ option order (declare stages in pipeline order); others sort by label. `orderBy` orders a level's groups by a number, date or boolean field of the same object instead — text or a select is refused -(`list-view-group-order-unorderable`): +(`list-view-group-order-unorderable`). On a grid (the default `type`) a +level's `field` is a stored single-valued field of the object: a +multi-valued (`multiselect`, `checkboxes`, `tags`, `multiple: true`), +JSON-stored (`json`, `address`, …) or `formula` field is refused at validate and +publish (`list-view-group-field-ungroupable`; show it as a column), +and so is a dotted path (`account.name`: `list-view-field-dotted`; group by +the lookup `account` itself): ```typescript grouping: { fields: [ @@ -380,8 +383,7 @@ export const WebToLead = defineForm({ ## Master-Detail Forms (parent + child line items) To let users enter a record **together with its child line items** (invoice + -lines, project + tasks) and save them **atomically**, you almost never need a -custom page. Prefer, in order: +lines, project + tasks) and save them **atomically**, prefer, in order: 1. **A parent field group naming the child (zero view config).** In the DATA MODEL, the parent declares `fieldGroups: [{ key: 'lines', label: 'Lines', @@ -399,7 +401,7 @@ custom page. Prefer, in order: **Line-item grid behaviors (`grid` mode).** Every behaviour of the editable grid is derived from the DATA MODEL — computed columns, catalog typeahead auto-fill, persisted drag-reorder, and the live Subtotal → Tax → Total -stack: **objectstack-data → Relationships → Inline Editing**. Three things are +stack (Inline Editing, above). Three things are authored on this side: a trailing **ghost** row always exists, so never add an "Add line" button to the grid (typing in the ghost materialises a row; an untouched one is never persisted; a record-header action that inserts a priced