diff --git a/.changeset/35494-nested-relation-hop-docblock.md b/.changeset/35494-nested-relation-hop-docblock.md new file mode 100644 index 00000000000..1ac9519e540 --- /dev/null +++ b/.changeset/35494-nested-relation-hop-docblock.md @@ -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. diff --git a/packages/spec/src/data/filter.zod.ts b/packages/spec/src/data/filter.zod.ts index 0c554a479dd..53409e39a8d 100644 --- a/packages/spec/src/data/filter.zod.ts +++ b/packages/spec/src/data/filter.zod.ts @@ -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 @@ -2232,7 +2236,7 @@ export type FilterCondition = { [key: string]: | any // Implicit equality: key: value | z.infer // 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[]; @@ -2370,7 +2374,7 @@ export const FilterConditionSchema: z.ZodType * { 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) * } * } * } @@ -2461,7 +2465,7 @@ export type Filter = { $null?: boolean; $exists?: boolean; } - | (T[K] extends object ? Filter : never); // Nested relation — typed at any depth here; the engine serves one level, in `where` (see FilterCondition) + | (T[K] extends object ? Filter : never); // Nested relation — typed at any depth here; the engine serves up to three relationships, in `where` (see FilterCondition) } & { $and?: Filter[]; $or?: Filter[];