Skip to content

refactor(convex): extract all inline validators to validators.ts files#48

Merged
larryro merged 10 commits into
mainfrom
claude/extract-convex-validators-SIMbv
Dec 30, 2025
Merged

refactor(convex): extract all inline validators to validators.ts files#48
larryro merged 10 commits into
mainfrom
claude/extract-convex-validators-SIMbv

Conversation

@larryro

@larryro larryro commented Dec 30, 2025

Copy link
Copy Markdown
Collaborator

Summary

  • Extract all complex inline validators from Convex function definitions into dedicated validators.ts files
  • Create new validator files for domains that were missing them
  • Update source files to import and use the extracted validators

Changes

New Files Created

File Validators Added
model/onedrive/validators.ts 15 validators (DriveItem, sync config, response validators)
model/threads/validators.ts 7 validators (chat type, message role, thread status)
model/members/validators.ts 5 validators (sort order, member list, context)
model/vendors/validators.ts 8 validators (source, address, input, list response)

Files Extended

File Validators Added
model/documents/validators.ts 30+ validators (Excel, PPTX, DOCX, PDF, image options)
model/email_providers/validators.ts 10+ validators (auth, connection test, OAuth2)

Source Files Updated

  • documents.ts - imports and uses extracted validators
  • onedrive.ts - imports and uses extracted validators
  • threads.ts - imports and uses extracted validators
  • member.ts - imports and uses extracted validators
  • vendors.ts - imports and uses extracted validators

Scope

  • Extracted: v.object(), v.union(v.literal(...)), v.array() validators
  • Kept inline: Simple primitives like v.string(), v.number(), v.optional(v.string()), v.id('table')

Test Plan

  • Verify TypeScript compilation passes
  • Verify Convex codegen succeeds
  • Test affected queries/mutations still work correctly

Resolves #42

Summary by CodeRabbit

  • Refactor
    • Centralized and standardized validation schemas across document processing, user management, email providers, file sync, messaging, and vendor features for improved data integrity and consistency.
    • Updated API method signatures to use centralized validators, enhancing type safety and error handling throughout the platform.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 30, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR systematically extracts ~100+ inline Convex validators from service function files into dedicated validators.ts modules. New validators.ts files are created for members, threads, vendors, and onedrive models, while existing documents and email_providers validators are extended. Service files (documents.ts, member.ts, threads.ts, vendors.ts, onedrive.ts) are updated to import and use these centralized validators in function argument and return type definitions, replacing inline validator definitions with references to the extracted validator constants.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 12

📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 4ac64e3 and bda7687.

📒 Files selected for processing (15)
  • services/platform/convex/documents.ts
  • services/platform/convex/member.ts
  • services/platform/convex/model/documents/validators.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/threads/index.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/onedrive.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/vendors.ts
