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
18 changes: 18 additions & 0 deletions .changeset/33773-skills-follow-merged-code-a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@objectstack/skills': patch
---

docs(skills): four published skills follow merged code — audit sealing, the compare widget's date key, i18n wording, nested relation conditions

Clause-②: no
Metadata-protocol: none

`skills/objectstack-data/rules/lifecycle.md` § Sealing: each sealed hour becomes one checkpoint, or consecutive checkpoints of at most 10,000 rows, per organization chain; `chainField` (optional, default `tenant_id`) names the chain column and is fixed once checkpoints exist; `os audit verify` exits 1 on a changed row or a chain fault, `listed_twice` included. The graded eval case in `evals/objects-fields-relationships.json` says the same.

`skills/objectstack-ui/rules/dashboards.md` § `compareTo`: a compare widget's window reaches the dataset query as a time dimension named after the date-range field, so the dataset declares a date dimension of that name (or one over a related-record date path), else `400 INVALID_FIELD`.

`skills/objectstack-i18n/SKILL.md`: the stale aside about the schema docstring is gone (activity-milestone summaries keep their `{field}` tokens); the wiring sentence is a statement again ("You do not need to wire this plugin"); `getSourceLocale()` returns the declared locale only, else `undefined`; the i18n routes answer signed-in callers, and the locales answer carries the declared `fallbackChain`.

`skills/objectstack-query/SKILL.md` and `rules/filters.md`: on a read verb a single-valued relation condition is one in-database subquery per relationship, up to three relationships, on drivers declaring `readableIdsLeaf` (MongoDB and OData refuse it); the 1000-id cap stays only where ids are still read. `filters.md` § Operator Reference lists one example per operator; the SQL equivalents live in `SKILL.md` **Filter Operators**.

