Skip to content

Conversation

lswith
Copy link
Contributor

@lswith lswith commented Jul 11, 2025

Summary

Adds a custom inspect method to AtomicOperation to provide a readable string representation of the queued operations (checks, mutations, enqueues). This improves developer experience when debugging atomic operations by showing the internal state in a human-readable format.

The implementation adds a custom [Symbol.for("Deno.customInspect")] method that formats the operations into a structured string showing:

  • Check operations with their keys and versionstamps
  • Mutation operations (set, delete, sum) with keys and values
  • Enqueue operations with payloads and options

Related Issues

Fixes #21034

The issue requested better debugging/logging support for the AtomicOperation class to help developers understand what operations are queued in an atomic transaction.

Changes

  • Added [Symbol.for("Deno.customInspect")] method to AtomicOperation class
  • Implemented formatting for check, mutation, and enqueue operations
  • Added comprehensive test coverage in tests/unit/kv_test.ts

Testing

  • Added comprehensive unit tests covering:
    • Empty atomic operations
    • Operations with checks only
    • Operations with mutations only (set, delete, sum)
    • Operations with enqueues only
    • Complex combinations of all operation types
    • Special value handling (Uint8Array, null, undefined, bigint)

All tests verify the expected human-readable inspection strings match the actual output from Deno.inspect().

Checklist

Release Notes

### kv

- Added custom inspect for `AtomicOperation` to provide readable output for debugging atomic transactions.

@CLAassistant
Copy link

CLAassistant commented Jul 11, 2025

CLA assistant check
All committers have signed the CLA.

@lswith lswith force-pushed the feat/atomic-operation-custom-inspect branch from e1f021b to 4a1dc32 Compare July 12, 2025 05:37
…ustomInspect symbol implementation to AtomicOperation\nto provide readable string representation of operations.\n\nFixes denoland#21034
@lswith lswith force-pushed the feat/atomic-operation-custom-inspect branch from 4a1dc32 to 42f84be Compare July 12, 2025 05:43
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@bartlomieju bartlomieju changed the title feat(kv): implement custom inspect for AtomicOperation feat(unstable): implement custom inspect for Deno.AtomicOperation Aug 13, 2025
@bartlomieju bartlomieju merged commit b2fd724 into denoland:main Aug 13, 2025
19 checks passed
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.

Useful output when logging AtomicOperations
4 participants