🧰 Additional context used
🧠 Learnings (34)
📓 Common learnings
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Use the documented Convex validators for all supported types (e.g., v.id, v.int64, v.number, v.boolean, v.string, v.bytes, v.array, v.object, v.record)
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always include argument and return validators for all Convex functions (query, internalQuery, mutation, internalMutation, action, internalAction)
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/conversation_action.ts:47-98
Timestamp: 2025-12-15T14:44:09.823Z
Learning: In Convex action files (services/platform/convex/workflow/actions/**/), maintaining a separate TypeScript type alongside the parametersValidator is an acceptable pattern when documented. The TypeScript type provides IDE support and compile-time checking, while the validator provides runtime validation. This intentional separation should be documented with a comment explaining the design choice.
Learnt from: larryro
Repo: tale-project/tale PR: 37
File: services/platform/convex/model/conversations/validators.ts:106-139
Timestamp: 2025-12-30T06:20:39.422Z
Learning: In services/platform/convex/model/conversations/validators.ts, conversationItemValidator and conversationWithMessagesValidator are intentionally kept as separate validators despite having identical structures. This separation serves different semantic purposes: conversationItemValidator is for list responses while conversationWithMessagesValidator is for single conversation detail views. The duplication allows future divergence when list views might need different fields than detail views for performance or feature reasons.
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use `v.id(tableName)` validator for document IDs, and use strict TypeScript types with `Id<'tableName'>` instead of generic string types for function arguments and returns
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/workspace_rules.mdc:0-0
Timestamp: 2025-11-30T12:29:39.745Z
Learning: Applies to convex/*.ts : Split existing Convex modules that export multiple functions into separate files with one function per file, except for explicitly designated thin wrapper modules
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Always include argument and return validators for all Convex functions; if no return, set returns: v.null()
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.ts : Ensure TypeScript Record key/value types match validators (e.g., Record<Id<'users'>, string>)
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/workspace_rules.mdc:0-0
Timestamp: 2025-11-30T12:29:39.745Z
Learning: Applies to services/**/convex/*.ts : Thin wrapper API modules in services may export multiple Convex functions as thin wrappers that delegate to model helpers, must use snake_case file names and camelCase export names, and must not contain business logic
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always use `v.null()` validator when a function returns a null value, and include `returns: v.null()` even if the function doesn't explicitly return anything
📚 Learning: 2025-11-30T12:29:39.745Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/workspace_rules.mdc:0-0
Timestamp: 2025-11-30T12:29:39.745Z
Learning: Applies to services/**/convex/*.ts : Thin wrapper API modules in services may export multiple Convex functions as thin wrappers that delegate to model helpers, must use snake_case file names and camelCase export names, and must not contain business logic

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/model/threads/index.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/!(model)/*.ts : Exception: Thin wrapper API modules (e.g., `services/platform/convex/documents.ts`) may export multiple Convex functions if they only validate args/returns and delegate to the model layer; must use snake_case for file names and camelCase for function names

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/member.ts
  • services/platform/convex/model/threads/index.ts
  • services/platform/convex/documents.ts
  • services/platform/convex/model/onedrive/validators.ts
📚 Learning: 2025-11-30T12:29:39.745Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/workspace_rules.mdc:0-0
Timestamp: 2025-11-30T12:29:39.745Z
Learning: Applies to convex/*.ts : Split existing Convex modules that export multiple functions into separate files with one function per file, except for explicitly designated thin wrapper modules

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/model/threads/index.ts
📚 Learning: 2025-10-11T11:46:02.452Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursorrules:0-0
Timestamp: 2025-10-11T11:46:02.452Z
Learning: Applies to convex/**/*.ts : In convex/ directory, exactly one exported function per file; file name and exported function name must be identical

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/model/threads/index.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use one file per Convex function under the `convex/` directory, with file name and exported function name identical (snake_case for file names, camelCase for function names)

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/vendors/index.ts
📚 Learning: 2025-10-11T11:46:02.452Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursorrules:0-0
Timestamp: 2025-10-11T11:46:02.452Z
Learning: Applies to convex/**/*.ts : If a Convex file contains multiple functions, split into separate files so each exports exactly one function named after the file

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/model/threads/index.ts
📚 Learning: 2025-10-11T11:46:02.452Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursorrules:0-0
Timestamp: 2025-10-11T11:46:02.452Z
Learning: Applies to convex/**/*.ts : Convex file names must be snake_case and exported function names must be camelCase

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/model/threads/index.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always include argument and return validators for all Convex functions (query, internalQuery, mutation, internalMutation, action, internalAction)

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/onedrive.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/member.ts
  • services/platform/convex/model/threads/index.ts
  • services/platform/convex/documents.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-12-15T14:44:09.823Z
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/conversation_action.ts:47-98
Timestamp: 2025-12-15T14:44:09.823Z
Learning: In Convex action files (services/platform/convex/workflow/actions/**/), maintaining a separate TypeScript type alongside the parametersValidator is an acceptable pattern when documented. The TypeScript type provides IDE support and compile-time checking, while the validator provides runtime validation. This intentional separation should be documented with a comment explaining the design choice.

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/onedrive.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/member.ts
  • services/platform/convex/documents.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Use the documented Convex validators for all supported types (e.g., v.id, v.int64, v.number, v.boolean, v.string, v.bytes, v.array, v.object, v.record)

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/onedrive.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/member.ts
  • services/platform/convex/model/threads/index.ts
  • services/platform/convex/documents.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-12-26T03:04:07.995Z
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/approvals.ts:51-62
Timestamp: 2025-12-26T03:04:07.995Z
Learning: In Convex approvals API (services/platform/convex/approvals.ts), continue the pattern of maintaining separate internalQuery functions for internal vs public API access (e.g., getApprovalInternal vs getApprovalById) even if implementations are identical. This separation preserves the ability to diverge access control patterns in the future without breaking call sites. Apply this guideline broadly to the Convex-related API files under services/platform/convex/, using the pattern services/platform/convex/**/*.ts to cover similar modules. Ensure new or refactored internal/public wrappers follow this convention and document intent where access rules may evolve.

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/onedrive.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/member.ts
  • services/platform/convex/model/threads/index.ts
  • services/platform/convex/documents.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-12-30T03:24:33.770Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/wf_step_defs.ts:33-39
