Coverage for src/prosemark/adapters/id_generator_uuid7.py: 100%

5 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-09-24 18:08 +0000

1# Copyright (c) 2024 Prosemark Contributors 

2# This software is licensed under the MIT License 

3 

4"""UUIDv7-based ID generator implementation.""" 

5 

6from prosemark.domain.models import NodeId 

7from prosemark.ports.id_generator import IdGenerator 

8 

9 

10class IdGeneratorUuid7(IdGenerator): 

11 """Production ID generator using UUIDv7 for temporal ordering. 

12 

13 This implementation leverages the UUIDv7 format to provide: 

14 - Globally unique identifiers 

15 - Temporal ordering capabilities (newer UUIDs sort after older ones) 

16 - Distributed generation without coordination 

17 - Compatibility with existing UUID tooling 

18 

19 The UUIDv7 format embeds a timestamp in the first 48 bits, enabling 

20 natural chronological sorting while maintaining the randomness properties 

21 needed for uniqueness across distributed systems. 

22 """ 

23 

24 def new(self) -> NodeId: 

25 """Generate a new NodeId using UUIDv7. 

26 

27 Returns: 

28 A new NodeId with UUIDv7 format 

29 

30 """ 

31 return NodeId.generate()