Skip to content

fix(server): harden RPC $transaction handler correctness#2404

Closed
Copilot wants to merge 5 commits intodevfrom
copilot/sub-pr-2399
Closed

fix(server): harden RPC $transaction handler correctness#2404
Copilot wants to merge 5 commits intodevfrom
copilot/sub-pr-2399

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

Several correctness issues in the handleTransaction RPC handler surfaced in review.

Changes:

  • Transaction type validation — pass the URL path segment (e.g. sequential) into handleTransaction and return 400 for any unrecognised type, preventing silent acceptance of typo'd routes like /$transaction/foobar
  • SuperJSON deserialization — run each operation's args through processRequestPayload before invoking the ORM, so BigInt/Date/Bytes fields encoded with meta.serialization are correctly deserialized (same pipeline as regular RPC operations)
  • Promise construction inside try — build the promise array inside the try block so that a missing/undefined model operation (e.g. invalid op name) throws into the error handler rather than crashing unguarded; additionally tighten the args validation to reject arrays
  • VALID_OPS hoisted to module scope — replaced the hardcoded per-call Set with new Set(CoreCrudOperations) at module level to avoid redundancy and stay in sync with the canonical operation list
  • Test cleanup — moved deleteMany cleanup into beforeEach/afterEach within the describe('transaction') block to eliminate repeated inline teardown

Example — before (args bypass deserialization):

// Date was passed raw; ORM may receive a string instead of a Date
const promises = requestBody.map(item => client[model][op](item.args ?? {}));

After:

const { result: processedArgs } = await this.processRequestPayload(itemArgs ?? {});
processedOps.push({ model, op, args: processedArgs });
// …inside try:
const promises = processedOps.map(({ model, op, args }) => client[model][op](args));

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add transaction handling with sequential operations and validation fix(server): harden RPC $transaction handler correctness Feb 25, 2026
Copilot AI requested a review from jiashengguo February 25, 2026 12:42
Base automatically changed from jiasheng-transaction to dev February 25, 2026 12:49
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.

2 participants