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
23 changes: 23 additions & 0 deletions .changeset/20015-name-field-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
"@objectstack/plugin-approvals": patch
"@objectstack/service-automation": patch
"@objectstack/service-messaging": patch
---

fix(plugin-approvals, service-automation, service-messaging): five system objects title their records with a text formula instead of the raw id (#20015)

Clause-②: no

ADR-0079 resolves a record's title as `nameField`, then `displayNameField`, then a derivation, and an explicit `nameField` takes precedence over the render-only `titleFormat`. Five system objects declared `nameField: 'id'` beside a composite `titleFormat`. A renderer that follows ADR-0079's order therefore showed the raw record id as the record page's title for:

- `sys_approval_request`, whose `titleFormat` is `{process_name} · {record_id}`;
- `sys_approval_action`, whose `titleFormat` is `{action} · {step_name}`;
- `sys_approval_approver`, whose `titleFormat` is `{approver} · {request_id}`;
- `sys_automation_run`, whose `titleFormat` is `{flow_name} · {node_id}`;
- `sys_http_delivery`, whose `titleFormat` is `{label} → {url}`.

Each object now declares `display_title`, a formula field with `returnType: 'text'` over the same columns, and points `nameField` and `displayNameField` at it. This is the migration the `titleFormat` schema text prescribes: "a composite to a formula field designated as nameField". The record title is now the text the `titleFormat` described. Where a source column is nullable (`step_name`, `node_id`, `label`), a row without it is titled by the other column alone.

A formula field is computed when a record is read. It adds no database column, so no schema migration runs. Record reads and write responses now carry `display_title`. For these objects the server-side title accessor (`resolveRecordTitle`) now returns the formula's text instead of the raw id.

`titleFormat` stays on all five objects, unchanged, for renderers that still read it first. `$search` resolution is unchanged: a formula field is never a search target, and neither was `id`.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.

import { ObjectSchema, Field } from '@objectstack/spec/data';
import { F } from '@objectstack/spec';
import { APPROVAL_ACTION_KINDS, APPROVAL_ACTION_KIND_LABELS } from '@objectstack/spec/contracts';

/**
Expand All @@ -22,8 +23,14 @@ export const SysApprovalAction = ObjectSchema.create({
isSystem: true,
managedBy: 'append-only',
description: 'Append-only audit trail for approval actions',
displayNameField: 'id',
nameField: 'id', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
// [ADR-0079] The record title is `display_title`, a text formula over the
// same two columns `titleFormat` names. The pointer used to be `id`: once a
// renderer honours ADR-0079's order (an explicit `nameField` wins over
// `titleFormat`), that made the record page's H1 the raw id. `titleFormat`
// stays for renderers that still read it first;
// `sys-approval-display-title.test.ts` holds the two to the same text.
displayNameField: 'display_title',
nameField: 'display_title', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
titleFormat: '{action} · {step_name}',
highlightFields: ['request_id', 'step_name', 'action', 'actor_id', 'via_override', 'created_at'],

Expand Down Expand Up @@ -71,6 +78,17 @@ export const SysApprovalAction = ObjectSchema.create({
fields: {
id: Field.text({ label: 'Action ID', required: true, readonly: true, group: 'System' }),

// [ADR-0079] The record title (`nameField` above). A formula is computed on
// read and has no stored column. `step_name` is nullable, so a row without
// one is titled by its action alone rather than failing to evaluate.
display_title: Field.formula({
label: 'Title',
returnType: 'text',
expression: F`record.step_name != null ? record.action + ' · ' + record.step_name : record.action`,
description: 'Record title: the action and, when recorded, its step (computed on read)',
group: 'Action',
}),

organization_id: Field.lookup('sys_organization', {
label: 'Organization',
required: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.

import { ObjectSchema, Field } from '@objectstack/spec/data';
import { F } from '@objectstack/spec';

/**
* sys_approval_approver — Pending-approver index (issue #1745).
Expand Down Expand Up @@ -32,14 +33,31 @@ export const SysApprovalApprover = ObjectSchema.create({
isSystem: true,
managedBy: 'engine-owned',
description: 'Normalized pending-approver rows for indexed inbox queries',
displayNameField: 'id',
nameField: 'id', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
// [ADR-0079] The record title is `display_title`, a text formula over the
// same two columns `titleFormat` names. The pointer used to be `id`: once a
// renderer honours ADR-0079's order (an explicit `nameField` wins over
// `titleFormat`), that made the record page's H1 the raw id. `titleFormat`
// stays for renderers that still read it first;
// `sys-approval-display-title.test.ts` holds the two to the same text.
displayNameField: 'display_title',
nameField: 'display_title', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
titleFormat: '{approver} · {request_id}',
highlightFields: ['request_id', 'approver', 'created_at'],

fields: {
id: Field.text({ label: 'Row ID', required: true, readonly: true, group: 'System' }),

// [ADR-0079] The record title (`nameField` above). A formula is computed on
// read and has no stored column. Both source columns are required, so the
// expression needs no null guard.
display_title: Field.formula({
label: 'Title',
returnType: 'text',
expression: F`record.approver + ' · ' + record.request_id`,
description: 'Record title: the approver identity and its request (computed on read)',
group: 'Target',
}),

organization_id: Field.lookup('sys_organization', {
label: 'Organization',
required: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* The record title of the three approval objects that used to point
* `nameField` at `id` (#20015).
*
* ADR-0079 resolves a record's title as `nameField ?? displayNameField ??
* derivation`, and an explicit `nameField` takes precedence over the
* render-only `titleFormat`. A renderer that honours that order therefore
* showed the raw id as the record page's H1 for `sys_approval_action`,
* `sys_approval_approver` and `sys_approval_request`, because each of them
* declared `nameField: 'id'` beside a composite `titleFormat`.
*
* Each object now points at `display_title`, a text formula over the same
* columns. This file asserts, per object, through the real engine:
*
* 1. the title field ADR-0079's order resolves is `display_title`, not `id`;
* 2. a seeded row read back through `findOne` carries the H1 the
* `titleFormat` intended, and that H1 is not the row's id;
* 3. the server-side title accessor (`resolveRecordTitle`) agrees;
* 4. the formula adds no stored column.
*
* Where a source column is nullable, a row without it is titled by the other
* column rather than failing to evaluate.
*/

import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { ObjectQL, resolveRecordTitle } from '@objectstack/objectql';
import { SqlDriver } from '@objectstack/driver-sql';
import { resolveDisplayField } from '@objectstack/spec/data';
import { SysApprovalAction } from './sys-approval-action.object.js';
import { SysApprovalApprover } from './sys-approval-approver.object.js';
import { SysApprovalRequest } from './sys-approval-request.object.js';

const SYS = { context: { isSystem: true } } as any;

/**
* The H1 a `titleFormat`-first renderer draws: each `{field}` placeholder
* substituted with the row's value. It is the reference the formula has to
* reproduce, not a second title resolver. The parsed schema carries
* `titleFormat` as a `{ dialect: 'template', source }` envelope.
*/
function renderTitleFormat(titleFormat: unknown, row: Record<string, unknown>): string {
const source = typeof titleFormat === 'string' ? titleFormat : (titleFormat as { source?: unknown })?.source;
if (typeof source !== 'string') throw new Error(`titleFormat carries no template source: ${JSON.stringify(titleFormat)}`);
return source.replace(/\{\{?\s*([a-zA-Z0-9_.]+)\s*\}?\}/g, (_m, key: string) => String(row[key] ?? ''));
}

/** The H1 under ADR-0079's order: the value at the resolved title field. */
function h1Of(schema: unknown, row: Record<string, unknown>): unknown {
const field = resolveDisplayField(schema as any);
return field === undefined ? undefined : row[field];
}

/** The stored row as a hook body holds it: no formula value on it. */
function storedOnly(row: Record<string, unknown>): Record<string, unknown> {
const { display_title: _omit, ...rest } = row;
return rest;
}

describe('[#20015] approval objects resolve a real record title under ADR-0079 order', () => {
let engine: ObjectQL;
let driver: SqlDriver;

beforeAll(async () => {
engine = new ObjectQL();
driver = new SqlDriver({
client: 'better-sqlite3',
connection: { filename: ':memory:' },
useNullAsDefault: true,
});
engine.registerDriver(driver, true);
await engine.init();
for (const o of [SysApprovalRequest, SysApprovalAction, SysApprovalApprover]) {
engine.registry.registerObject(o as any, 'com.objectstack.test.20015');
}
await engine.syncSchemas();
});

afterAll(async () => {
try { await engine?.destroy(); } catch { /* noop */ }
});

it('points all three objects at display_title, a text formula', () => {
for (const schema of [SysApprovalRequest, SysApprovalAction, SysApprovalApprover]) {
expect(resolveDisplayField(schema as any)).toBe('display_title');
const field = (schema.fields as Record<string, any>).display_title;
expect(field?.type).toBe('formula');
expect(field?.returnType).toBe('text');
}
});

it('sys_approval_request: the H1 is "{process_name} · {record_id}", not the id', async () => {
const created = await engine.insert('sys_approval_request', {
process_name: 'flow:deal_desk', object_name: 'opportunity', record_id: 'opp_42',
status: 'pending',
}, SYS);
// The write response carries the title too (read-your-write).
expect(created.display_title).toBe('flow:deal_desk · opp_42');
const row = await engine.findOne('sys_approval_request', { where: { id: created.id } }, SYS);
expect(row).not.toBeNull();

expect(h1Of(SysApprovalRequest, row!)).toBe('flow:deal_desk · opp_42');
expect(h1Of(SysApprovalRequest, row!)).not.toBe(row!.id);
expect(h1Of(SysApprovalRequest, row!)).toBe(renderTitleFormat(SysApprovalRequest.titleFormat, row!));
expect(resolveRecordTitle(SysApprovalRequest, storedOnly(row!))).toBe('flow:deal_desk · opp_42');
});

it('sys_approval_action: the H1 is "{action} · {step_name}", and the action alone without a step', async () => {
const request = await engine.insert('sys_approval_request', {
process_name: 'flow:deal_desk', object_name: 'opportunity', record_id: 'opp_43',
status: 'pending',
}, SYS);

const stepped = await engine.insert('sys_approval_action', {
request_id: request.id, action: 'approve', step_name: 'manager_review',
}, SYS);
const row = await engine.findOne('sys_approval_action', { where: { id: stepped.id } }, SYS);
expect(h1Of(SysApprovalAction, row!)).toBe('approve · manager_review');
expect(h1Of(SysApprovalAction, row!)).not.toBe(row!.id);
expect(h1Of(SysApprovalAction, row!)).toBe(renderTitleFormat(SysApprovalAction.titleFormat, row!));
expect(resolveRecordTitle(SysApprovalAction, storedOnly(row!))).toBe('approve · manager_review');

const stepless = await engine.insert('sys_approval_action', {
request_id: request.id, action: 'submit',
}, SYS);
const bare = await engine.findOne('sys_approval_action', { where: { id: stepless.id } }, SYS);
expect(bare!.step_name ?? null).toBeNull();
expect(h1Of(SysApprovalAction, bare!)).toBe('submit');
expect(resolveRecordTitle(SysApprovalAction, storedOnly(bare!))).toBe('submit');
});

it('sys_approval_approver: the H1 is "{approver} · {request_id}", not the id', async () => {
const request = await engine.insert('sys_approval_request', {
process_name: 'flow:deal_desk', object_name: 'opportunity', record_id: 'opp_44',
status: 'pending',
}, SYS);
const created = await engine.insert('sys_approval_approver', {
request_id: request.id, approver: 'role:finance',
}, SYS);
const row = await engine.findOne('sys_approval_approver', { where: { id: created.id } }, SYS);

expect(h1Of(SysApprovalApprover, row!)).toBe(`role:finance · ${request.id}`);
expect(h1Of(SysApprovalApprover, row!)).not.toBe(row!.id);
expect(h1Of(SysApprovalApprover, row!)).toBe(renderTitleFormat(SysApprovalApprover.titleFormat, row!));
expect(resolveRecordTitle(SysApprovalApprover, storedOnly(row!))).toBe(`role:finance · ${request.id}`);
});

it('adds no stored column: the formula is computed on read', async () => {
for (const [object, sourceColumn] of [
['sys_approval_request', 'process_name'],
['sys_approval_action', 'step_name'],
['sys_approval_approver', 'approver'],
] as const) {
const columns = Object.keys(await driver.getKnex()(object).columnInfo());
expect(columns).toContain(sourceColumn);
expect(columns).not.toContain('display_title');
}
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.

import { ObjectSchema, Field } from '@objectstack/spec/data';
import { F } from '@objectstack/spec';
import {
APPROVAL_STATUSES,
APPROVAL_STATUS_LABELS,
Expand Down Expand Up @@ -44,8 +45,14 @@ export const SysApprovalRequest = ObjectSchema.create({
isSystem: true,
managedBy: 'engine-owned',
description: 'Live approval instance tracked per submission',
displayNameField: 'id',
nameField: 'id', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
// [ADR-0079] The record title is `display_title`, a text formula over the
// same two columns `titleFormat` names. The pointer used to be `id`: once a
// renderer honours ADR-0079's order (an explicit `nameField` wins over
// `titleFormat`), that made the record page's H1 the raw id. `titleFormat`
// stays for renderers that still read it first;
// `sys-approval-display-title.test.ts` holds the two to the same text.
displayNameField: 'display_title',
nameField: 'display_title', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
titleFormat: '{process_name} · {record_id}',
highlightFields: ['process_name', 'object_name', 'record_id', 'status', 'current_step', 'submitter_id', 'updated_at'],

Expand Down Expand Up @@ -103,6 +110,17 @@ export const SysApprovalRequest = ObjectSchema.create({
fields: {
id: Field.text({ label: 'Request ID', required: true, readonly: true, group: 'System' }),

// [ADR-0079] The record title (`nameField` above). A formula is computed on
// read and has no stored column. Both source columns are required, so the
// expression needs no null guard.
display_title: Field.formula({
label: 'Title',
returnType: 'text',
expression: F`record.process_name + ' · ' + record.record_id`,
description: 'Record title: the request source and the record it is about (computed on read)',
group: 'Target',
}),

// [#10101, the cloud#1395 Option A ruling] The SUBJECT record's
// organization, with the acting context as fallback — resolved by the
// SHARED platform-row resolver (`resolveRecordOrganizationField`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
id: {
label: "Request ID"
},
display_title: {
label: "Title",
help: "Record title: the request source and the record it is about (computed on read)"
},
organization_id: {
label: "Organization",
help: "Organization of the record this request is about (falls back to the acting context when the record has none)"
Expand Down Expand Up @@ -212,6 +216,10 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
id: {
label: "Action ID"
},
display_title: {
label: "Title",
help: "Record title: the action and, when recorded, its step (computed on read)"
},
organization_id: {
label: "Organization",
help: "Tenant that owns this action (mirrors the parent request)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const esESObjects: NonNullable<TranslationData['objects']> = {
id: {
label: "ID de solicitud"
},
display_title: {
label: "Título",
help: "Título del registro: el origen de la solicitud y el registro al que se refiere (calculado al leer)"
},
organization_id: {
label: "Organización",
help: "Organización del registro al que se refiere esta solicitud (recurre al contexto del actor cuando el registro no tiene ninguna)."
Expand Down Expand Up @@ -212,6 +216,10 @@ export const esESObjects: NonNullable<TranslationData['objects']> = {
id: {
label: "ID de acción"
},
display_title: {
label: "Título",
help: "Título del registro: la acción y, si consta, su paso (calculado al leer)"
},
organization_id: {
label: "Organización",
help: "Tenant que posee esta acción (refleja la solicitud principal)."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const jaJPObjects: NonNullable<TranslationData['objects']> = {
id: {
label: "リクエスト ID"
},
display_title: {
label: "タイトル",
help: "レコードタイトル:申請のソースと対象レコード(読み取り時に計算)"
},
organization_id: {
label: "組織",
help: "このリクエストの対象レコードが属する組織(レコードに組織がない場合は操作コンテキストにフォールバック)"
Expand Down Expand Up @@ -212,6 +216,10 @@ export const jaJPObjects: NonNullable<TranslationData['objects']> = {
id: {
label: "アクション ID"
},
display_title: {
label: "タイトル",
help: "レコードタイトル:アクションと、記録されている場合はそのステップ(読み取り時に計算)"
},
organization_id: {
label: "組織",
help: "このアクションを所有するテナント(親リクエストと同じ)"
Expand Down
Loading
Loading