jetpack-io / typeid
- воскресенье, 2 июля 2023 г. в 00:00:11
Type-safe, K-sortable, globally unique identifier inspired by Stripe IDs
TypeIDs are a modern, type-safe extension of UUIDv7. Inspired by a similar use of prefixes in Stripe's APIs.
TypeIDs are canonically encoded as lowercase strings consisting of three parts:
Here's an example of a TypeID of type user:
user_2x4y6z8a0b1c2d3e4f5g6h7j8k
└──┘ └────────────────────────┘
type uuid suffix (base32)
A formal specification defines the encoding in more detail.
user ID where a post ID is expected. When debugging, you can
immediately understand what type of entity a TypeID refers to thanks to the type prefix.Implementations should adhere to the formal specification.
jetpack.io| Language | Status |
|---|---|
| Go | ✓ Implemented |
| Python | ... Coming Soon |
| SQL | ✓ Implemented |
| TypeScript | ✓ Implemented |
| Language | Author | Validated Against Spec? |
|---|---|---|
| C# (.Net) | @TenCoKaciStromy | Not Yet |
| Python | @akhundMurad | Yes, 2023-06-30 |
| Ruby | @broothie | Yes, on 2023-06-30 |
| Rust | @alisa101rs | Not Yet |
| Rust | @conradludgate | Yes, on 2023-07-01 |
| Swift | @Frizlab | Yes, on 2023-06-30 |
| TypeScript | @ongteckwu | Yes, on 2023-06-30 |
We are looking for community contributions to implement TypeIDs in other languages.
This repo includes a command-line tool for generating TypeIDs. To install it, run:
curl -fsSL https://get.jetpack.io/typeid | bashTo generate a new TypeID, run:
$ typeid new prefix
prefix_01h2xcejqtf2nbrexx3vqjhp41To decode an existing TypeID into a UUID run:
$ typeid decode prefix_01h2xcejqtf2nbrexx3vqjhp41
type: prefix
uuid: 0188bac7-4afa-78aa-bc3b-bd1eef28d881And to encode an existing UUID into a TypeID run:
$ typeid encode prefix 0188bac7-4afa-78aa-bc3b-bd1eef28d881
prefix_01h2xcejqtf2nbrexx3vqjhp41Alternatives to UUIDv7 that are also worth considering (but not type-safe like TypeIDs):