Skip to content

Commit e832ca6

Browse files
committed
docs(core): the 34990 note no longer says a class instance is never refused, and the null-rooted shape is declared
Changeset and docblock prose only, plus the foreign-realm predicate's Array.isArray read moved inside its try. No behaviour change. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibvVRcFWKrfWeG5jzPb
1 parent d074b4a commit e832ca6

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎.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 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.
14+
- FROM: `!=` served every other row (every row but one holding the caller's own object) and `not_contains` 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, 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.
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 as a relation, even one with keys of its own such as a moment, luxon or decimal object: it is a value. An ordering operator compares it through its `valueOf` when that returns a primitive, otherwise as its text; under an equality, membership or text operator it is refused, in a sentence of its own.
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Metadata-protocol: none
2525
- 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.
2727
- 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.
28+
- Also moved: an object whose prototype is a `null`-prototype object, such as `Object.create(Object.create(null))`. FROM: `convertFiltersToAST` read it as an operator map (with no own key it was refused as an empty operator map; with `$` keys it lowered), and in comparand position the value data source compared it by reference under `$eq` / `$in`, and under an ordering operator threw `TypeError: Cannot convert object to primitive value` and `find` rejected, unless its prototype defines a `valueOf`, which it then compared through. TO: both faces refuse it as `an object of an unrecognised type`: the converter as the field's whole condition, and the value data source in comparand position under every operator.
2829

2930
**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.
3031

‎ui/packages/core/src/adapters/ValueDataSource.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,14 @@ function foreignRealmComparandRefusalReason(field: string): string {
624624
}
625625

626626
/**
627-
* Is `value` an object whose prototype chain ends one step up without this
628-
* realm's `Object.prototype`, and that is not a foreign plain object:
629-
* `Object.create(Object.create(null))`? It has no `toString` or `valueOf`, so
630-
* an ordering would throw on it, and it is refused under every operator, in a
631-
* sentence that names it as the converter does.
627+
* Is `value` an object whose prototype is a `null`-prototype object, such as
628+
* `Object.create(Object.create(null))`? Its chain never reaches
629+
* `Object.prototype`, so it inherits no `toString` or `valueOf` from it (an
630+
* ordering threw on it, unless its prototype defines one), and it is refused
631+
* under every operator, in a sentence that names it as the converter does.
632+
*
633+
* The test alone also matches a plain object of ANOTHER realm: it relies on
634+
* {@link objectValueRefusal} running {@link isForeignRealmPlainObject} first.
632635
*/
633636
function isNullRootedObject(value: unknown): boolean {
634637
if (!value || typeof value !== 'object' || Array.isArray(value) || isPlainObject(value)) return false;
@@ -734,8 +737,8 @@ function objectValueRefusal(field: string, value: unknown, byValue: boolean): st
734737
*
735738
* And, only under an operator that compares by equality, membership or text
736739
* (`byValue`), a class instance ({@link classInstanceComparandRefusalReason}).
737-
* Under an ordering it is data compared through its `valueOf` when that returns
738-
* a primitive, and otherwise as its text, so it is not refused there. A `Date` and a `{ $field }` reference are still compared.
740+
* Under an ordering this builder does not refuse it. It refuses neither a
741+
* `Date` nor a `{ $field }` reference.
739742
*/
740743
function objectComparandRefusal(
741744
field: string,

‎ui/packages/core/src/utils/foreign-realm-object.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
* must never itself throw (a revoked `Proxy` throws on `getPrototypeOf`).
3232
*/
3333
export function isForeignRealmPlainObject(value: unknown): boolean {
34-
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
34+
if (!value || typeof value !== 'object') return false;
3535
try {
36+
if (Array.isArray(value)) return false;
3637
const proto = Object.getPrototypeOf(value) as { constructor?: { name?: unknown } } | null;
3738
if (proto === null || proto === Object.prototype) return false;
3839
if (Object.getPrototypeOf(proto) !== null) return false;

0 commit comments

Comments
 (0)