Skip to content

Commit 7c1dd7f

Browse files
committed
fix(core): a foreign-realm filter object gets its own refusal, one structural realm test, and the changeset FROM lines are completed
The converter refuses a plain object of another realm as a field's whole condition in a sentence of its own, naming the copy that rebuilds it in this realm, before the exotic-comparand refusal. Both faces decide "foreign realm" by one structural test, so Object.create(plainObject) and Object.create(Object.create(null)) are no longer named as foreign. The value source reads a $now anchor by the spec's test, gives the anchor sentence its remedy, and states that an ordering compares a class instance through valueOf only when that returns a primitive. Changeset prose completed per the L2 record. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibvVRcFWKrfWeG5jzPb
1 parent b559fc5 commit 7c1dd7f

9 files changed

Lines changed: 250 additions & 41 deletions

‎.changeset/34990-nested-relation-filter-node.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Metadata-protocol: none
1111

1212
**BREAKING** for a host that filters a `ValueDataSource` (the in-memory `provider: 'value'` source) with a comparison whose comparand is a plain object (prototype `Object.prototype` or `null`) with no `$` key, such as `['account', '!=', { owner: 'u1' }]`, under `!=`, `not_contains` or an ordering operator (`>`, `>=`, `<`, `<=`).
1313

14-
- FROM: `!=` and `not_contains` served every row, and an ordering operator compared each value with the text `[object Object]` and served the string values that happened to sort past it. That holds for an object whose prototype is `Object.prototype`. A `null`-prototype object has no `toString` or `valueOf`, so under `not_contains` and the ordering operators the comparison threw `TypeError: Cannot convert object to primitive value` and `find` rejected.
14+
- FROM: `!=` and `not_contains` served every row, and an ordering operator compared each value with the text `[object Object]` and served the string values that happened to sort past it. That holds for an object whose prototype is `Object.prototype`. A `null`-prototype object has no `toString` or `valueOf`, so an ordering operator threw `TypeError: Cannot convert object to primitive value` and `find` rejected; `not_contains` threw as soon as it reached a row holding a string, and served every row when none did.
1515
- TO: the condition is refused by name. It excludes every row and logs the sentence the object form `{ account: { owner: 'u1' } }` already logs. `=` compared by reference, so it matched no row unless a row held the caller's own object (stored through `create` or `update`, which copy shallowly), and that row matched; it matches none now and gains the log line.
1616
- The spec's comparand door already refuses an object comparand under these operators, so the rows served before were a wrong answer. Spell a relation condition only against a server-backed source, whose server joins it; a value source holds flat rows, so filter there on the row's own fields.
1717

1818
`convertFiltersToAST` now lowers the nested-relation form the spec declares on `FilterCondition` (`{ account: { owner: 'u1' } }`, a plain object with no `$` key beneath a field) to one equality node, `['account', '=', { owner: 'u1' }]`, which the spec's `parseFilterAST` reads back as the same nested condition. It used to refuse that shape as an unknown operator. The condition travels as written, deeper relations included; whether the field is a relationship is judged by the server, which answers `INVALID_FILTER` / 400 for such a condition under a field that stores a scalar or a structured-JSON value, and, under a relationship, for a condition key the related object does not declare, a dotted key, or a relation nested past the hop limit. A map that mixes `$` operators with plain keys is still refused.
1919

20-
`ValueDataSource` (the in-memory `provider: 'value'` source) does not descend into relations, and it now says so for the lowered node too: a comparison whose comparand is a plain object with no `$` key, such as `['account', '=', { owner: 'u1' }]`, excludes every row and logs the same sentence the object form `{ account: { owner: 'u1' } }` already logged, for `=`, `!=` and every other operator that reads the comparand. Before this, `=` compared the object by reference and matched no row without a word, and `!=` matched every row. A class instance is not refused, even one with keys of its own such as a moment, luxon or decimal object: it is a value, and an ordering operator still compares it through its `valueOf`.
20+
`ValueDataSource` (the in-memory `provider: 'value'` source) does not descend into relations, and it now says so for the lowered node too: a comparison whose comparand is a plain object with no `$` key, such as `['account', '=', { owner: 'u1' }]`, excludes every row and logs the same sentence the object form `{ account: { owner: 'u1' } }` already logged, for `=`, `!=` and every other operator that reads the comparand. Before this, `=` compared the object by reference and matched no row without a word, unless a row held the caller's own object, and `!=` matched every other row. A class instance is not refused, even one with keys of its own such as a moment, luxon or decimal object: it is a value, and an ordering operator still compares it through its `valueOf` when that returns a primitive; otherwise as its text.
2121