Timestamp: 2025-12-30T03:24:33.770Z
Learning: In Convex API files under services/platform/convex (e.g., wf_step_defs.ts and peers) refrain from delegating trivial single-line database calls like ctx.db.get(id) to model helpers. Use direct calls for simple operations with no extra business logic. Reserve model helpers for complex tasks (ordering, filtering, validation, transformation). This guideline applies to all .ts files in this Convex API area.

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/onedrive.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/member.ts
  • services/platform/convex/model/threads/index.ts
  • services/platform/convex/documents.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-12-30T06:21:13.183Z
Learnt from: larryro
Repo: tale-project/tale PR: 37
File: services/platform/convex/model/documents/validators.ts:89-102
Timestamp: 2025-12-30T06:21:13.183Z
Learning: Do not flag a missing trailing newline for TypeScript files in code reviews. POSIX text files should end with a trailing newline and Prettier (or your formatter) will enforce this. Treat the trailing newline as a non-issue in reviews for all TS files.

Applied to files:

  • services/platform/convex/model/members/index.ts
  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/onedrive.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/model/vendors/index.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/member.ts
  • services/platform/convex/model/threads/index.ts
  • services/platform/convex/documents.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-12-30T06:20:39.422Z
Learnt from: larryro
Repo: tale-project/tale PR: 37
File: services/platform/convex/model/conversations/validators.ts:106-139
Timestamp: 2025-12-30T06:20:39.422Z
Learning: In services/platform/convex/model/conversations/validators.ts, conversationItemValidator and conversationWithMessagesValidator are intentionally kept as separate validators despite having identical structures. This separation serves different semantic purposes: conversationItemValidator is for list responses while conversationWithMessagesValidator is for single conversation detail views. The duplication allows future divergence when list views might need different fields than detail views for performance or feature reasons.

Applied to files:

  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/onedrive.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/member.ts
  • services/platform/convex/model/threads/index.ts
  • services/platform/convex/documents.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Always include argument and return validators for all Convex functions; if no return, set returns: v.null()

Applied to files:

  • services/platform/convex/model/onedrive/index.ts
  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/member.ts
  • services/platform/convex/model/threads/index.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.ts : Ensure TypeScript Record key/value types match validators (e.g., Record<Id<'users'>, string>)

Applied to files:

  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/member.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use `v.id(tableName)` validator for document IDs, and use strict TypeScript types with `Id<'tableName'>` instead of generic string types for function arguments and returns

