Skip to content

add searchableJson query type for automatic operation inference#283

Open
tobyhede wants to merge 2 commits intomainfrom
searchable-json
Open

add searchableJson query type for automatic operation inference#283
tobyhede wants to merge 2 commits intomainfrom
searchable-json

Conversation

@tobyhede
Copy link
Contributor

@tobyhede tobyhede commented Feb 5, 2026

Summary by CodeRabbit

  • New Features

    • Added a new searchableJson query type for JSON-based searchable encryption
    • Automatic inference of query operations from plaintext types (strings, objects, arrays)
    • Support for batch queries mixing plaintext types and nulls
  • Tests

    • Comprehensive test coverage for searchableJson behavior and inference logic
    • Tests for validation scenarios and mixed explicit/implicit query specifications

…inference

Add searchableJson as a new query type that auto-infers the correct
query operation (ste_vec_selector or ste_vec_term) from the plaintext
value type:
- String values → ste_vec_selector (JSONPath queries)
- Object/Array/Number/Boolean → ste_vec_term (containment queries)

This provides a friendlier API compared to explicitly specifying
steVecSelector or steVecTerm. Existing query types remain unchanged.
Add documentation explaining that searchableJson behaves identically to
omitting queryType on ste_vec columns - both auto-infer the query
operation. The explicit queryType is useful for code clarity.
@changeset-bot
Copy link

changeset-bot bot commented Feb 5, 2026

⚠️ No Changeset found

Latest commit: 25b0580

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

Adds a new searchableJson QueryType with mapping to ste_vec and implements inference of the underlying query operation from plaintext (strings → selector, objects/arrays → term), updates index-type resolution logic, and adds comprehensive tests covering plaintext varieties, batch behavior, and error cases.

Changes

Cohort / File(s) Summary
Type Definitions
packages/protect/src/types.ts
Adds searchableJson to QueryTypeName, queryTypes discriminator, and queryTypeToFfi mapping (searchableJsonste_vec).
Query Inference Logic
packages/protect/src/ffi/helpers/infer-index-type.ts
Special-case handling for queryType === 'searchableJson': when plaintext is provided infer queryOp via plaintext type (string → selector, object/array → term); if plaintext is null/undefined return only indexType.
Tests
packages/protect/__tests__/encrypt-query-searchable-json.test.ts, packages/protect/__tests__/infer-index-type.test.ts
Adds extensive tests validating searchableJson auto-inference, handling of null/number/boolean/scalars, nested objects/arrays, batch mixed types, ste_vec index requirement, returnType formats, and withLockContext exposure.

Sequence Diagram(s)

sequenceDiagram
  participant Client as ProtectClient
  participant Resolver as InferIndexType
  participant FFI as ste_vec FFI
  participant DB as Database

  Client->>Resolver: resolveIndexType(column, queryType='searchableJson', plaintext)
  alt plaintext is string
    Resolver-->>Client: indexType='ste_vec', queryOp='ste_vec_selector'
  else plaintext is object/array
    Resolver-->>Client: indexType='ste_vec', queryOp='ste_vec_term'
  else plaintext is null/undefined
    Resolver-->>Client: indexType='ste_vec' (no queryOp)
  end
  Client->>FFI: encryptQuery(payload with indexType, queryOp?)
  FFI->>DB: store/encrypt using ste_vec semantics
  DB-->>FFI: ack
  FFI-->>Client: encrypted result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • coderdan
  • calvinbrewer

Poem

🐰 I nibble through JSON, sniffing types with delight,
Strings hop to selectors, objects tumble to terms at night—
ste_vec hums a tune, encrypting each quest,
Rabbity tests cheer loudly: the inference is blessed! 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: adding a new 'searchableJson' query type that performs automatic operation inference based on plaintext types.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch searchable-json

Comment @coderabbitai help to get the list of available commands and usage tips.

@tobyhede
Copy link
Contributor Author

tobyhede commented Feb 5, 2026

@CodeRabbit full review

@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

✅ Actions performed

Full review triggered.

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.

1 participant