No token ceiling moved: every addition is paid by a deletion in the same file.
3 changes: 2 additions & 1 deletion packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8019,7 +8019,8 @@ export class ObjectStackClient {
*
* Speaks the path-param dialect (`/translations/:locale`) — the shape
* `plugin-rest-api.zod.ts` declares and the ONLY shape any serving surface
* mounts (service-i18n's autonomous routes, the dispatcher's HTTP mounts).
* mounts (the runtime HTTP dispatcher's `/i18n` domain; service-i18n's own
* routes were retired by #23347).
* The `?locale=` query form this used to send matched no route anywhere
* and 404'd on the wire; the dispatcher's domain body accepts it, but
* nothing ever routes a bare `/translations` to that body (#3636).
Expand Down
10 changes: 5 additions & 5 deletions packages/spec/src/system/i18n-resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3959,8 +3959,8 @@ describe('toLocaleDescriptors', () => {
// The SUBSTANCE pin: producer output vs the DECLARED shape, both halves.
//
// `GetLocalesResponseSchema` described `label` as "Display name of the
// locale" while this helper — the ONLY producer, shared by the
// dispatcher's `/i18n` domain and service-i18n's route — echoed the code
// locale" while this helper — the ONLY producer, used by the runtime
// dispatcher's `/i18n` domain, which mounts the route — echoed the code
// back. Declared ≠ enforced, one field wide (ADR-0049), and it misleads in
// exactly one direction: a client that trusts the describe renders `th`
// where `ไทย` belongs. objectui#4039 hit that and routed around the field
Expand Down Expand Up @@ -3997,9 +3997,9 @@ describe('toLocaleDescriptors', () => {

describe('normalizeSupportedLocales — the declared supportedLocales narrow the advertised set', () => {
// The narrowing rule both providers of the `i18n` slot share. Held here,
// next to `toLocaleDescriptors`, because both of them can be the thing
// mounting `GET /i18n/locales` and a second copy is how that route came to
// answer in two shapes before.
// next to `toLocaleDescriptors`, because either can be the provider behind
// `GET /i18n/locales` (the runtime dispatcher mounts it), and a second
// copy is how that route came to answer in two shapes before.

it('returns the declared codes in DECLARED order', () => {
// Order is authored, so it is preserved: a picker rendering the app's own
Expand Down
13 changes: 8 additions & 5 deletions packages/spec/src/system/i18n-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4586,7 +4586,8 @@ export function toLocaleDescriptors(
* [#7679] Shared for the same reason `toLocaleDescriptors` above is: BOTH
* providers of the `i18n` slot implement `setSupportedLocales`
* (`createMemoryI18n` in core, `FileI18nAdapter` in service-i18n) and either
* one can be the thing mounting `GET /i18n/locales`. Two copies of "what
* one can be the provider behind `GET /i18n/locales`, which the runtime HTTP
* dispatcher mounts (#23347). Two copies of "what
* counts as a declaration" is how the same route came to answer in two shapes
* before (#3636), one narrowing rule over.
*
Expand Down Expand Up @@ -4629,12 +4630,14 @@ export function normalizeSupportedLocales(
* "which fields does this locale translate at all", which is what the
* endpoint returns and what no per-field lookup can produce.
*
* Shared deliberately. Both serving surfaces derive this map — the dispatcher
* domain body and service-i18n's autonomous route — and they are the only
* Shared deliberately. Both serving surfaces once derived this map — the
* dispatcher domain body and service-i18n's own route, retired by #23347, so
* the runtime HTTP dispatcher now mounts the endpoint — and this is the only
* path there is: `getFieldLabels` is optional on `II18nService` and NOTHING
* implements it (neither `memory-i18n` nor `file-i18n-adapter`), so the
* "dedicated method" branch both surfaces check first is dead and this
* derivation always runs. Keeping one copy each is how the dispatcher was
* "dedicated method" branch the dispatcher checks first (as service-i18n's
* route did) is dead and this derivation always runs. Keeping one copy each
* was how the dispatcher was
* left scanning the retired flat `o.<object>.fields.<field>` dialect after
* #3778 converged the tree on nested `objects.<object>.fields.<field>.label`
* and fixed only service-i18n's copy — a scan that cannot match a real bundle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
{
"id": 16,
"prompt": "Our `consent_change` audit log must show it if anyone edits, inserts or deletes rows directly in the database, but whatever proof is stored must not carry the consent text itself. How do I declare that?",
"expected_output": "Keep `lifecycle.class: 'audit'` with its bounding `retention` (or a `ttl` on `created_at`) and add `seal: { valueFields: ['consent_text'] }`: the audit plugin signs each `created_at` hour into one checkpoint per organization, chained to the one before, where `valueFields` columns enter as salted commitments and every other column in clear. The object declares its own `id` and a text or lookup `tenant_id` field; without that `tenant_id` (and with no `chainField` naming another chain column, such as the injected `organization_id`) it is refused at parse, and without `id` it parses but is not sealed, and the sealer reports it at `error` each hour. Refused at parse: `seal` on a class other than `audit`, `valueFields` naming `id`, `created_at` or an undeclared field, and beside `seal` a `retention` or `ttl` `onlyWhen`, a `ttl` on another field, or rotation `storage`. Signed expiry covers objects whose lifecycle is declared in packaged metadata, as this one is: its sealed rows leave only by whole checkpoints and read as `expired`. With no `archive`, a retention override below the declared window is rejected and the declared window applies; to keep rows for less time, shorten the declared window. On any other sealed object (one created at runtime) the sweeper still deletes sealed rows, which then read as missing. Field history is not tamper evidence.",
"expected_output": "Keep `lifecycle.class: 'audit'` with its bounding `retention` (or a `ttl` on `created_at`) and add `seal: { valueFields: ['consent_text'] }`: the audit plugin signs each `created_at` hour, per organization chain, into one checkpoint (or consecutive checkpoints of at most 10,000 rows), each chained to the one before, where `valueFields` columns enter as salted commitments and every other column in clear. The object declares its own `id` and a text or lookup `tenant_id` field; without that `tenant_id` (and with no `chainField` naming another chain column, such as the injected `organization_id`) it is refused at parse, as is a `chainField` naming a column the object lacks or one that cannot name an organization, and without `id` it parses but is not sealed, and the sealer reports it at `error` each hour. Refused at parse: `seal` on a class other than `audit`, `valueFields` naming `id`, `created_at` or an undeclared field, and beside `seal` a `retention` or `ttl` `onlyWhen`, a `ttl` on another field, or rotation `storage`. Signed expiry covers objects whose lifecycle is declared in packaged metadata, as this one is: its sealed rows leave only by whole checkpoints and read as `expired`. With no `archive`, a retention override below the declared window is rejected and the declared window applies; to keep rows for less time, shorten the declared window. On any other sealed object (one created at runtime) the sweeper still deletes sealed rows, which then read as missing. `os audit verify` checks the ledger and exits 1 on a changed, missing or unsealed row or a chain fault such as a row `listed_twice`. Field history is not tamper evidence.",
"files": [],
"assertions": {
"must_contain": [
Expand Down
109 changes: 39 additions & 70 deletions skills/objectstack-data/rules/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ expired rows under a system context, and reclaims driver space.
## Lifecycle Classes

| Class | Contract | Typical use |
|:------|:---------|:------------|
| `record` | Business truth — permanent; policies FORBIDDEN | accounts, orders, invoices |
|:-|:-|:-|
| `record` | Business truth — permanent; policies FORBIDDEN | accounts, orders |
| `audit` | Compliance ledger — retain → archive → delete | audit trails |
| `telemetry` | High-frequency log — rotation / short retention | activity streams, run history |
| `transient` | Ephemeral state — TTL auto-expire | receipts, codes, sessions |
Expand All @@ -34,58 +34,33 @@ import { ObjectSchema, Field } from '@objectstack/spec/data';
export const ApiCallLog = ObjectSchema.create({
name: 'api_call_log',
sharingModel: 'private',
lifecycle: {
class: 'telemetry',
retention: { maxAge: '14d' }, // reap past 14 days (created_at)
storage: { strategy: 'rotation', shards: 14, unit: 'day' },
},
fields: {
endpoint: Field.text({}),
status: Field.number({}),
},
// reap past 14 days (created_at)
lifecycle: { class: 'telemetry', retention: { maxAge: '14d' }, storage: { strategy: 'rotation', shards: 14, unit: 'day' } },
fields: { endpoint: Field.text({}), status: Field.number({}) },
});

// ✅ Ephemeral token: TTL on its own expiry field
export const ImportTicket = ObjectSchema.create({
name: 'import_ticket',
sharingModel: 'private',
lifecycle: {
class: 'transient',
ttl: { field: 'expires_at', expireAfter: '1d' }, // reap 1 day after expires_at
},
fields: {
expires_at: Field.datetime({}),
},
// reap 1 day after expires_at
lifecycle: { class: 'transient', ttl: { field: 'expires_at', expireAfter: '1d' } },
fields: { expires_at: Field.datetime({}) },
});

// ✅ Compliance ledger: hot window, then cold storage
export const ConsentLog = ObjectSchema.create({
name: 'consent_log',
sharingModel: 'private',
lifecycle: {
class: 'audit',
retention: { maxAge: '90d' },
archive: { after: '90d', to: 'archive', keep: '7y' },
},
fields: {
subject: Field.text({}),
},
lifecycle: { class: 'audit', retention: { maxAge: '90d' }, archive: { after: '90d', to: 'archive', keep: '7y' } },
fields: { subject: Field.text({}) },
});

// ✅ MIXED table: terminal history is telemetry, but paused rows are live
// workflow state — `onlyWhen` scopes the age sweep to the declared filter
// ✅ Mixed table: paused rows are live workflow state — `onlyWhen` scopes the age sweep
export const AutomationRun = ObjectSchema.create({
name: 'sys_automation_run',
lifecycle: {
class: 'telemetry',
retention: {
maxAge: '30d',
onlyWhen: { status: { $in: ['completed', 'failed'] } },
},
},
fields: {
status: Field.select(['running', 'paused', 'completed', 'failed'], {}),
},
lifecycle: { class: 'telemetry', retention: { maxAge: '30d', onlyWhen: { status: { $in: ['completed', 'failed'] } } } },
fields: { status: Field.select(['running', 'paused', 'completed', 'failed'], {}) },
});
```

Expand All @@ -100,20 +75,15 @@ lifecycle: { class: 'telemetry' }
// ❌ archive.after must equal retention.maxAge
lifecycle: { class: 'audit', retention: { maxAge: '90d' }, archive: { after: '30d', to: 'archive' } }

// ❌ onlyWhen + rotation/archive — shard DROPs and the Archiver act on age
// alone and would destroy/move rows the filter protects
lifecycle: {
class: 'telemetry',
retention: { maxAge: '14d', onlyWhen: { status: 'done' } },
storage: { strategy: 'rotation', shards: 14, unit: 'day' },
}
// ❌ onlyWhen + rotation/archive: both act on age alone, destroying/moving rows the filter protects
lifecycle: { class: 'telemetry', retention: { maxAge: '14d', onlyWhen: { status: 'done' } }, storage: { strategy: 'rotation', shards: 14, unit: 'day' } }
```

## Safety Semantics

- **Archive-then-delete**: an object declaring `archive` is never
hot-deleted before the copy to the archive datasource succeeded. If no
datasource is registered under the `archive.to` name, rows are retained.
hot-deleted before the copy to the archive datasource succeeded. No
datasource registered under the `archive.to` name ⇒ rows are retained.
- **Rotation** time-shards the table on SQLite (writes hit the
current shard, reads go through a view under the object's name, expired
shards are DROPped). Other dialects enforce the same window with an
Expand All @@ -123,39 +93,38 @@ lifecycle: {

## Sealing (`seal`)

`seal` makes an `audit` ledger tamper-evident (ADR-0154): an edit, insert or
delete outside the platform breaks its signed checkpoints. Ten minutes after each `created_at`
hour, `@objectstack/plugin-audit` signs its rows into a chained checkpoint
per organization (`tenant_id`; rows with none share a deployment chain); late
rows get a `late` checkpoint. Columns enter in clear, `valueFields` as salted
commitments.
`seal` makes an `audit` ledger tamper-evident (ADR-0154): `os audit verify`
(read-only) exits with code 1 on a changed, missing or unsealed row or a chain fault (a
link, a signature, a row `listed_twice`).

Ten minutes after each `created_at` hour, `@objectstack/plugin-audit` signs
its rows, per organization chain (plus one chain for rows about no
organization), into one checkpoint, or consecutive checkpoints of at most
10,000 rows; late rows get a `late` checkpoint. Columns enter in clear,
`valueFields` as salted commitments.

`chainField` (optional, default `tenant_id`) names the chain column: a text
or lookup column holding the organization id, e.g. the injected
`organization_id`. Fixed once checkpoints exist: a change reads `listed_twice`.

<!-- os:check -->
```typescript
import { ObjectSchema, Field } from '@objectstack/spec/data';

// ✅ The sealer needs declared `id` and `tenant_id`
// ✅ The sealer needs declared `id` and `tenant_id` (stamped on insert)
export const PolicyChangeLog = ObjectSchema.create({
name: 'policy_change_log',
sharingModel: 'private',
lifecycle: { class: 'audit', retention: { maxAge: '1y' }, seal: { valueFields: ['new_value'] } },
fields: {
id: Field.text({}),
tenant_id: Field.lookup('sys_organization', {}), // stamped on insert
new_value: Field.textarea({}),
},
fields: { id: Field.text({}), tenant_id: Field.lookup('sys_organization', {}), new_value: Field.textarea({}) },
});
```

```typescript
// ❌ Refused at parse time: id / created_at order the leaves
seal: { valueFields: ['created_at'] }
```

Also refused: `seal` off class `audit`, an undeclared `valueFields` name, no
text `tenant_id` outside `valueFields` (or `chainField: 'organization_id'`),
and beside `seal` any `onlyWhen`, a `ttl` not on `created_at`, or rotation
`storage`. Unsealed, `error` hourly: no declared `id`; a `password`,
Refused at parse: `seal` off class `audit`, a `valueFields` name that is
undeclared, `id` or `created_at` (they order the leaves), a chain column (`chainField`, else `tenant_id`) the object lacks or that
cannot name an organization (not one text value, `id`, `created_at`, or in
`valueFields`), and beside `seal` any `onlyWhen`, a `ttl` not on
`created_at`, or rotation `storage`. Unsealed, `error` hourly: no declared `id`; a `password`,
`secret`, `formula`, `summary`, `image`, `file`, `avatar`, `video` or `audio`
column; no `cryptoProvider` on `AuditPlugin`.

Expand All @@ -169,9 +138,9 @@ runtime) the sweeper still deletes sealed rows, which then read as missing.
## Operations

| Knob | Where | Effect |
|:-----|:------|:-------|
|:-|:-|:-|
| `enabled` | `lifecycle` settings namespace | Runtime master switch |
| `retention_overrides` | settings, **tenant-scoped** | Per-object window overrides — a regulated tenant sets `'2y'` while dev keeps days; sealed objects: see § Sealing |
| `retention_overrides` | settings, **tenant-scoped** | Per-object window overrides; sealed objects: see § Sealing |
| `quotas` / `quota_defaults` | settings | Row ceilings; breaches ALERT (never delete beyond declared policy) |
| `growth_alert_rows` | settings | Per-sweep growth spike alert |
| `OS_LIFECYCLE_DISABLED=1` | env | Disables sweeping entirely |
Expand Down
Loading
Loading