Applied to files:

  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/member.ts
  • services/platform/convex/documents.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-12-15T14:01:55.275Z
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/helpers/update_conversations.ts:7-10
Timestamp: 2025-12-15T14:01:55.275Z
Learning: In Convex action helpers (services/platform/convex/workflow/actions/**/helpers/*.ts), using Record<string, unknown> for update parameters is acceptable when field validation is handled at the mutation level in Convex. This provides flexibility for dynamic field updates while keeping validation centralized at the mutation layer.

Applied to files:

  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/onedrive.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/member.ts
  • services/platform/convex/documents.ts
  • services/platform/convex/model/onedrive/validators.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Use v.null() as the return validator when returning null

Applied to files:

  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/model/onedrive/validators.ts
📚 Learning: 2025-12-30T06:20:14.869Z
Learnt from: larryro
Repo: tale-project/tale PR: 37
File: services/platform/convex/model/conversations/validators.ts:31-39
Timestamp: 2025-12-30T06:20:14.869Z
Learning: In services/platform/convex/model/conversations/validators.ts, the messageValidator intentionally uses v.string() for the status field because message statuses are dynamic and come from different sources (email providers, internal state, etc.) and are not yet constrained to a fixed set of values.

Applied to files:

  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/onedrive.ts
  • services/platform/convex/threads.ts
  • services/platform/convex/model/email_providers/validators.ts
  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/model/onedrive/validators.ts
  • services/platform/convex/model/documents/validators.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always use `v.null()` validator when a function returns a null value, and include `returns: v.null()` even if the function doesn't explicitly return anything

Applied to files:

  • services/platform/convex/model/members/validators.ts
  • services/platform/convex/model/threads/validators.ts
  • services/platform/convex/model/onedrive/validators.ts
📚 Learning: 2025-08-21T14:59:56.034Z
Learnt from: CR
Repo: talecorp/lanserhof PR: 0
File: .cursor/rules/ai.mdc:0-0
Timestamp: 2025-08-21T14:59:56.034Z
Learning: Applies to {**/actions/*.ts,**/app/api/**/*.ts,**/lib/**/*.ts} : Always use the Vercel AI SDK to access large language models

Applied to files:

  • services/platform/convex/onedrive.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Register internal functions with internalQuery, internalMutation, and internalAction (imported from ./_generated/server)

Applied to files:

  • services/platform/convex/onedrive.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.ts : Use Id helper type from ./_generated/dataModel to type document ids (e.g., Id<'users'>)

Applied to files:

  • services/platform/convex/onedrive.ts
  • services/platform/convex/documents.ts
📚 Learning: 2025-07-20T08:40:24.693Z
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursor/rules/ai.mdc:0-0
Timestamp: 2025-07-20T08:40:24.693Z
Learning: Applies to **/actions/*.ts : Import the Vercel AI SDK directly (e.g., `import { generateObject } from 'ai'; import { openrouter } from 'openrouter/ai-sdk-provider';`)

Applied to files:

  • services/platform/convex/onedrive.ts
📚 Learning: 2025-07-03T08:43:49.346Z
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursor/rules/next-best-practice.mdc:0-0
Timestamp: 2025-07-03T08:43:49.346Z
Learning: Applies to {actions/**/*.ts,actions/**/*.tsx,app/**/*.tsx} : Prioritize server actions for mutations and side effects (use `'use server'` and server action functions)

Applied to files:

  • services/platform/convex/onedrive.ts
📚 Learning: 2025-08-21T14:59:56.034Z
Learnt from: CR
Repo: talecorp/lanserhof PR: 0
File: .cursor/rules/ai.mdc:0-0
Timestamp: 2025-08-21T14:59:56.034Z
Learning: Applies to {**/actions/*.ts,**/app/api/**/*.ts,**/lib/**/*.ts} : Import the Vercel AI SDK directly (e.g., `import { generateObject } from 'ai'; import { openrouter } from 'openrouter/ai-sdk-provider';`)

Applied to files:

  • services/platform/convex/onedrive.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Define pagination using `paginationOptsValidator` with `numItems` and `cursor` properties, and use `.paginate()` on queries which returns objects with `page`, `isDone`, and `continueCursor` properties

Applied to files:

  • services/platform/convex/onedrive.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/documents.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Always use the new Convex function syntax (query/mutation/action with args/returns/handler)

