Documentation
¶
Overview ¶
Package tsid generates Time-Sorted IDs as Crockford Base32 strings.
Compatible with the other FlowCatalyst SDKs' generators. A raw TSID is 13 characters; a typed TSID is {prefix}_{13-char-raw} (e.g. "clt_0HZXEQ5Y8JY5Z").
Layout of the 64-bit value:
bits 63..22 timestamp (42 bits, millis since epoch) bits 21..10 sequence (12 bits) bits 9..0 random (10 bits)
The order of the two low fields is the whole of "time-sorted". The sequence is what makes ids minted inside one millisecond comparable, so it has to outrank the random field: with random above it, two ids from the same millisecond sorted by NOISE and the counter contributed nothing to ordering at all. Sorting is by string, and Crockford Base32 is order-preserving, so the bit order IS the sort order.
Collision resistance is unchanged by the swap — it still takes the same (millisecond, sequence, random) triple to collide — because only the comparison order moved, not the entropy.
This package is the SDK-exported primitive set: generation, encoding, decoding. FlowCatalyst's typed-entity catalog lives in the platform's internal/tsid package and forwards to these primitives, so SDK consumers (and operations within the platform) share a single implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeCrockford ¶
DecodeCrockford parses a 13-char Crockford Base32 string back to its 64-bit value. Returns 0, false on malformed input.
func Generate ¶
func Generate(e EntityType) string
Generate returns a typed TSID with the entity's 3-char prefix: "{prefix}_{13-char-raw}", e.g. "clt_0HZXEQ5Y8JY5Z".
func GenerateRaw ¶
func GenerateRaw() string
GenerateRaw produces the 13-character Crockford Base32 TSID.
Within one process the result is strictly increasing: the millisecond only moves forward (nextMsSeq borrows the next one rather than reusing a sequence), and inside a millisecond the sequence increments — and the sequence sits above the random field, so nothing below can reverse the pair.
func GenerateUntyped ¶
func GenerateUntyped() string
GenerateUntyped returns a raw 13-character TSID with no prefix. Used for execution IDs, trace IDs, event IDs, and other non-entity contexts.
func GenerateWithPrefix ¶
GenerateWithPrefix returns a typed TSID with a custom prefix. Use this for application-specific entity types not in EntityType.
Types ¶
type EntityType ¶
type EntityType int
EntityType enumerates the well-known prefixes used across the FlowCatalyst platform. Mirrors the TypeScript / Laravel SDKs — all SDKs share the same wire format.
New variants MUST be added to every SDK so the format stays consistent.
const ( Client EntityType = iota Principal Application ServiceAccount Role Permission OAuthClient AuthCode LoginAttempt ClientAuthConfig AppClientConfig IdpRoleMapping CorsOrigin AnchorDomain IdentityProvider EmailDomainMapping ClientAccessGrant EventType Event EventRead Connection Subscription DispatchPool DispatchJob DispatchJobRead Schema AuditLog PlatformConfig ConfigAccess PasswordResetToken WebauthnCredential ScheduledJob ScheduledJobInstance ScheduledJobInstanceLog ApplicationOpenApiSpec Process PortalUser PortalApp )
func (EntityType) Prefix ¶
func (e EntityType) Prefix() string
Prefix returns the 3-character platform prefix for the entity type.