Skip to content

Commit 7d84d05

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-tiru7x
2 parents 2280a66 + 48c7780 commit 7d84d05

22 files changed

Lines changed: 557 additions & 110 deletions

‎.changeset/27626-record-open-requests.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Measured in the console on app-crm, opening one record from a list and closing i
1212

1313
- **The list under the drawer is not read again.** The first record opened replaced the list with the route skeleton (the drawer made the route read the whole object registry instead of the app's object scope, and the route waited for it), so the list mounted again and re-read its rows; every later open and close handed the list a different document for its object, which rebuilt its columns and re-ran the list query. The drawer now reads the whole registry beside the route's scope, without holding the route, and the registry joins the scope once it lands with the scope's own documents kept as they are. The list page also holds `columns` and `searchableFields` by value, as it holds the view-type blocks. The record form overlay (`?form=`) still reads the whole registry.
1414
- **One field-access request per record.** The record's sections, highlights, form and page each asked `GET /data/:object/:id/field-access` at once; `ObjectStackAdapter.getRecordFieldAccess` now shares one request between concurrent asks for the same record, remembers a 404 for that record until a write to its object, and stops asking a server that answers 501. A settled answer is not cached: the next ask after a save reaches the server.
15-
- **The bell polls once a minute.** The inbox and approvals feeds polled every 10 s and 30 s on every console page. With no realtime channel in the platform, they now poll every 60 s in the foreground, still stop in a hidden tab, and stop polling altogether while a host reports an open push channel (a pushed change reads the feed it names). A new inbox message can show up to about a minute later.
15+
- **The bell polls once a minute.** The inbox and approvals feeds polled every 10 s and 30 s on every console page. With no realtime channel in the platform, they now poll every 60 s in the foreground, every three minutes while the tab is hidden (and not at all once it has been hidden for ten minutes), and stop polling altogether while a host reports an open push channel (a pushed change reads the feed it names). A new inbox message can show up to about a minute later.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/core': patch
3+
---
4+
5+
fix(core): an import lookup cell also resolves by the target object's unique fields, an autonumber included
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A data import lookup cell is matched against the target object's id, the lookup's `displayField`, the target's title field and the fixed keys `name`, `title`, `label`, `full_name`, `email`, `username`. A cell holding the target's autonumber (`ACC-000012`) or another unique field matched none of them and answered `reference_not_found`, so a title change broke every export file written before it.
11+
12+
The matcher now also asks, after those candidates and in the target's declared field order, every field whose `unique` declares a constraint (`true`, `'organization'`, `'global'`) and every `autonumber` field that omits `unique` (unique per organization by the spec's default). An autonumber declared `unique: false` is not asked. The existing rules are unchanged: the first field to match wins, an earlier candidate that matches still wins, a field that matches more than one record answers `reference_ambiguous`, and a cell matching nothing answers `reference_not_found`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/service-settings': patch
3+
---
4+
5+
fix(i18n): the Data Lifecycle settings page reads in the admin's language
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Setup → All Settings → Data Lifecycle read English under Chinese (zh-CN), Japanese (ja-JP) and Spanish (es-ES): the hub card's title and description and every field on the page, while every other settings page and the Setup sidebar entry for this page were translated. The page now reads in those languages too: its title, description, and each field's label and help (Enforce lifecycle policies, Retention overrides, Row quotas, Per-class quota defaults, Growth alert threshold). The hub card and the sidebar entry now carry the same name in every shipped locale.
11+
12+
Nothing to do: the translations ship in the built-in settings bundle and load with the settings service, as the other pages' do. The JSON examples inside the help text stay as written, since they are the values you type.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/service-settings': patch
3+
---
4+
5+
fix(service-settings): AI & Embedder and Knowledge help is in business words
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On Setup → Settings → AI & Embedder and Knowledge, the help under several fields read like code comments, in every language: "Forwarded as OPENAI_API_KEY", traces saved "to sys_ai_trace", "Chunks per embed() call", "Per-source values on KnowledgeSource.adapterConfig take precedence", "topK × overFetch". The help now says what each setting does:
11+
12+
- A provider API key or the gateway model is "used instead of the one set in the server configuration".
13+
- Record traces keeps a record of each AI request and its response, so a conversation can be inspected and replayed.
14+
- Batch size is the number of chunks sent to the embedding provider in one request.
15+
- Indexing defaults: a value set on a knowledge source itself wins over these defaults.
16+
- Over-fetch multiplier: search fetches this many times the requested number of results, so enough are left after filtering.
17+
18+
The English, Chinese, Japanese and Spanish text changed together. No setting, default or accepted value changed, and model examples such as openai/gpt-4o stay as written because they are what you type.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
perf(console): a background tab checks the bell and the approvals badge every three minutes instead of every minute
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Since the bell's foreground poll moved to once a minute, a hidden console tab polled just as often as a visible one for its first ten minutes. A hidden tab now polls every three minutes (the foreground tick already armed when the tab hides still fires once), still stops polling altogether after ten hidden minutes, and reads each feed once, at once, when the user comes back. A desktop notification for a new inbox message in a background tab can now arrive up to about three minutes late instead of one.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#27947] An import cell is also resolved against a lookup TARGET's unique
5+
* fields: every field whose `unique` declares a constraint (`isUniqueDeclared`:
6+
* `true`, `'organization'`, `'global'`), and every `autonumber` field that
7+
* omits `unique`, which the spec makes `unique: 'organization'` by contract.
8+
* An autonumber that writes `unique: false` has opted out and is not asked.
9+
*
10+
* They are asked AFTER the existing candidates (the id, the lookup's
11+
* `displayField`, the target's title field, the fixed human keys), in the
12+
* target's declared field order, each at most once. The existing rules hold:
13+
* the first field to match wins, and a field matching more than one record is
14+
* `reference_ambiguous`, never a silent pick.
15+
*
16+
* The fake's `findData` answers like the engine: equality over the stored row.
17+
*/
18+
19+
import { describe, it, expect, vi } from 'vitest';
20+
import { runImport, type ImportProtocolLike } from './import-runner';
21+
import type { ExportFieldMeta } from './import-field-meta.js';
22+
23+
type FindArgs = Parameters<ImportProtocolLike['findData']>[0];
24+
type Row = Record<string, unknown>;
25+
type Declaration = { fields: Record<string, Row>; nameField?: string };
26+
27+
const TEXT = { type: 'text' };
28+
29+
const DECLARATIONS: Record<string, Declaration> = {
30+
xu_account: {
31+
nameField: 'name',
32+
fields: {
33+
name: TEXT,
34+
// The contract default: an autonumber that omits `unique` is unique.
35+
account_number: { type: 'autonumber', autonumberFormat: 'ACC-{000000}' },
36+
region: TEXT,
37+
tax_id: { type: 'text', unique: true },
38+
// An opted-out autonumber: a display-only ordinal, never asked.
39+
ordinal: { type: 'autonumber', unique: false },
40+
external_code: { type: 'text', unique: 'global' },
41+
// Already a fixed key: asked once, in its fixed place.
42+
email: { type: 'email', unique: 'organization' },
43+
},
44+
},
45+
};
46+
47+
const ROWS: Record<string, Row[]> = {
48+
xu_account: [
49+
{ id: 'a1', name: 'Acme', account_number: 'ACC-000012', region: 'EMEA', tax_id: 'TX-1', ordinal: '7', external_code: 'EXT-1' },
50+
// A name that equals another record's autonumber: the name is asked first.
51+
{ id: 'a2', name: 'ACC-000013', account_number: 'ACC-000002', region: 'APAC', tax_id: 'TX-2', ordinal: '8' },
52+
{ id: 'a3', name: 'Globex', account_number: 'ACC-000013', region: 'APAC', tax_id: 'TX-3', ordinal: '9' },
53+
// Two holders of one tax id, as a read across organizations can see.
54+
{ id: 'a4', name: 'Initech', account_number: 'ACC-000004', tax_id: 'TX-SHARED', ordinal: '10' },
55+
{ id: 'a5', name: 'Umbrella', account_number: 'ACC-000005', tax_id: 'TX-SHARED', ordinal: '11' },
56+
],
57+
};
58+
59+
const metaMap = new Map<string, ExportFieldMeta>([
60+
['name', { name: 'name', type: 'text' }],
61+
['account', { name: 'account', type: 'lookup', reference: 'xu_account' }],
62+
]);
63+
64+
function protocol() {
65+
const findData = vi.fn(async (args: FindArgs) => {
66+
const [[field, value]] = Object.entries(args.query!.where!);
67+
return (ROWS[args.object] ?? []).filter((r) => r[field] === value);
68+
});
69+
const getMetaItem = vi.fn(async ({ name }: { type: string; name: string }) =>
70+
({ type: 'object', name, item: { name, ...DECLARATIONS[name] } }));
71+
const createData = vi.fn(async (a: { data: Row }) => ({ id: 'new', ...a.data }));
72+
const p: ImportProtocolLike = { findData, getMetaItem, createData, updateData: vi.fn() };
73+
return { p, findData, createData };
74+
}
75+
76+
const run = (p: ImportProtocolLike, rows: Row[]) =>
77+
runImport({
78+
p, context: {}, objectName: 'xu_source', metaMap, writeMode: 'insert', matchFields: [], dryRun: false,
79+
runAutomations: false, trimWhitespace: true, createMissingOptions: false, skipBlankMatchKey: false, rows,
80+
});
81+
82+
/** The `where` keys asked of the target, in order. */
83+
const asked = (findData: ReturnType<typeof protocol>['findData']) =>
84+
findData.mock.calls.filter(([a]) => a.object === 'xu_account').map(([a]) => Object.keys(a.query!.where!)[0]);
85+
86+
const verdict = (r: { ok: boolean; code?: string; field?: string }) => ({ ok: r.ok, code: r.code, field: r.field });
87+
const OK = { ok: true, code: undefined, field: undefined };
88+
const FIXED = ['id', 'name', 'title', 'label', 'full_name', 'email', 'username'];
89+
90+
describe('[#27947] import resolves a lookup cell by the target object\'s unique fields', () => {
91+
it('an autonumber cell (ACC-000012) resolves, asked after every existing candidate', async () => {
92+
const { p, findData, createData } = protocol();
93+
const summary = await run(p, [{ name: 'r', account: 'ACC-000012' }]);
94+
expect(summary.results.map(verdict)).toEqual([OK]);
95+
expect(createData.mock.calls.map(([a]) => a.data.account)).toEqual(['a1']);
96+
expect(asked(findData)).toEqual([...FIXED, 'account_number']);
97+
});
98+
99+
it('another declared-unique field (tax_id, unique: true) resolves', async () => {
100+
const { p, findData, createData } = protocol();
101+
const summary = await run(p, [{ name: 'r', account: 'TX-3' }]);
102+
expect(summary.results.map(verdict)).toEqual([OK]);
103+
expect(createData.mock.calls.map(([a]) => a.data.account)).toEqual(['a3']);
104+
expect(asked(findData)).toEqual([...FIXED, 'account_number', 'tax_id']);
105+
});
106+
107+
it('an earlier candidate that matches still wins: the name ACC-000013 links a2, not a3\'s autonumber', async () => {
108+
const { p, findData, createData } = protocol();
109+
const summary = await run(p, [{ name: 'r', account: 'ACC-000013' }]);
110+
expect(summary.results.map(verdict)).toEqual([OK]);
111+
expect(createData.mock.calls.map(([a]) => a.data.account)).toEqual(['a2']);
112+
expect(asked(findData)).toEqual(['id', 'name']);
113+
});
114+
115+
it('a value matching nothing still answers reference_not_found, after the unique fields in declared order', async () => {
116+
const { p, findData, createData } = protocol();
117+
const summary = await run(p, [{ name: 'r', account: 'ACC-999999' }]);
118+
expect(summary.results.map(verdict)).toEqual([{ ok: false, code: 'reference_not_found', field: 'account' }]);
119+
expect(createData).not.toHaveBeenCalled();
120+
// Declared order, `email` not asked twice, the opted-out `ordinal` never.
121+
expect(asked(findData)).toEqual([...FIXED, 'account_number', 'tax_id', 'external_code']);
122+
});
123+
124+
it('an opted-out autonumber (unique: false) is not asked: its value answers reference_not_found', async () => {
125+
const { p, findData } = protocol();
126+
const summary = await run(p, [{ name: 'r', account: '7' }]);
127+
expect(summary.results.map(verdict)).toEqual([{ ok: false, code: 'reference_not_found', field: 'account' }]);
128+
expect(asked(findData)).not.toContain('ordinal');
129+
});
130+
131+
it('a unique field two records answer is still reference_ambiguous, and links neither', async () => {
132+
const { p, findData, createData } = protocol();
133+
const summary = await run(p, [{ name: 'r', account: 'TX-SHARED' }]);
134+
expect(summary.results.map(verdict)).toEqual([{ ok: false, code: 'reference_ambiguous', field: 'account' }]);
135+
expect(createData).not.toHaveBeenCalled();
136+
expect(asked(findData)).toEqual([...FIXED, 'account_number', 'tax_id']);
137+
});
138+
});

‎packages/core/src/utils/import-runner.ts‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { coerceRow, type CoerceContext, type RefResolver, type RefMatch } from '
55
import type { ExportFieldMeta } from './import-field-meta.js';
66
import type { ValidationMessageTranslator } from '@objectstack/spec/system';
77
import {
8-
canServeApiOperation, isMultiValueField, isVirtualSearchField, resolveDisplayField, STRUCTURED_JSON_TYPES,
8+
canServeApiOperation, isMultiValueField, isUniqueDeclared, isVirtualSearchField, resolveDisplayField, STRUCTURED_JSON_TYPES,
99
type DisplayNameObjectMeta, type DroppedFieldsEvent, type EnableLike, type SearchFieldMeta,
1010
} from '@objectstack/spec/data';
1111
import type { ExecutionContext } from '@objectstack/spec/kernel';
@@ -639,12 +639,33 @@ async function servesReferenceTarget(p: ImportProtocolLike, target: string): Pro
639639
}
640640
if (!canServeApiOperation(item?.enable, REFERENCE_TARGET_OPERATION)) return null;
641641
if (!item || typeof item !== 'object') return {};
642+
const fields = item.fields as ServedReferenceTarget['fields'];
642643
return {
643644
titleField: resolveDisplayField(item),
644-
fields: item.fields as ServedReferenceTarget['fields'],
645+
fields,
646+
uniqueFields: Object.keys(fields ?? {}).filter((f) => isUniqueReferenceField(fields?.[f])),
645647
};
646648
}
647649