Applied to files:

  • services/platform/convex/threads.ts
  • services/platform/convex/member.ts
  • services/platform/convex/documents.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Define paginated queries using paginationOptsValidator and .paginate(opts)

Applied to files:

  • services/platform/convex/model/vendors/validators.ts
  • services/platform/convex/vendors.ts
  • services/platform/convex/documents.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always use the new Convex function syntax with `query`, `mutation`, `internalQuery`, `internalMutation`, `action`, or `internalAction` with explicit `args`, `returns`, and `handler` properties

Applied to files:

  • services/platform/convex/documents.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Be strict with types, particularly around IDs of documents; use `Id<'tableName'>` rather than `string` for function arguments and returns

Applied to files:

  • services/platform/convex/documents.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Read file metadata via the _storage system table (e.g., ctx.db.system.get(Id<'_storage'>))

Applied to files:

  • services/platform/convex/documents.ts
🧬 Code graph analysis (7)
services/platform/convex/model/members/validators.ts (2)
services/platform/convex/model/documents/validators.ts (1)
  • sortOrderValidator (107-107)
services/platform/convex/model/vendors/validators.ts (1)
  • sortOrderValidator (10-10)
services/platform/convex/threads.ts (1)
services/platform/convex/model/threads/validators.ts (4)
  • chatTypeValidator (10-13)
  • threadMessagesResponseValidator (53-55)
  • threadListItemValidator (60-66)
  • latestToolMessageValidator (71-75)
services/platform/convex/model/vendors/validators.ts (2)
services/platform/convex/model/documents/validators.ts (1)
  • sortOrderValidator (107-107)
services/platform/convex/model/members/validators.ts (1)
  • sortOrderValidator (10-10)
services/platform/convex/vendors.ts (1)
services/platform/convex/model/vendors/validators.ts (5)
  • sortOrderValidator (10-10)
  • vendorListResponseValidator (67-75)
  • vendorSourceValidator (15-19)
  • vendorAddressValidator (24-30)
  • vendorInputValidator (35-46)
services/platform/convex/member.ts (1)
services/platform/convex/model/members/validators.ts (4)
  • sortOrderValidator (10-10)
  • memberListItemValidator (15-24)
  • memberContextValidator (42-48)
  • addMemberResponseValidator (53-55)
services/platform/convex/documents.ts (1)
services/platform/convex/model/documents/validators.ts (23)
  • sourceProviderValidator (23-26)
  • uploadBase64ResponseValidator (135-142)
  • excelSheetValidator (112-118)
  • readFileBase64ResponseValidator (147-153)
  • sourceTypeValidator (158-162)
  • outputFormatValidator (167-170)
  • pdfOptionsValidator (175-183)
  • imageOptionsValidator (188-195)
  • urlOptionsValidator (210-213)
  • generateDocumentResponseValidator (218-226)
  • membershipValidator (231-236)
  • signedUrlResponseValidator (241-250)
  • documentByExtensionItemValidator (255-263)
  • deleteFromRagResponseValidator (268-274)
  • uploadFileResponseValidator (279-284)
  • createOneDriveSyncConfigResponseValidator (289-293)
  • analyzePptxResponseValidator (362-368)
  • slideContentDataValidator (381-387)
  • pptxBrandingDataValidator (392-402)
  • generatePptxResponseValidator (407-414)
  • docxContentValidator (444-448)
  • generateDocxResponseValidator (453-460)
  • retryRagIndexingResponseValidator (465-469)
services/platform/convex/model/documents/validators.ts (3)
services/platform/convex/model/members/validators.ts (1)
  • sortOrderValidator (10-10)
services/platform/convex/model/vendors/validators.ts (1)
  • sortOrderValidator (10-10)
services/platform/convex/model/products/validators.ts (1)
  • sortOrderValidator (45-45)
🔇 Additional comments (52)
services/platform/convex/model/email_providers/validators.ts (4)

41-53: LGTM! Well-structured union validators.

