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
10 changes: 10 additions & 0 deletions .changeset/35494-nested-relation-hop-docblock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/spec': patch
---

docs(spec): the `FilterCondition` nested-relation docblock states the engine's three-relationship limit

Clause-②: no — comment-only edits in packages/spec; no schema, export or accept set moves
Metadata-protocol: none — no metadata key is touched

`@objectstack/spec`: comments only, in `src/data/filter.zod.ts`, which the package ships as source. The nested-relation form (`{ relation: { field: value } }`, form 4 on `FilterCondition`) and its three one-line mentions said the engine serves it one level deep; they now say up to three relationships deep (ADR-0071's 3-hop limit, `RELATION_CONDITION_MAX_HOPS` in objectql), with a condition past the third relationship refused as `INVALID_FILTER` / 400, and name the platform-provisioned `id`, `created_at` and `updated_at` beside the related object's declared fields as admitted keys.
18 changes: 11 additions & 7 deletions packages/spec/src/data/filter.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2219,10 +2219,14 @@ function checkFilterConditionComparands(
* field permissions apply, so a condition on a field the caller cannot read
* is refused, never answered empty — and matches the relation field against
* the ids it returns (`$in` on a single-valued relation; any member, an
* `$or` of `$contains` per id, on a multi-valued one). One level: every key
* must be a field the related object declares, and a relation condition
* beneath it, or a dotted key, is refused. A condition matching more related
* records than the engine's cap is refused rather than truncated; filter the
* `$or` of `$contains` per id, on a multi-valued one). Up to three
* relationships deep (ADR-0071's 3-hop limit, `RELATION_CONDITION_MAX_HOPS`
* in `packages/objectql/src/relation-filter-lowering.ts`): every key must be
* a field the related object declares (or `id`, `created_at`, `updated_at`),
* a relation key may hold a condition of its own, and a condition past the
* third relationship, or a dotted key, is refused (`INVALID_FILTER` / 400).
* A condition matching more related records than the engine's cap is
* refused rather than truncated; filter the
* related object yourself then, and match its ids the same way. An
* aggregation's own `filter` and `having` do not serve the form. The same
* object beneath a JSON-valued field (a whole-value match) and beneath a
Expand All @@ -2232,7 +2236,7 @@ export type FilterCondition = {
[key: string]:
| any // Implicit equality: key: value
| z.infer<typeof FieldOperatorsSchema> // Explicit operators: key: { $op: value }
| FilterCondition; // Nested relation: key: { nested: ... } — served by the engine in `where`, one level (form 4 above)
| FilterCondition; // Nested relation: key: { nested: ... } — served by the engine in `where`, up to three relationships deep (form 4 above)
} & {
/** Logical AND - combines all conditions that must be true */
$and?: FilterCondition[];
Expand Down Expand Up @@ -2370,7 +2374,7 @@ export const FilterConditionSchema: z.ZodType<FilterCondition, FilterCondition>
* { email: { $contains: "@company.com" } }
* ],
* account: { // Nested relation (form 4): a field
* industry: "tech" // of the related record, one level
* industry: "tech" // of the related record (up to 3 hops)
* }
* }
* }
Expand Down Expand Up @@ -2461,7 +2465,7 @@ export type Filter<T = any> = {
$null?: boolean;
$exists?: boolean;
}
| (T[K] extends object ? Filter<T[K]> : never); // Nested relation — typed at any depth here; the engine serves one level, in `where` (see FilterCondition)
| (T[K] extends object ? Filter<T[K]> : never); // Nested relation — typed at any depth here; the engine serves up to three relationships, in `where` (see FilterCondition)
} & {
$and?: Filter<T>[];
$or?: Filter<T>[];
Expand Down
Loading