650+
/**
651+
* [#27947] Does this target field name at most one record, so a cell holding
652+
* its value identifies the record? Yes when its `unique` declares a constraint
653+
* (`isUniqueDeclared`: `true`, `'organization'`, `'global'`), and for an
654+
* `autonumber` that omits `unique`: the spec makes that field
655+
* `unique: 'organization'` by contract (`FieldSchema`'s autonumber default),
656+
* and the default is applied here too in case the declaration was read
657+
* unparsed. An autonumber that writes `unique: false` has opted out (a
658+
* display-only ordinal) and is not an identifier.
659+
*/
660+
function isUniqueReferenceField(meta: ReferenceTargetFieldMeta | undefined): boolean {
661+
if (!meta) return false;
662+
if (isUniqueDeclared(meta.unique)) return true;
663+
return meta.type === 'autonumber' && meta.unique === undefined;
664+
}
665+
666+
/** The slice of a lookup target's field declaration the reference resolution reads. */
667+
type ReferenceTargetFieldMeta = SearchFieldMeta & { unique?: unknown };
668+
648669
/** The slice of a lookup target's declaration the reference resolution reads. */
649670
type ReferenceTargetDeclaration = DisplayNameObjectMeta & { enable?: EnableLike | null };
650671

@@ -662,11 +683,18 @@ interface ServedReferenceTarget {
662683
*/
663684
titleField?: string;
664685
/**
665-
* The target's declared field map. It is read for one question only: which
686+
* The target's declared field map. It is read for two questions: which
666687
* candidate fields are virtual ({@link isVirtualSearchField}), because a
667-
* `where` over a virtual field is refused by the engine's filter seam.
688+
* `where` over a virtual field is refused by the engine's filter seam, and
689+
* which are unique ({@link ServedReferenceTarget.uniqueFields}).
690+
*/
691+
fields?: Readonly<Record<string, ReferenceTargetFieldMeta | undefined>>;
692+
/**
693+
* [#27947] The target's unique fields ({@link isUniqueReferenceField}), in
694+
* declared order: the last candidates a cell is asked by, so an export file
695+
* written before a record's title changed still resolves by its autonumber.
668696
*/
669-
fields?: Readonly<Record<string, SearchFieldMeta | undefined>>;
697+
uniqueFields?: readonly string[];
670698
}
671699