2222
`resolveDatasetDrillFilter` uses it: a dataset dimension whose field is a relationship path (`account.owner`, up to three hops) drills as `{ account: { owner: VALUE } }`, nested one level per hop, instead of reading up to 200 related ids per hop and filtering on `$in` them. No related record is read, nothing is capped, and the `too-many` answer is no longer produced; `DATASET_DRILL_RELATED_ID_CAP` and the `too-many` member of `DatasetDrillResolution` stay exported, marked deprecated. The schema reads that check each hop is a single-valued relationship, the hop limit and the empty-bucket refusal are unchanged.
2323

‎.changeset/35735-filter-flag-and-comparand-edges.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fix(core)!: a non-boolean `$null` / `$exists` flag is refused in the filter conv
77
Clause-②: no (narrowing)
88
Metadata-protocol: none
99

10-
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. What moves is what convertFiltersToAST lowers and what ValueDataSource.find answers for filters the spec already refuses (a non-boolean $null / $exists flag, a plain object of another realm, a class instance under an equality, membership or text operator) or that this in-memory face cannot evaluate (a { $now, addDays } anchor): no stored row, registry key or authored value changes, so there is nothing for a migration to rewrite and no tombstone. -->
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. What moves is what convertFiltersToAST lowers and what ValueDataSource.find answers for filters the spec already refuses (a non-boolean $null / $exists flag, a plain object of another realm, a plain object with a $ key that is not a { $field } reference such as { $foo: 1 }, a class instance under an equality, membership or text operator) or that this in-memory face cannot evaluate (a { $now, addDays } anchor): no stored row, registry key or authored value changes, so there is nothing for a migration to rewrite and no tombstone. -->
1111

1212
**BREAKING** for `convertFiltersToAST` and `ValueDataSource` (the in-memory `provider: 'value'` data source), for four filter shapes.
1313

