diff --git a/.changeset/35394-context-token-temporal-door.md b/.changeset/35394-context-token-temporal-door.md index 64104d4b561..6724a921a4d 100644 --- a/.changeset/35394-context-token-temporal-door.md +++ b/.changeset/35394-context-token-temporal-door.md @@ -22,6 +22,6 @@ The engine's judge-only admission runs the same door, and so do two of its reade - `IObjectQLEngine.judgeFilter` answers `{ ok: false, code: 'INVALID_FILTER', status: 400 }` for this spelling on a temporal field. With a session it answered `{ ok: true }`; without one it answered `FILTER_TOKEN_UNRESOLVED`. - Lint's row-scope predicate rule (`rls-predicate-unenforceable`) still refuses a predicate such as `due_on < '{current_user_id}'`. The finding now quotes `INVALID_FILTER / 400` with the hint to rewrite the comparison, where it quoted `FILTER_TOKEN_UNRESOLVED / 400` with the hint to write the caller's value as a `current_user` key. -- Analytics read-scope admission: when the analytics service asks the engine to admit an object's read scope, a scope that compares a `date` or `datetime` field with a context placeholder is now refused at compile, `READ_SCOPE_COMPILE_FAILED` (500, fail-closed). After the upgrade, a dashboard or analytics query over such an object answers 500 until that clause is rewritten as below. +- Analytics read-scope admission: when the analytics service asks the engine to admit an object's read scope, a scope that compares a `date`, `datetime` or `time` field with a context placeholder is now refused at compile, `READ_SCOPE_COMPILE_FAILED` (500, fail-closed). After the upgrade, a dashboard or analytics query over such an object answers 500 until that clause is rewritten as below. The fix for an author: compare the date field against a date (a `YYYY-MM-DD` day, an ISO-8601 instant, or a date macro such as `{30_days_ago}`), and compare the user or organization id against the field that holds it, such as `owner_id`. In a row-level-security predicate, write `owner == current_user.id`. diff --git a/.changeset/t1-stale-prose.md b/.changeset/t1-stale-prose.md new file mode 100644 index 00000000000..1629638aa02 --- /dev/null +++ b/.changeset/t1-stale-prose.md @@ -0,0 +1,20 @@ +--- +'@objectstack/spec': patch +'@objectstack/objectql': patch +'@objectstack/core': patch +'@objectstack/lint': patch +'@objectstack/service-analytics': patch +'@object-ui/fields': patch +--- + +docs: stale prose on summary currency, the temporal-comparand door and analytics filters now says what the code does + +Clause-②: no +Metadata-protocol: none + +No accepted value, key or answer moves. Two refusal messages change their words: + +- A `currencyMode: 'dynamic'` summary over a child `currency` field that is neither `dynamic` nor a well-formed `record` / `fixed` (a stored `fixed` field with no `defaultCurrency`, or a `currencyMode` outside the three) is still refused, and the refusal now names what the child lacks: "is a 'currency' field in `fixed` mode with no `defaultCurrency` code (the currency it is fixed to is missing)", or "is a 'currency' field whose `currencyMode` 'X' is none of `dynamic`, `fixed` and `record`". Before, it said only "is a 'currency' field, not a `currency` field in `dynamic` mode". +- The temporal-comparand door's refusal of a comparand no temporal rule reads (`'not-a-date'`, the preset name `'last_30_days'`) now ends "As written it would reach the driver and be compared as text: it may select every row, none or the wrong ones (or raise a database error), an answer indistinguishable from a real one." Before, it said the comparison would "compare false for EVERY row", which was wrong for `$lt` and others that selected every row, for a partial day such as `'2026-06'` that selected a subset, and on PostgreSQL, which raised a database error. Its `having` twin says the same of the groups it would keep, where it said "no group or every group, a 200". + +The upgrade-guide entry `summary-dynamic-currency-rollup-home-amount-judged-as-served` now states the admitted set as both doors enforce it: a `dynamic` summary may roll up any child `currency` field in `dynamic` mode, a stored home amount included. Source comments and published docblocks that said every `{placeholder}` is stepped around by the temporal door now state the per-kind rule: a date macro is stepped around and judged by its year once resolved, a period key and a context token are judged as written, and an unknown or record-context token is left to the resolver. diff --git a/content/docs/ui/dashboards.mdx b/content/docs/ui/dashboards.mdx index 0fb385c1d65..b433ed3ec22 100644 --- a/content/docs/ui/dashboards.mdx +++ b/content/docs/ui/dashboards.mdx @@ -577,14 +577,18 @@ the base rows whose relationship points at a record it returned: unfiltered set. - A related field the caller cannot read is refused (`403 PERMISSION_DENIED`), as filtering on it directly would be. -- On a SQL datasource the related condition runs inside the same statement, as - a subquery, so the number of matching related records is not limited. Where - the engine reads the matching related ids first instead (a related object on - another datasource, a federated one, or a driver that compiles no subquery, - such as MongoDB; the full list is in - [Query Syntax](/docs/protocol/objectql/query-syntax)), more than 1,000 of them - are refused (`400 INVALID_FILTER`), never truncated. Narrow the related - condition. +- On a SQL datasource a condition through a single-valued relation usually + runs inside the same statement, as a subquery, so the number of matching + related records is not limited. Where the engine reads the matching related + ids first instead (a multi-valued relation, on every driver; a related object + on another datasource, a federated one, one whose reads an object-scoped + middleware or an `afterFind` hook shapes, or one read under different driver + options than the queried object, its tenant scope most commonly; the full + list is in [Query Syntax](/docs/protocol/objectql/query-syntax)), more than + 1,000 of them are refused (`400 INVALID_FILTER`), never truncated. Narrow the + related condition. On a driver that cannot run it in one read (MongoDB, + OData), a condition through a single-valued relation is refused before + anything is read (`400 INVALID_FILTER`), naming the two-step route. - These are refused (`400 INVALID_FIELD`) rather than answered differently: a path of four or more relationships (`line.plan.order.customer.tier`), a related-field condition under `$not` (write `$ne` / `$nin` inside the diff --git a/packages/core/src/utils/import-coerce.ts b/packages/core/src/utils/import-coerce.ts index ce479042f3a..31754821ccf 100644 --- a/packages/core/src/utils/import-coerce.ts +++ b/packages/core/src/utils/import-coerce.ts @@ -348,8 +348,10 @@ function pad2(n: number): string { * read back unchanged, and it reads `07/15/2026 10:00` through `Date.parse` * in the host's zone and rolls `2026-02-30T10:00:00Z` over to March 2, both of * which the verdict refuses. A `{placeholder}` is filter vocabulary, which the - * verdict steps around rather than judges, so it is refused here, as the write - * door refuses it. + * verdict does not refuse whole: it steps around a date macro and an unknown or + * record-context token, and judges only a period key and a context token as + * written. So every placeholder is refused here first, by + * `classifyFilterToken`, as the write door refuses it. * * This replaced a private pattern with no fractional part, which refused the * `10:00:00.250` that `/export` writes for a `time` with milliseconds, so such diff --git a/packages/lint/src/validate-rls-predicate-enforceability.ts b/packages/lint/src/validate-rls-predicate-enforceability.ts index 3d8849d429b..0162a9c1f90 100644 --- a/packages/lint/src/validate-rls-predicate-enforceability.ts +++ b/packages/lint/src/validate-rls-predicate-enforceability.ts @@ -202,10 +202,17 @@ * app-staged set holds app data this rule cannot know: measured, * `close_date in current_user.holidays` lowered with the probe string is * refused by the temporal door, while with `[]` it is admitted. - * - **With what context:** none. A `{placeholder}` string in a predicate - * therefore answers `FILTER_TOKEN_UNRESOLVED` (known) or - * `FILTER_TOKEN_UNKNOWN` (unknown) — the engine's own semantics for a filter - * judged with no caller. An RLS predicate names the caller as `current_user.*`. + * - **With what context:** none, so a `{placeholder}` string in a predicate + * answers as the engine answers a filter judged with no caller. The + * field-aware doors run first: on a `date`, `datetime` or `time` field a + * period key or a context token is judged as written and answers + * `INVALID_FILTER` (the temporal door), and on a number or a boolean field + * every placeholder does (the number door and its boolean arm). Otherwise + * the resolver answers: a + * context token or a record-context token `FILTER_TOKEN_UNRESOLVED`, an + * unknown one `FILTER_TOKEN_UNKNOWN`, while a date macro and a period key + * resolve with no caller (a date macro then judged by its year). An RLS + * predicate names the caller as `current_user.*`. * - **When:** only when every pass above left this clause clean, so one * defect earns one finding. * diff --git a/packages/objectql/src/engine-delete-and-aggregate.ts b/packages/objectql/src/engine-delete-and-aggregate.ts index 03cd568986d..6de660d2085 100644 --- a/packages/objectql/src/engine-delete-and-aggregate.ts +++ b/packages/objectql/src/engine-delete-and-aggregate.ts @@ -1177,7 +1177,10 @@ export class DeleteAndAggregateFacet { // bound in a `where` was refused 400 — measured on the base on // driver-memory and driver-sql, through the engine and REST. // Before the token resolver below, as there, so a `{placeholder}` - // is stepped around and resolved (or refused) a moment later. + // is judged by its kind as there: a date macro is stepped around + // and judged by its year once resolved, a period key or a context + // token is judged as written, and an unknown or record-context + // token is left to the resolver, which refuses it a moment later. // [#20334] Rooted at this position too: the refusal said // `at where.placed_on.$gt`. assertTemporalComparandsInterpretable( @@ -1443,9 +1446,11 @@ export class DeleteAndAggregateFacet { // group with a 200). Both `applyHaving` doors below read `ast.having`, so // one call covers the native and the rows path, before any driver read. // After every `having` door above, as `where`'s resolution follows its - // doors: the temporal door steps around a `{placeholder}` exactly as - // `where`'s does (so, as there, the resolved value is judged only for - // its year, by the resolution stage — #20844), and the other doors + // doors: the temporal door judges a `{placeholder}` by its kind exactly + // as `where`'s does (a date macro stepped around, so, as there, its + // resolved value is judged only for its year, by the resolution stage — + // #20844; a period key or a context token judged as written; an unknown + // or record-context token left to this resolver), and the other doors // judged a string that resolves to a string. { const havingColumnTypes = aggregatedRowColumnTypes(query.groupBy, query.aggregations, declaredFields); diff --git a/packages/objectql/src/engine-temporal-comparand-door.test.ts b/packages/objectql/src/engine-temporal-comparand-door.test.ts index 2a86753725c..e952e980e5f 100644 --- a/packages/objectql/src/engine-temporal-comparand-door.test.ts +++ b/packages/objectql/src/engine-temporal-comparand-door.test.ts @@ -197,6 +197,9 @@ describe('[#8690] the temporal-comparand door at the engine collection point', ( expect(err!.message).toContain('created_date'); expect(err!.message).toContain(comparand); expect(err!.message).toMatch(/NOT applied/); + // The junk class's consequence, the phrase the misread and year classes + // are pinned NOT to carry: compared as text, every row, none or the wrong ones. + expect(err!.message).toContain('compared as text: it may select every row, none or the wrong ones'); // And no driver read happened — the refusal precedes the driver. expect(reads).toHaveLength(0); } @@ -446,8 +449,8 @@ describe('[#20549] the comparand door refuses what the write door refuses — a expect(err!.message).toContain(`'${field}'`); expect(err!.message).toMatch(/NOT applied/); // Not junk: the rule READ it, as the wrong value, so the refusal does - // not claim it would have compared false for every row. - expect(err!.message, `${field} ${value}`).not.toContain('compare false for EVERY row'); + // not claim the junk class's "compared as text: it may select every row, none or the wrong ones". + expect(err!.message, `${field} ${value}`).not.toContain('compared as text: it may select every row, none or the wrong ones'); } } expect(reads, 'every refusal precedes the driver').toHaveLength(0); diff --git a/packages/objectql/src/engine-temporal-year-range.test.ts b/packages/objectql/src/engine-temporal-year-range.test.ts index 0cfd909cc28..5b4f0b4bb4e 100644 --- a/packages/objectql/src/engine-temporal-year-range.test.ts +++ b/packages/objectql/src/engine-temporal-year-range.test.ts @@ -221,12 +221,12 @@ describe('[#20264] the temporal-comparand door — a year outside the kind\'s ye expect(reads, 'every refusal precedes the driver').toHaveLength(3); }); - it('the refusal names the year class, not "compares false for every row"', async () => { + it('the refusal names the year class, not the junk class\'s "every row, none or the wrong ones"', async () => { const err = await refusalOf(engine.find('ledger', { where: { opened_at: { $gt: Y10000 } } })); expect(err!.message).toContain("'opened_at'"); expect(err!.message).toContain('where.opened_at.$gt'); expect(err!.message).toContain('1000 to 9999'); - expect(err!.message).not.toContain('compare false for EVERY row'); + expect(err!.message).not.toContain('compared as text: it may select every row, none or the wrong ones'); // A `date` keeps its own years in its words. const day = await refusalOf(engine.find('ledger', { where: { placed_on: { $gt: Y10000 } } })); expect(day!.message).toContain('0001 to 9999'); diff --git a/packages/objectql/src/engine-top-level.ts b/packages/objectql/src/engine-top-level.ts index c98d4cadfb4..65b7d6da3c2 100644 --- a/packages/objectql/src/engine-top-level.ts +++ b/packages/objectql/src/engine-top-level.ts @@ -951,8 +951,11 @@ export function lowerWhereFilterArray( // asks "can that column's storage rule READ this value". // It must run BEFORE `resolveWhereTokens` (which is downstream of every // caller of this function) because the refusal has to precede the driver — - // hence the door steps around `{placeholder}` strings rather than judging - // them; the token resolver refuses the unknown ones a moment later, loudly. + // hence the door judges a `{placeholder}` by its kind rather than as the + // value it resolves to: a date macro is stepped around (judged by its year + // once resolved), a period key or a context token is judged as written, and + // an unknown or record-context token is left to the token resolver, which + // refuses it a moment later, loudly. assertTemporalComparandsInterpretable(object, operation, schema, where); // [#20351] The NUMBER-comparand declared-type door, fifth on the same seam // and fifth question about the same predicate: is this string a number the diff --git a/packages/objectql/src/temporal-comparand-door.ts b/packages/objectql/src/temporal-comparand-door.ts index 10efb471828..22fbb45f346 100644 --- a/packages/objectql/src/temporal-comparand-door.ts +++ b/packages/objectql/src/temporal-comparand-door.ts @@ -90,12 +90,18 @@ * it in passing"); measured, `$gte ""` binds as `''` and returns every * non-null row — 51 of 51, not the 38 the card's table records, which is a * transcription error its own prose corrects. - * - **`{placeholder}` strings are stepped around**, not judged. This gate runs - * BEFORE `resolveWhereTokens` (which is where it must run — the refusal has - * to precede the driver), so judging one would refuse `{30_days_ago}`, the - * platform's own correct spelling. Unknown tokens keep their existing loud - * refusal one layer down, and [#20844] a known one is judged once resolved, - * by its year alone (below). + * - **A `{placeholder}` is judged per kind** (`@objectstack/core`'s + * `PLACEHOLDER_AT_THE_TEMPORAL_RULE`, one row per `classifyFilterToken` + * kind). This gate runs BEFORE `resolveWhereTokens` (which is where it must + * run — the refusal has to precede the driver). A date macro is stepped + * around, because judging it as written would refuse `{30_days_ago}`, the + * platform's own correct spelling; [#20844] it is judged once resolved, by + * its year alone (below). [#34938] A period key (`{current_iso_week}`) and + * [#35394] a context token (`{current_user_id}`) are judged AS WRITTEN: each + * resolves to text no temporal rule reads (a week key, an id), so each takes + * the refusal its literal takes. An unknown or a record-context token is + * stepped around and left to the resolver, which refuses it by name + * (`FILTER_TOKEN_UNKNOWN` / `FILTER_TOKEN_UNRESOLVED`, 400). * - **Non-string comparands are not judged, save the year classes.** A number * is epoch milliseconds and a `Date` is an instant; the `datetime` and `time` * rules read both, [#20480] a `time` column only when the instant's UTC year @@ -140,7 +146,8 @@ * * These are not junk: the rule reads each one, as the wrong value, so each * answered rows. Their refusal says so in its own words ({@link misreadClassOf}) - * rather than in the junk class's "compare false for EVERY row". + * rather than in the junk class's "compared as text: it may select every row, + * none or the wrong ones". * * ## [#20480] An instant on a `time` column outside the four-digit years * @@ -188,8 +195,8 @@ * * ## [#20844] A relative-date placeholder, judged by its year once resolved * - * The door steps around a `{placeholder}`, so the year range never saw what - * one resolved to. Measured before this on InMemoryDriver and SqlDriver on + * The door steps around a date macro, so the year range never saw what one + * resolved to. Measured before this on InMemoryDriver and SqlDriver on * SQLite, through `engine.find` and `POST /data/:object/query`, a `datetime` * field and two rows, one in 2026 and one in 1500: * @@ -623,8 +630,8 @@ function yearClassOutside(kind: 'date' | 'datetime', value: unknown): YearClass /** * [#20549] A comparand the storage rule READS, but not as the value it names — * the two readings the write door refused first, and `@objectstack/core`'s one - * rule now refuses at both doors. Such a comparand does not compare false for - * every row, as junk does: it answers rows, the wrong ones. Each class says + * rule now refuses at both doors. Such a comparand is not junk, which no rule + * reads at all: it is read, as the wrong value, and answers the wrong rows. Each class says * why, and what the value would have done, per position. */ interface MisreadClass { @@ -712,10 +719,11 @@ export function assertTemporalComparandsInterpretable( const hit = findUninterpretableTemporalComparand(schema, where, path); if (!hit) return; // [#20240] [#20264] A comparand whose year falls outside the kind's years - // gets words that say so. It does not compare false for every row as junk - // does: its text orders as no day or instant does, so it answers the WRONG - // rows (or, on PostgreSQL, a database error) — or [#20280], for a `datetime` - // in 0001..0999, it names a year MySQL's `DATETIME` does not document. + // gets words that say so. It is not junk, which is compared as text and may + // select every row, none or the wrong ones: its text orders as no day or + // instant does, so it answers the WRONG rows (or, on PostgreSQL, a database + // error) — or [#20280], for a `datetime` in 0001..0999, it names a year + // MySQL's `DATETIME` does not document. // [#27173] Each arm: the verdict, the prescription, then the consequence. const yearClass = yearClassOf(hit); if (yearClass) { @@ -738,8 +746,8 @@ export function assertTemporalComparandsInterpretable( `${operation}('${object}'): filter on '${hit.field}' compares a declared ${hit.kind} ` + `field against ${preview(hit.value)} at ${hit.path}, which is not a ${hit.kind} value ` + `this platform can interpret. ${REMEDY[hit.kind]} The filter was NOT applied. As written ` - + 'it would reach the driver, compare false for EVERY row, and return 200 with an empty ' - + 'result — indistinguishable from "there is no data".', + + 'it would reach the driver and be compared as text: it may select every row, none or the ' + + 'wrong ones (or raise a database error), an answer indistinguishable from a real one.', ); } @@ -817,8 +825,9 @@ export function assertHavingTemporalComparandsInterpretable( throw invalidFilterError( `aggregate('${object}'): ${column} compares against ${preview(hit.value)} at ${hit.path}, ` + `which is not a ${hit.kind} value this platform can interpret. ${REMEDY[hit.kind]} The ` - + '`having` was NOT applied. Compared with each group as written, it would keep no group or ' - + 'every group, a 200 indistinguishable from a real answer.', + + '`having` was NOT applied. As written it would be compared with each group as text: it may ' + + 'keep every group, none or the wrong ones (or raise a database error), an answer ' + + 'indistinguishable from a real one.', ); } diff --git a/packages/services/service-analytics/src/strategies/filter-normalizer.ts b/packages/services/service-analytics/src/strategies/filter-normalizer.ts index 51b6146d686..3d92b215574 100644 --- a/packages/services/service-analytics/src/strategies/filter-normalizer.ts +++ b/packages/services/service-analytics/src/strategies/filter-normalizer.ts @@ -625,12 +625,19 @@ export type NormalizedFilterNode = * a condition on that field: on a member the native compile reads through a * relationship path it holds only for a row whose parent exists ("no parent * never matches, whatever the operator", `cross-object-where.ts`). The member - * gates need no second reading of it: the shared lowering wraps every `$nin` - * in the NULL escape (`{ $or: [{ f: { $null: true } }, { f: { $nin: [] } }] }`), - * so the escape's `notSet` leaf names the same member beside it (see - * {@link collectFilterLeaves}), and a `$not` never meets the constant bare - * ({@link notOf} receives the escape's `$or`). Every other constant names no - * member. + * gates need no second reading of it: the shared lowering + * (`lowerFilterCondition`, `@objectstack/spec/data`) always puts a leaf on the + * same member beside the `$nin` (see {@link collectFilterLeaves}). Outside a + * `$not` it wraps every `$nin` in the NULL escape + * (`{ $or: [{ f: { $null: true } }, { f: { $nin: [] } }] }`), whose `notSet` + * leaf names the member. Inside a `$not` it takes that escape when a row with + * no value satisfies every operator of the field's spec (for example `$nin` + * alone, or beside `$null: true` / `$eq: null`); for a mixed spec it takes a `$null: + * false` requirement instead, a `set` leaf on the member, as its own conjunct + * or the enclosing conjunct that already requires the field. So a `$not` + * never meets the constant bare either: {@link notOf} receives the escape's + * `$or`, or the conjunction holding the constant. Every other constant names + * no member. */ | { kind: 'const'; value: boolean; member?: string } | { kind: 'and'; children: NormalizedFilterNode[] } @@ -2501,8 +2508,12 @@ export function collectFilterLeaves( // A boolean constant names no member — it constrains rows, not columns — so // it contributes nothing to the cross-object envelope check. The empty // `$nin`'s TRUE names its member too, and is not read here: the shared - // lowering wraps every `$nin` in its NULL escape, whose `notSet` leaf names - // the same member, so every gate already reads that member for it. + // lowering always puts a leaf on the same member beside the `$nin`, so every + // gate already reads that member for it. Outside a `$not` that is the + // `notSet` leaf of the NULL escape every `$nin` is wrapped in; inside one it + // is that escape's leaf, or for a mixed spec the `set` leaf of a + // `$null: false` requirement (its own conjunct, or the enclosing one that + // already requires the field). See the `const` arm of `NormalizedFilterNode`. if (node.kind === 'const') return []; if (node.kind === 'not') return collectFilterLeaves(node.child); return node.children.flatMap(collectFilterLeaves); diff --git a/packages/spec/src/data/currency-summary-home-rollup.test.ts b/packages/spec/src/data/currency-summary-home-rollup.test.ts index e1edd7b03ce..3ef93218c8f 100644 --- a/packages/spec/src/data/currency-summary-home-rollup.test.ts +++ b/packages/spec/src/data/currency-summary-home-rollup.test.ts @@ -354,4 +354,18 @@ describe('case (d) is worded once', () => { )); } }); + + it('a `currency` child that is neither `dynamic` nor a well-formed `record` / `fixed` is named by what its `currencyConfig` lacks', () => { + // A stored row the object door never parsed: `fixed` with no code, or a mode outside the three. + const rollup = { object: 'crm_probe_project', field: 'home_expense_total', fn: 'sum', childObject: 'crm_probe_expense', childField: 'note_amount' }; + for (const [config, names] of [ + [{ currencyMode: 'fixed' }, '`fixed` mode with no `defaultCurrency` code'], + [{ currencyMode: 'euro' }, "`currencyMode` 'euro' is none of `dynamic`, `fixed` and `record`"], + ] as const) { + const child = { type: 'currency', label: 'Plain', currencyConfig: config }; + const message = recordCurrencyDynamicRollupNotHomeError(rollup, { ...(expense().fields as Record), note_amount: child }, child); + expect(message, names).toContain(`'crm_probe_expense.note_amount' is a 'currency' field `); + expect(message, names).toContain(names); + } + }); }); diff --git a/packages/spec/src/data/filter-number-comparand-declared-type.ts b/packages/spec/src/data/filter-number-comparand-declared-type.ts index f66faa4f395..a4bc84db2b5 100644 --- a/packages/spec/src/data/filter-number-comparand-declared-type.ts +++ b/packages/spec/src/data/filter-number-comparand-declared-type.ts @@ -178,10 +178,13 @@ * * ## A `{placeholder}` against a number field is refused, not stepped around * - * The temporal door steps around `{tokens}` because for a temporal field a - * token IS the platform's correct spelling. For a numeric field none is: every - * token in the filter vocabulary resolves to a user or organization id, a - * `YYYY-MM-DD` day or an ISO instant (`resolveFilterToken`, + * The temporal door steps around a date macro (`{30_days_ago}`) because for a + * temporal field that token IS the platform's correct spelling; it judges a + * period key and a context token as written, and leaves an unknown or + * record-context token to the resolver. For a numeric field no token is a + * correct spelling: every token in the filter vocabulary resolves to a user or + * organization id, an ISO week key (`2026-W47`), a `YYYY-MM-DD` day or an ISO + * instant (`resolveFilterToken`, * `@objectstack/core`), none of which is numeric — so a resolved token reaches * PostgreSQL as the same 500. The engine's field-aware doors run BEFORE the * token resolver (the temporal door records why), so this door meets the diff --git a/packages/spec/src/data/record-currency-path.ts b/packages/spec/src/data/record-currency-path.ts index 557f1887812..c0ea2ce7c9e 100644 --- a/packages/spec/src/data/record-currency-path.ts +++ b/packages/spec/src/data/record-currency-path.ts @@ -32,7 +32,7 @@ * `currencyMode: 'dynamic'` roll-up over a child field that is not such an * amount. * - * Messages only and two predicates: each door decides when a pair is judged. + * Messages only and three predicates: each door decides when a pair is judged. */ import { VALUE_DOMAIN_FIELD_TYPES } from './field.zod'; @@ -258,6 +258,16 @@ export function recordCurrencyDynamicRollupNotHomeError( : undefined; const amounts = tenantCurrencyAmountsOf(childFields); const kind = isRecord(childDef) && typeof childDef.type === 'string' ? `a '${childDef.type}' field` : 'not a field'; + // A `currency` child reaches this arm only with a mode that is neither + // `dynamic` nor a well-formed `record` / `fixed`, so the words name what its + // `currencyConfig` lacks rather than its type alone. + const mode = config?.currencyMode; + const defect = !isRecord(childDef) || childDef.type !== 'currency' + ? kind + : mode === 'fixed' + ? 'a \'currency\' field in `fixed` mode with no `defaultCurrency` code (the currency it is fixed to is missing)' + : `a 'currency' field whose \`currencyMode\` ${typeof mode === 'string' ? `'${mode}'` : String(mode)} is none of ` + + '`dynamic`, `fixed` and `record`'; const why = config?.currencyMode === 'record' ? `${named} is an amount in ${typeof config.currencyField === 'string' && config.currencyField.includes('.') ? 'its parent\'s' : 'each record\'s own'} ` + `currency (\`currencyMode: 'record'\`), not the home currency. ` @@ -269,7 +279,7 @@ export function recordCurrencyDynamicRollupNotHomeError( : config?.currencyMode === 'fixed' && typeof config.defaultCurrency === 'string' ? `${named} is fixed to ${config.defaultCurrency}. Declare \`currencyConfig: { currencyMode: 'fixed', defaultCurrency: ` + `'${config.defaultCurrency}' }\` on the summary instead.` - : `${named} is ${kind}, not a \`currency\` field in \`dynamic\` mode, so its rows are not known to be in the home currency. ` + : `${named} is ${defect}, not a \`currency\` field in \`dynamic\` mode, so its rows are not known to be in the home currency. ` + (amounts.length > 0 ? `The amounts of '${rollup.childObject}' in the home currency are ${amounts.map((h) => `'${h}'`).join(', ')}; ` + 'roll up one of them, ' diff --git a/packages/spec/src/migrations/entries/semantic/18.summary-dynamic-currency-rollup-home-amount-judged-as-served.ts b/packages/spec/src/migrations/entries/semantic/18.summary-dynamic-currency-rollup-home-amount-judged-as-served.ts index 35a975da05f..83af4428538 100644 --- a/packages/spec/src/migrations/entries/semantic/18.summary-dynamic-currency-rollup-home-amount-judged-as-served.ts +++ b/packages/spec/src/migrations/entries/semantic/18.summary-dynamic-currency-rollup-home-amount-judged-as-served.ts @@ -4,7 +4,9 @@ import type { SemanticMigration } from '../../types.js'; // The upgrade-guide entry of a `dynamic` summary roll-up (ADR-0144 D6 and D8 // rule 5) as the engine registry now judges it, beside `defineStack`: only -// over a stored home amount, against the objects as the server serves them. +// over a child amount in the home currency (a `currency` field in `dynamic` +// mode, a stored home amount included), against the objects as the server +// serves them. // The widening that admitted the home roll-up shipped in a `next` snapshot of // the spec before the engine door judged it, so a body that snapshot accepted // on a running server can be refused now. No conversion: which child field @@ -17,20 +19,22 @@ export const entry: SemanticMigration = { + 'publish of an object or an `object_extension` item through the `/meta` doors, the batch writers, and the end of ' + 'an install, upgrade or reload run on a running server, against the parent and the child as served (their bases ' + 'and every enabled extension), in both directions: a parent saving such a roll-up, and a child saved so that a ' - + 'registered parent\'s roll-up no longer reads a home amount. Also `defineStack`, where a home amount now counts ' - + 'only when its `homeAmount` is valid as declared. Not the cold boot', + + 'registered parent\'s roll-up no longer reads an amount in the home currency. Also `defineStack`, where a home ' + + 'amount now counts only when its `homeAmount` is valid as declared. Not the cold boot', replacement: - 'Roll up the child\'s stored home amount (a `readonly` `dynamic` currency field that the `homeAmount.field` of one ' - + 'record-mode amount on the child names; the refusal lists them), declare `currencyMode: \'fixed\'` with the code ' - + 'when every amount the roll-up reads is in that one currency, or delete `currencyConfig` on the summary. When an ' + 'Roll up an amount of the child in the home currency: a `currency` field in `dynamic` mode (an absent mode is ' + + '`dynamic`), a stored home amount included (the refusal lists them), declare `currencyMode: \'fixed\'` with the ' + + 'code when every amount the roll-up reads is in that one currency, or delete `currencyConfig` on the summary. When an ' + '`objectExtensions` entry declares the home amount, give it a `readonly` `dynamic` currency field of its own and ' + 'the record-mode amount that converts into it', reason: - 'A `dynamic` summary is drawn in the organization\'s home currency, which is right only for a roll-up of a stored ' - + 'home amount. `defineStack` admitted it only there, but the engine registry, which a single-object save on a ' - + 'running server meets, judged only `record` roll-ups, so a `dynamic` roll-up over a `fixed` EUR amount, a plain ' - + 'number or a formula was stored and its total shown with the home currency\'s symbol. It is now refused 422 ' - + '`INVALID_METADATA` there, in the words `defineStack` uses. A `homeAmount` makes a field a home amount only where ' + 'A `dynamic` summary is drawn in the organization\'s home currency, which is right only for a roll-up of an amount ' + + 'in that currency: a child `currency` field in `dynamic` mode, a stored home amount included. Both doors now ' + + 'admit it only there. Before this entry, `defineStack` judged it (then admitting a stored home amount alone), ' + + 'but the engine registry, which a single-object save on a running server meets, judged only `record` roll-ups, ' + + 'so a `dynamic` roll-up over a `fixed` EUR amount, a plain number or a formula was stored and its total shown ' + + 'with the home currency\'s symbol. Since this entry it is refused 422 `INVALID_METADATA` there, in the words ' + + '`defineStack` uses. A `homeAmount` makes a field a home amount only where ' + 'it is valid as declared (a record-mode `currency` amount naming another `readonly` `dynamic` currency field of ' + 'the same object, with no `expression`, claimed by that one amount), so an extension cannot make a plain number ' + 'a home amount by naming it. Roll-ups stored before this release keep loading at every boot, which is not asked. ' @@ -38,5 +42,6 @@ export const entry: SemanticMigration = { acceptanceCriteria: 'Save the parent with its `dynamic` roll-up of the child\'s home amount through PUT /api/v1/meta/object/PARENT on a ' + 'running server and confirm the answer is 200 and the record page shows the total with the home currency\'s ' - + 'symbol. Save one over another child field and confirm the answer is 422 `INVALID_METADATA` naming the field', + + 'symbol. Save one over a child field that is not a `currency` field in `dynamic` mode (a `fixed` EUR amount, a ' + + 'plain number or a formula) and confirm the answer is 422 `INVALID_METADATA` naming the field', }; diff --git a/ui/packages/fields/src/currency.ts b/ui/packages/fields/src/currency.ts index 0748515cc43..1b21b1ce00c 100644 --- a/ui/packages/fields/src/currency.ts +++ b/ui/packages/fields/src/currency.ts @@ -54,12 +54,14 @@ export function readFollowedParentObject(field: unknown): string | undefined { * `resolveFieldCurrency`, with the parent row as the record. * * `dynamic` (and a `currencyConfig` naming no `currencyMode`, which the spec - * parses as `dynamic`) is admitted by the spec only on a roll-up of a stored - * home amount, a child field some `homeAmount.field` names (objectstack#33659). - * That field is a `dynamic` currency field in the home currency (ADR-0144 D8 - * rule 5), so its total is too: `resolveFieldCurrency` answers the tenant - * default (`localization.currency`), the code a metric tile over the same home - * field resolves, and a plain number when none is set. A summary that declares + * parses as `dynamic`) is admitted by the spec only on a roll-up of an amount + * in the home currency: any child `currency` field in `dynamic` mode (an absent + * mode is `dynamic`), a stored home amount, one some `homeAmount.field` names, + * included (objectstack#33659, widened by objectstack#35045). Every row of + * such a field is in the home currency (ADR-0144 D4, D8 rule 5), so its total + * is too: `resolveFieldCurrency` answers the tenant default + * (`localization.currency`), the code a metric tile over the same child field + * resolves, and a plain number when none is set. A summary that declares * no `currencyConfig` stays a number. */ export function summaryDeclaresCurrency(field: unknown): boolean { diff --git a/ui/packages/fields/src/index.tsx b/ui/packages/fields/src/index.tsx index 223c77237fc..44b095559a9 100644 --- a/ui/packages/fields/src/index.tsx +++ b/ui/packages/fields/src/index.tsx @@ -2889,8 +2889,9 @@ export function FormulaCellRenderer({ value, field, dependentValues }: CellRende // A roll-up that declares its currency is money (ADR-0144 D6 as amended): // the currency cell draws it, with the parent row as its record, so a // `record` roll-up reads the parent's code as its children's amounts do, and - // a `dynamic` one (a roll-up of a stored home amount, objectstack#33659) - // reads the tenant default, as its home field's own cells do. + // a `dynamic` one (a roll-up of a child `currency` field in `dynamic` mode, + // a stored home amount included) reads the tenant default, as that child + // field's own cells do. const declaresMoney = (field as { type?: unknown } | undefined)?.type === 'summary' && summaryDeclaresCurrency(field); const valueType = declaresMoney && typeof value === 'number' ? 'currency' diff --git a/ui/packages/fields/src/widgets/SummaryField.tsx b/ui/packages/fields/src/widgets/SummaryField.tsx index 97463043f35..e2fe9e47406 100644 --- a/ui/packages/fields/src/widgets/SummaryField.tsx +++ b/ui/packages/fields/src/widgets/SummaryField.tsx @@ -61,8 +61,9 @@ export function SummaryField({ value, field, dependentValues, ...props }: FieldW // A roll-up that declares its currency is money (ADR-0144 D6 as amended), // drawn by the call the currency cell and `CurrencyField` make, so this face // and `FormulaCellRenderer`'s agree; `dependentValues` is the parent record. - // A `dynamic` roll-up (of a stored home amount, objectstack#33659) resolves - // to the tenant default, as the metric tile over its home field does. + // A `dynamic` roll-up (of a child `currency` field in `dynamic` mode, a + // stored home amount included) resolves to the tenant default, as the metric + // tile over that child field does. const isNumber = typeof value === 'number' && !isNaN(value); const text = isNumber && summaryDeclaresCurrency(field)