672700
/** Upper bound on rows in one createManyData batch (framework#2678 suggests 100-500). */
@@ -821,7 +849,10 @@ export function runImport(opts: RunImportOptions): Promise<ImportRunSummary> {
821849
// Try an exact id first (authoritative + unique when the user pasted an id),
822850
// then the configured display field, then the target's own title field
823851
// (#24981: ADR-0079's rule, the field the list export writes the cell by),
824-
// then the usual human identifiers. De-dupe so a field isn't queried twice.
852+
// then the usual human identifiers, then the target's unique fields in
853+
// declared order (#27947: an autonumber included, so a cell naming the
854+
// record by its number resolves after a title change). De-dupe so a field
855+
// isn't queried twice.
825856
// The first candidate field to match wins; if that field matches >1 record
826857
// we stop and report ambiguity rather than silently linking the first.
827858
//
@@ -836,6 +867,7 @@ export function runImport(opts: RunImportOptions): Promise<ImportRunSummary> {
836867
...(meta.displayField ? [meta.displayField] : []),
837868
...(target.titleField ? [target.titleField] : []),
838869
'name', 'title', 'label', 'full_name', 'email', 'username',
870+
...(target.uniqueFields ?? []),
839871
])].filter((f) => !isVirtualSearchField(target.fields?.[f]));
840872
const lookup = async (): Promise<RefMatch> => {
841873
let match: RefMatch = {};

0 commit comments

Comments
 (0)