@@ -16,16 +16,16 @@ Metadata-protocol: none
1616
- TO: both refuse it, as they already refused a non-boolean `$empty` flag. The converter throws `FilterOperatorError` (`INVALID_FILTER` / 400) with `The '$null' filter operator on field 'owner' takes a boolean flag (true or false); received "no"`, and the value data source excludes every row and logs `filter operator '$null' on field 'owner' takes a boolean flag (true or false); received "no"`. `true` and `false` lower and match exactly as before. The spec's `FilterConditionSchema` and every query face already refused these flags.
1717
- The AST null-ness operators (`is_null`, `is_not_null` and their spellings) carry no flag and are not moved: direction comes from the operator name and the value slot is not read, as the spec's `parseFilterAST` reads it.
1818
2. **A plain object of another realm** (an iframe, a `vm` context), whose prototype is that realm's `Object.prototype`.
19-
- FROM: `convertFiltersToAST` read it as an operator map, so `{ age: foreignObject }` with `$gte: 18` lowered to `['age', '>=', 18]` and one with no `$` key lowered to the nested-relation node `['owner', '=', foreignObject]`, which the value data source compared by reference (`=` no row, `!=` every row).
20-
- TO: it is a comparand, as the spec's filter walk and the engine's `isNoOperatorObject` read it: the converter refuses it as the field's whole condition (`The filter on field 'age' carries a plain object from another realm in comparand position…`), and the value data source refuses it in comparand position under every operator (`filter comparand on field 'owner' is a plain object from another realm, which is neither a comparison value nor filter structure here`). The server refused it already.
19+
- FROM: `convertFiltersToAST` read it as an operator map, so `{ age: foreignObject }` with `$gte: 18` lowered to `['age', '>=', 18]`, and the value data source answered it with the right rows, the ones with `age >= 18`: that is the answer this change takes away. One with no `$` key lowered to the nested-relation node `['owner', '=', foreignObject]`. In comparand position the value data source compared it as a value: by reference under `$eq` / `=` and as an `$in` member, so no row matched unless a row held the caller's own object (stored through `create` or `update`, which copy shallowly), and that row did; `$ne` / `!=` and `$nin` served every other row; and under an ordering operator it compared as the text `[object Object]`, serving the string values that sort past that text.
20+
- TO: it is a comparand, as the spec's filter walk and the engine's `isNoOperatorObject` read it: the converter refuses it as the field's whole condition in a sentence of its own (`The filter on field 'age' is a plain object from another realm (an iframe, a vm context). Only a plain object of this realm (prototype Object.prototype or null) is read as an operator map or a nested condition here…`), and the value data source refuses it in comparand position under every operator (`filter comparand on field 'owner' is a plain object from another realm, which is neither a comparison value nor filter structure here`). The server refused it already when the object reached it in process; sent as JSON, it arrives as a plain object of the server's realm.
2121
3. **A plain object with a `$` key that is not a `{ $field }` reference**, in comparand position on the value data source, the spec's `{ $now, addDays }` date anchor among them, such as `{ due: { $lt: { $now: true, addDays: 7 } } }`.
22-
- FROM: compared as a value: by reference, or as the text `[object Object]` (so `$lt` answered the rows sorting before that text, and `$ne` / `$nin` every row).
23-
- TO: refused under every operator that reads a comparand, whole or as a list member, in both dialects. The anchor gets `filter comparand on field 'due' is a { $now, addDays } date anchor, which the in-memory matcher does not resolve…`: the platform resolves it in the compared column's temporal form, and this source has no field types to read a form from, the reason it already refuses a `{ $field, addDays }` offset. Any other one gets `filter comparand on field 'owner' is an object carrying the key '$foo', which is neither a comparison value nor a { $field } reference`, the comparand the spec's door refuses. `convertFiltersToAST` still lowers the anchor verbatim for a server-backed source, which resolves it.
22+
- FROM: compared as a value: by reference under `$eq` and as an `$in` member, so no row matched unless a row held the caller's own object (stored through `create` or `update`), and that row did; `$ne` and `$nin` served every other row, and `$notContains` every row; under an ordering operator it compared as the text `[object Object]`, so `$lt` answered the rows sorting before that text. A `null`-prototype one has no text: under an ordering operator, `$between`, and a text operator on a row holding a string, the comparison threw `TypeError: Cannot convert object to primitive value` and `find` rejected.
23+
- TO: refused under every operator that reads a comparand, whole or as a list member, in both dialects. The anchor (by the spec's test: `$now` is `true` or a string) gets `filter comparand on field 'due' is a { $now, addDays } date anchor, which the in-memory matcher does not resolve…`, ending in the remedy `compare with a concrete Date or ISO string here`: the platform resolves it in the compared column's temporal form, and this source has no field types to read a form from, the reason it already refuses a `{ $field, addDays }` offset. Any other one gets `filter comparand on field 'owner' is an object carrying the key '$foo', which is neither a comparison value nor a { $field } reference`, the comparand the spec's door refuses. `convertFiltersToAST` still lowers the anchor verbatim for a server-backed source, which resolves it.
2424
4. **A class instance** (a moment or luxon date, a decimal object, a `RegExp`, a `Map`) as the comparand of an equality, membership or text operator on the value data source: `$eq`, `$ne`, an `$in` / `$nin` member, `$contains`, `$notContains`, `$startsWith`, `$endsWith`, and their AST spellings.
25-
- FROM: compared by reference or as its text: `$eq` and `$in` answered no row, `$ne`, `$nin` and `$notContains` every row.
25+
- FROM: compared by reference or as its text. `$eq` / `=` and `$in` answered no row unless a row held the caller's own instance (stored through `create` or `update`), and that row matched; `$ne` and `$nin` served every other row. `$contains`, `$startsWith` and `$endsWith` matched on the instance's `String()` text and served rows (a `new String('ab')`, a class with a `toString`), and `$notContains` served their complement.
2626
- TO: refused, in both dialects, with `filter comparand on field 'age' is a Amount instance, which the in-memory matcher compares only by order…`. The spec's comparand door refuses it at these operators.
27-
- Not moved: under `$gt` / `$gte` / `$lt` / `$lte` / `$between` it is still compared through its `valueOf`, and `$icontains` keeps its own text-comparand refusal.
27+
- Not moved: under `$gt` / `$gte` / `$lt` / `$lte` / `$between` it is still compared through its `valueOf` when that returns a primitive; otherwise as its text. `$icontains` keeps its own text-comparand refusal.
2828

2929
**Not moved.** A scalar, a `Date` and a `{ $field }` reference are compared as before; `$empty` keeps its boolean-flag refusal, with the converter's sentence now built by the same helper as `$null` / `$exists`; a `null`-prototype object of this realm is still an operator map.
3030

31-
The fix for a caller: write the flag as the boolean itself (`{ owner: { $null: true } }`, `{ owner: { $exists: false } }`); compare with a scalar, a `Date` or a `{ $field }` reference; filter a relative date on a server-backed source, or compare a value source with a concrete `Date` or ISO string; and convert a class-instance comparand to its primitive (`moment.toDate()`, `decimal.toNumber()`) before filtering.
31+
The fix for a caller: write the flag as the boolean itself (`{ owner: { $null: true } }`, `{ owner: { $exists: false } }`); compare with a scalar, a `Date` or a `{ $field }` reference; rebuild a filter object from another realm in this one (`{ ...condition }` per operator map, or `structuredClone(filter)`); filter a relative date on a server-backed source, or compare a value source with a concrete `Date` or ISO string; and convert a class-instance comparand to its primitive (`moment.toDate()`, `decimal.toNumber()`) before filtering.

0 commit comments

Comments
 (0)