Skip to content

feat(prisma): add string concatenation and hierarchy operators#157

Merged
alexolivier merged 11 commits intomainfrom
primsa-add-hierachy
Mar 26, 2026
Merged

feat(prisma): add string concatenation and hierarchy operators#157
alexolivier merged 11 commits intomainfrom
primsa-add-hierachy

Conversation

@alexolivier
Copy link
Copy Markdown
Contributor

Summary

  • Add add operator support for string/numeric concatenation with algebraic solving (e.g. P.attr.context == "projects:" + R.attr.id{ id: { equals: "123" } })
  • Add hierarchy operator support: overlaps, ancestorOf, descendentOf for segment-wise prefix comparisons
  • Support all hierarchy construction forms: hierarchy(string), hierarchy(string, delimiter), hierarchy([segments])

Closes #155, closes #156

Test plan

  • 119 tests passing (v6 and v7)
  • Unit tests for add operator: constant folding, prefix/suffix solving, numeric, relation mapping, impossible filters
  • Unit tests for hierarchy operators: both operand orderings, custom delimiters, edge cases
  • Cerbos integration tests for each operator against live PDP

…ators

Add support for the `add` operator (string/numeric concatenation) with
algebraic solving, and hierarchy functions (`overlaps`, `ancestorOf`,
`descendentOf`) for segment-wise prefix comparisons.

Closes #155, closes #156

Signed-off-by: Alex Olivier <alex@alexolivier.me>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4fb9bb4ca9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread prisma/src/index.ts Outdated
Comment thread prisma/src/index.ts Outdated
…segment-based hierarchy prefixes

- buildImpossibleFilter now wraps contradiction in buildNestedRelationFilter
  when the field reference has relations, preventing Prisma validation errors
- Hierarchy prefix construction uses segments re-joined with the target
  delimiter instead of raw strings, fixing false negatives with mismatched
  delimiters
- Constant/constant ancestor check compares segment arrays directly

Signed-off-by: Alex Olivier <alex@alexolivier.me>
@alexolivier
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3973fbb5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread prisma/src/index.ts Outdated
Comment thread prisma/src/index.ts
Comment thread prisma/src/index.ts Outdated
…cestor/descendant

- buildImpossibleFilter delegates each condition to buildFieldFilter so
  relation field aliases are handled correctly per-condition
- handleOverlapsOperator supports field-type hierarchies by combining
  prefix/equality/startsWith checks
- normalizeHierarchy converts all-constant segmented hierarchies to
  constant type for ancestor/descendant and overlaps operators

Signed-off-by: Alex Olivier <alex@alexolivier.me>
- Reuse getStrictPrefixes in handleFieldOverlaps instead of manual loop
- Fix unsafe type cast in handleFieldOverlaps with proper narrowing
- Move normalizeHierarchy into extractHierarchyOperands
- Use CERBOS_TO_PRISMA_OPERATOR map instead of manual ternary
- Remove unreachable buildImpossibleFilterFromHierarchies
- Short-circuit tryFoldValueExpression on non-value left operand
- Deduplicate descendentOf operator name string

Signed-off-by: Alex Olivier <alex@alexolivier.me>
@alexolivier
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b71fa9457

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread prisma/src/index.ts Outdated
Comment thread prisma/src/index.ts Outdated
…field delimiter for prefixes

- buildImpossibleFilter now builds the AND contradiction as a single unit
  wrapped in one relation traversal, ensuring to-many relations can't
  satisfy each condition with different rows
- Use ancestor field's delimiter when building prefixes from constant
  descendant segments, fixing mismatch when segmented hierarchies are
  normalized with default delimiter

Signed-off-by: Alex Olivier <alex@alexolivier.me>
buildImpossibleFilter now uses the deepest relation's field alias
when constructing the contradiction, matching the remapping behavior
in buildNestedRelationFilter.

Signed-off-by: Alex Olivier <alex@alexolivier.me>
@alexolivier
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f0d0c0549

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread prisma/src/index.ts Outdated
Replace null-based contradiction (equals: null / not: null) with
{ in: [] } which works for all field types including non-nullable
required fields. Also simplifies buildImpossibleFilter to a single
buildFieldFilter call.

Signed-off-by: Alex Olivier <alex@alexolivier.me>
Signed-off-by: Alex Olivier <alex@alexolivier.me>
Signed-off-by: Alex Olivier <alex@alexolivier.me>
@alexolivier alexolivier merged commit f8cb242 into main Mar 26, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support add operator Support hierarchy functions

1 participant