The sendMethodValidator and accountTypeValidator properly use v.union(v.literal(...)) to define restricted string values, following the extraction guidelines and Convex best practices.


58-100: Excellent separation of input, stored, and testing validators.

The auth validators properly distinguish between input formats (plain secrets), stored formats (encrypted secrets), and testing formats. This design pattern prevents accidental exposure of sensitive data and provides clear boundaries for different stages of the authentication flow.


105-118: LGTM! Well-composed connection test validators.

The connection test validators properly use composition (connectionTestResultValidator references connectionTestItemValidator) and correctly model optional error fields that only appear on failure.


123-128: LGTM! OAuth2 callback validator correctly handles optional fields.

The oauth2CallbackResponseValidator appropriately uses v.optional() for fields that may or may not be present in the callback response.

services/platform/convex/model/onedrive/validators.ts (1)

1-164: LGTM!

The OneDrive validators are well-structured and comprehensive. The use of v.string() for id fields is correct since these validators handle external Microsoft Graph API responses rather than internal Convex document IDs.

services/platform/convex/model/threads/index.ts (1)

5-6: LGTM!

The re-export of validators follows the established pattern for model barrel files and enables centralized access to thread validators.

services/platform/convex/model/members/index.ts (1)

5-6: LGTM!

The re-export of validators follows the established pattern for model barrel files.

services/platform/convex/model/onedrive/index.ts (1)

5-6: LGTM!

The re-export of validators follows the established pattern for model barrel files.

services/platform/convex/model/vendors/index.ts (1)

5-6: LGTM!

The re-export of validators follows the established pattern for model barrel files.

services/platform/convex/onedrive.ts (2)

21-33: LGTM!

The import of centralized validators from the model layer follows the PR's objective to consolidate validators and reduce inline definitions.


897-906: LGTM!

The refactoring successfully replaces the inline union validator with the centralized syncConfigStatusValidator, improving maintainability and consistency.

services/platform/convex/threads.ts (4)

30-51: LGTM!

The createChatThread mutation correctly uses the imported chatTypeValidator for the chatType argument, maintaining type safety while centralizing the validator definition.


80-88: LGTM!

The getThreadMessages query correctly uses the imported threadMessagesResponseValidator for the return type.


94-108: LGTM!

The listThreads query correctly uses v.array(threadListItemValidator) for the return type, maintaining consistency with the centralized validator pattern.


136-144: LGTM!

The getLatestToolMessage query correctly uses the imported latestToolMessageValidator for the return type.

services/platform/convex/vendors.ts (4)

11-18: LGTM!

The validator imports are correctly structured and all imported validators are used in this file.


99-110: LGTM!

The listVendors query correctly uses sortOrderValidator for the sortOrder argument and vendorListResponseValidator for the return type.


205-218: LGTM!

The updateVendor mutation correctly uses vendorSourceValidator for the source field and vendorAddressValidator for the address field.


296-300: LGTM!

The bulkCreateVendors mutation correctly uses v.array(vendorInputValidator) for the vendors argument, centralizing the vendor input validation.

services/platform/convex/member.ts (4)

6-12: LGTM!

The validator imports are correctly structured and all imported validators are used in this file.


53-59: LGTM!

The listByOrganization query correctly uses sortOrderValidator for the sortOrder argument and v.array(memberListItemValidator) for the return type.


121-125: LGTM!

The getCurrentMemberContext query correctly uses memberContextValidator for the return type.


230-238: LGTM!

The addMember mutation correctly uses addMemberResponseValidator for the return type.

services/platform/convex/documents.ts (20)

22-52: LGTM!

The comprehensive validator import block correctly imports all needed validators from the centralized validators module. All imported validators are used in the file.


62-82: LGTM!

The createDocument mutation correctly uses sourceProviderValidator for the sourceProvider argument.


91-101: LGTM!

The uploadBase64Internal action correctly uses uploadBase64ResponseValidator for the return type.


111-173: LGTM!

The generateExcelInternal action correctly uses v.array(excelSheetValidator) for the sheets argument.


