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
2 changes: 1 addition & 1 deletion .changeset/35394-context-token-temporal-door.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
'@objectstack/core': patch
---
Expand All @@ -22,6 +22,6 @@

- `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`.
20 changes: 20 additions & 0 deletions .changeset/t1-stale-prose.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 12 additions & 8 deletions content/docs/ui/dashboards.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/utils/import-coerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions packages/lint/src/validate-rls-predicate-enforceability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 9 additions & 4 deletions packages/objectql/src/engine-delete-and-aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions packages/objectql/src/engine-temporal-comparand-door.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/objectql/src/engine-temporal-year-range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 5 additions & 2 deletions packages/objectql/src/engine-top-level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,11 @@ export function lowerWhereFilterArray<T extends object | undefined>(
// 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
Expand Down
47 changes: 28 additions & 19 deletions packages/objectql/src/temporal-comparand-door.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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:
*
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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.',
);
}

Expand Down Expand Up @@ -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.',
);
}

Expand Down
Loading
Loading