Skip to content

feat(data): Data querying - #36

Merged
SteakFisher merged 3 commits into
mainfrom
feat/data
May 13, 2026
Merged

feat(data): Data querying#36
SteakFisher merged 3 commits into
mainfrom
feat/data

Conversation

@SteakFisher

@SteakFisher SteakFisher commented May 13, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added a data query service with validated query inputs, nested filtering, flexible sorting, and pagination; returns structured rows and total counts with clear error responses.
  • Chores

    • Expanded gRPC/protobuf code generation to include additional service definitions and updated the proto subproject reference.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 837f3181-ac7e-42c7-bb4f-c0b4cce4aa23

📥 Commits

Reviewing files that changed from the base of the PR and between 6e09fc7 and 282c460.

📒 Files selected for processing (2)
  • proto
  • src/routes/gRPC/data/query.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • proto
  • src/routes/gRPC/data/query.ts

📝 Walkthrough

Walkthrough

This PR adds a new gRPC data query service: updates the proto submodule and build script to generate bindings, introduces Zod request schemas, implements a parameterized query handler with nested filters/sorting/pagination, and wires the service into the gRPC server.

Changes

Data Query gRPC Service

Layer / File(s) Summary
Proto definitions and build setup
proto, package.json
Proto submodule bumped to new commit containing data service definitions; gen npm script extended to generate JavaScript bindings for data, query, and payment proto files.
Request validation schema
src/zod/data.ts
Zod schemas define operator/logical operator mappings, filter conditions with field/operator/value, recursive filter groups supporting AND/OR nesting with defaults, order-by field selection, and composite dataQuerySchema that normalizes and validates table selection, filters, sorting, pagination parameters.
Query handler implementation
src/routes/gRPC/data/query.ts
Exports queryData gRPC handler that validates requests against Zod schema, maintains a table/column registry with per-field type casting rules, builds parameterized WHERE predicates from nested filter groups, constructs drizzle order-by clauses, executes count and paginated select queries in parallel against Postgres, maps result rows to protobuf Row format, and routes Zod validation errors to the response callback.
Server integration
src/servers/rawGrpcServer.ts
Imports generated data gRPC bindings and queryData handler; creates interceptor-wrapped wrappedQueryData handler following the existing auth/logging pattern; registers DataQueryServiceService on the gRPC server with query method routed to wrapped handler.

Sequence Diagram(s)

sequenceDiagram
  participant gRPCClient
  participant queryData
  participant ZodValidator
  participant TableRegistry
  participant Database
  participant QueryResponse
  gRPCClient->>queryData: QueryRequest
  queryData->>ZodValidator: validate with dataQuerySchema
  alt validation fails
    ZodValidator-->>queryData: Zod error
    queryData->>QueryResponse: set validationFailed error
  else validation succeeds
    ZodValidator-->>queryData: DataQueryRequest
    queryData->>TableRegistry: lookup table and field defs
    queryData->>queryData: build WHERE predicates from filters
    queryData->>queryData: build order-by clauses
    par count query
      queryData->>Database: SELECT COUNT(*)
    and paginated select
      queryData->>Database: SELECT columns WITH LIMIT/OFFSET
    end
    Database-->>queryData: count and rows
    queryData->>QueryResponse: populate columns, rows, total
  end
  QueryResponse-->>gRPCClient: QueryResponse
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A query service hops into place,
With filters nested and tidy grace,
Protos compiled, schemas align,
Rows march out in ordered line,
The server hums — data on its way!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(data): Data querying' clearly summarizes the main change—adding a data querying feature with gRPC handlers, validation schemas, and service registration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/data
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/data

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/routes/gRPC/data/query.ts`:
- Around line 143-147: The code currently silently skips unknown filter/order
field names (when reading group.conditions and later in the order processing),
which can broaden results; update the loops that reference fieldDef =
tableDef.fields[condition.field] (inside the group.conditions iteration that
calls applyOp) and the analogous order-handling block (lines referencing
order.field and tableDef.fields) to validate that fieldDef exists and
immediately return/throw a validation error (e.g., BadRequest/ValidationError)
with a clear message when a field is not found instead of continuing; ensure the
error is emitted before any DB operation so input validation fails fast.
- Around line 99-107: The castValue function currently coerces non-"true"
strings to false and passes invalid integers as strings, which lets bad inputs
reach SQL predicate building; update castValue (and validate inputs before
calling it) so that for fieldDef.cast === "boolean" you accept only "true" or
"false" and otherwise throw/return a validation error, and for fieldDef.cast ===
"integer" parse with Number and ensure the value is a finite integer (rejecting
non-numeric or non-integer strings) so callers building SQL predicates receive
validated typed values; reference the function name castValue and the FieldDef
type so the validation logic is applied at the same call site that constructs DB
predicates.
- Around line 39-42: Update the TableDef interface and the local result variable
to use explicit types: replace table: any in interface TableDef with table:
typeof usersTable | typeof sessionsTable | typeof tagsTable | typeof
expressionsTable | typeof metadataTable (matching the keys in TABLE_REGISTRY),
and change const result: Record<string, any> to const result: Record<string,
AnyPgColumn>; ensure AnyPgColumn is imported/available where this file defines
the query function so the declared return type aligns with the actual variable
type.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c638e5b6-6774-478c-be6d-18a6d97a96f8

📥 Commits

Reviewing files that changed from the base of the PR and between bcdd6f2 and 6e09fc7.

⛔ Files ignored due to path filters (3)
  • src/gen/data/v1/data_grpc_pb.js is excluded by !**/gen/**
  • src/gen/data/v1/data_pb.d.ts is excluded by !**/gen/**
  • src/gen/data/v1/data_pb.js is excluded by !**/gen/**
📒 Files selected for processing (5)
  • package.json
  • proto
  • src/routes/gRPC/data/query.ts
  • src/servers/rawGrpcServer.ts
  • src/zod/data.ts

Comment thread src/routes/gRPC/data/query.ts Outdated
Comment thread src/routes/gRPC/data/query.ts Outdated
Comment thread src/routes/gRPC/data/query.ts
@SteakFisher
SteakFisher merged commit 31a4887 into main May 13, 2026
3 checks passed
This was referenced May 14, 2026
@SteakFisher
SteakFisher deleted the feat/data branch May 17, 2026 22:24
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