178-186: LGTM!

The readFileBase64Internal action correctly uses readFileBase64ResponseValidator for the return type.


193-209: LGTM!

The generateDocumentInternal action correctly uses the extracted validators: sourceTypeValidator, outputFormatValidator, pdfOptionsValidator, imageOptionsValidator, urlOptionsValidator, and generateDocumentResponseValidator.


227-241: LGTM!

The queryDocuments internal query correctly uses sourceProviderValidator for the sourceProvider argument.


263-280: LGTM!

The updateDocumentInternal mutation correctly uses sourceProviderValidator for the sourceProvider argument.


285-294: LGTM!

The checkMembership internal query correctly uses membershipValidator in a union with v.null() for the return type.


299-307: LGTM!

The generateSignedUrl internal query correctly uses signedUrlResponseValidator for the return type.


315-325: LGTM!

The listDocumentsByExtension internal query correctly uses v.array(documentByExtensionItemValidator) for the return type.


334-371: LGTM!

The deleteDocumentFromRagInternal action correctly uses deleteFromRagResponseValidator for the return type.


399-413: LGTM!

The getDocuments public query correctly uses sortOrderValidator for the sortOrder argument.


527-535: LGTM!

The uploadFile action correctly uses uploadFileResponseValidator for the return type.


657-672: LGTM!

The createOneDriveSyncConfig mutation correctly uses createOneDriveSyncConfigResponseValidator for the return type.


681-691: LGTM!

The analyzePptxInternal action correctly uses analyzePptxResponseValidator for the return type.


699-715: LGTM!

The generatePptxInternal action correctly uses v.array(slideContentDataValidator) for slidesContent, v.optional(pptxBrandingDataValidator) for branding, and generatePptxResponseValidator for the return type.


720-732: LGTM!

The generateDocxInternal action correctly uses docxContentValidator for content and generateDocxResponseValidator for the return type.


742-756: LGTM!

The generateDocxFromTemplateInternal action correctly uses docxContentValidator for content and generateDocxResponseValidator for the return type.


766-807: LGTM!

The retryRagIndexing action correctly uses retryRagIndexingResponseValidator for the return type.

services/platform/convex/model/documents/validators.ts (9)

344-402: Note: Subtle difference between brandingInfoValidator and pptxBrandingDataValidator.

brandingInfoValidator (for analysis responses) uses v.optional(v.union(v.string(), v.null())) for color/font fields, while pptxBrandingDataValidator (for generation input) uses v.optional(v.string()). This appears intentional—analysis can return null values from parsed templates, while generation input expects strings or omission. No action needed, but documenting this distinction in comments would help future maintainers.


109-118: LGTM!

The excelSheetValidator is well-structured with appropriate types for sheet name, headers, and row data including support for mixed cell types.


132-153: LGTM!

The uploadBase64ResponseValidator and readFileBase64ResponseValidator are well-structured with appropriate fields for file upload/read responses.


155-226: LGTM!

The document generation validators (sourceTypeValidator, outputFormatValidator, pdfOptionsValidator, imageOptionsValidator, waitUntilValidator, urlOptionsValidator, generateDocumentResponseValidator) are well-structured and cover all the generation options.


228-293: LGTM!

The membership, signed URL, document extension, RAG deletion, file upload, and OneDrive sync config validators are well-structured with appropriate response shapes.


295-368: LGTM!

The PPTX analysis validators (textContentInfoValidator, tableInfoValidator, chartInfoValidator, imageInfoValidator, slideInfoValidator, brandingInfoValidator, analyzePptxResponseValidator) are well-structured for parsing template content.


370-414: LGTM!

The PPTX generation validators (tableDataValidator, slideContentDataValidator, pptxBrandingDataValidator, generatePptxResponseValidator) are well-structured for creating presentations.


416-469: LGTM!

The DOCX validators (docxSectionTypeValidator, docxSectionValidator, docxContentValidator, generateDocxResponseValidator) and retryRagIndexingResponseValidator are well-structured with comprehensive section type support.


