feat: support returnOnConditionCheckFailure on write operations#552
feat: support returnOnConditionCheckFailure on write operations#552anatolzak wants to merge 12 commits into
returnOnConditionCheckFailure on write operations#552Conversation
✅ Deploy Preview for electrodb-dev canceled.
|
|
Hey @tywalch! Let me know what you think about this proposal and the API design. Handling condition check failures seems common enough that it probably deserves first class support in the library, similar to how we treat transactions today by returning errors as values. Also sorry for the flood of PRs today 😅. While migrating to multi-attribute composite indexes, I ran into a few bugs and found some opportunities to improve the accuracy of the TypeScript types around the new feature. Appreciate you taking the time to review them! |
No sorry needed, your contributions have been solid and very impactful 💪 Can you give me a sense of what you're hoping for in terms of prioritization? |
|
Hey @tywalch! Do you mind taking a look at the 2 open PRs above when you get a chance? |
Add `returnOnConditionCheckFailure: "all_old"` option to `go()` for write
operations (put, create, update, patch, delete, remove, upsert). When a
condition expression fails, returns `{ rejected: true, data: existingItem }`
instead of throwing, using DynamoDB's `ReturnValuesOnConditionCheckFailure`.
Includes TypeScript types, integration tests (v2 + v3), params tests, and docs.
f11ecc2 to
96df224
Compare
Accepts `true` in addition to `"all_old"`. The `true` mode resolves with
`{ rejected: true }` on condition failure without fetching the existing
item
— no extra DynamoDB payload cost.
`originalErr` is now orthogonal: when `returnOnConditionCheckFailure` is
set,
condition-check rejections are always caught, regardless of
`originalErr`.
Previously the two flags interacted and `originalErr: true` would
re-throw
the rejection.
…ConditionCheckFailure is set
…ionCheckFailure: "all_old"` is now typed as the full `EntityItem` instead of `Partial<EntityItem>`
…heck tsd tests
|
@tywalch heads up, I added another mode. On top of |
closes #551
Adds a
returnOnConditionCheckFailure?: boolean | "all_old"execution option for write operations (put,create,update,patch,delete,remove,upsert). When a condition expression fails, the call resolves instead of throwing.Modes
true— resolves with{ rejected: true }. No extra DDB cost."all_old"— resolves with{ rejected: true, data: existingItem | null }. Sets DynamoDB'sReturnValuesOnConditionCheckFailure: "ALL_OLD". Requires AWS SDK v3 or v2 >=2.1408.0.false/ omitted — throws (default).Notes
datais typed as the fullEntityItem<E>for every write op, including theupdate/patchchains.originalErris orthogonal — condition-check failures always resolve with{ rejected: true }.originalErronly governs how non-conditional DynamoDB errors are surfaced.ResourceNotFoundException) still throw normally.Tests
trueand"all_old"modes (84 tests).expectErrorassertions for invalid string values and forresult.rejectedaccess when the option is not set..params()tests verifyingReturnValuesOnConditionCheckFailureis/isn't set on the underlying DDB params.response,data: "raw" | "includeKeys",originalErr: true.Docs
Updated the mutation execution options reference and added a "Handling Condition Check Failures" section to
mutations/conditions.