120-130: Remove generateExcelResponseValidator or refactor generateExcelInternal to use it.

The validator is defined but unused. Both generateExcelInternal in documents.ts and its counterpart in node_only/documents/generate_excel_internal.ts define the return shape inline instead of referencing this validator, creating unnecessary duplication.

⛔ Skipped due to learnings
Learnt from: larryro
Repo: tale-project/tale PR: 37
File: services/platform/convex/model/conversations/validators.ts:106-139
Timestamp: 2025-12-30T06:20:39.422Z
Learning: In services/platform/convex/model/conversations/validators.ts, conversationItemValidator and conversationWithMessagesValidator are intentionally kept as separate validators despite having identical structures. This separation serves different semantic purposes: conversationItemValidator is for list responses while conversationWithMessagesValidator is for single conversation detail views. The duplication allows future divergence when list views might need different fields than detail views for performance or feature reasons.
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/conversation_action.ts:47-98
Timestamp: 2025-12-15T14:44:09.823Z
Learning: In Convex action files (services/platform/convex/workflow/actions/**/), maintaining a separate TypeScript type alongside the parametersValidator is an acceptable pattern when documented. The TypeScript type provides IDE support and compile-time checking, while the validator provides runtime validation. This intentional separation should be documented with a comment explaining the design choice.
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Use v.null() as the return validator when returning null

Comment thread services/platform/convex/model/documents/validators.ts
Comment thread services/platform/convex/model/email_providers/validators.ts
Comment thread services/platform/convex/model/members/validators.ts
Comment thread services/platform/convex/model/members/validators.ts
Comment thread services/platform/convex/model/members/validators.ts
Comment thread services/platform/convex/model/vendors/validators.ts
Comment thread services/platform/convex/model/vendors/validators.ts Outdated
Comment thread services/platform/convex/model/vendors/validators.ts
Comment thread services/platform/convex/model/vendors/validators.ts
Comment thread services/platform/convex/threads.ts
- Create model/onedrive/validators.ts with DriveItem, sync config, and response validators
- Create model/threads/validators.ts with chat type, message role, and thread validators
- Create model/members/validators.ts with sort order, member list, and context validators
- Create model/vendors/validators.ts with source, address, input, and response validators
- Add 30+ validators to model/documents/validators.ts including Excel, PPTX, DOCX validators
- Add 10+ validators to model/email_providers/validators.ts for auth and connection validators
- Update source files (documents.ts, onedrive.ts, threads.ts, member.ts, vendors.ts) to import extracted validators
- Follows existing pattern from commit 4ce7b5a

Resolves #42
@larryro larryro force-pushed the claude/extract-convex-validators-SIMbv branch from bda7687 to 8374509 Compare December 30, 2025 13:24
larryro and others added 8 commits December 30, 2025 21:28
When success is false, there won't be a message ID. Making messageId
optional allows returning error responses without a messageId.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use proper Convex document ID validator instead of v.string() for the
_id field to enforce correct ID format for the members table.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use proper Convex document ID validator instead of v.string() for the
_id field to enforce correct ID format for the members table.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…alidator

Use proper Convex document ID validator instead of v.string() for the
_id field to enforce correct ID format for the threadMessages table.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use proper Convex document ID validator instead of v.string() for the
_id field to enforce correct ID format for the threads table.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The vendorUpdateValidator was defined but never used. The updateVendor
function in vendors.ts defines its fields inline. Removing this dead code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Import and use bulkCreateVendorsResponseValidator in the
bulkCreateVendors mutation to validate the return value.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove messageRoleValidator, threadStatusValidator, and
threadMessageValidator imports that were not being used in the file.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Members, threads, and messages come from external systems (Better Auth
adapter and Agent Component) that return plain strings for _id fields,
not native Convex Id<> types. Changed validators to use v.string()
instead of v.id() to match the actual data types.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

refactor(convex): extract all inline validators to validators.ts files

2 participants