class / @typed/id/Uuid7

Uuid7State

Process-local Effect service that produces monotonic UUID version 7 seeds.

Package version
1.0.0-beta.7
Category
Sequence state
Since
1.0.0

Import

import { Uuid7State } from "@typed/id/Uuid7";

Signatures

export declare class Uuid7State extends Uuid7State_base {
    static readonly next: Effect.Effect<{
        timestamp: number;
        seq: number;
        randomBytes: Uint8Array<ArrayBufferLike> & {
            readonly length: 16;
        };
    }, Cause.IllegalArgumentError, Uuid7State>;
    static readonly Default: Layer.Layer<Uuid7State, never, never>;
}

Why

Clock rollback and 32-bit sequence rollover are handled inside an explicit service, guaranteeing monotonicity only for one shared service instance.

Ownership and lifetime

Each Layer instance owns mutable timestamp and sequence state. A new process, worker, deployment, or Layer resets it; exact hydration identity must be serialized.

Property: Default

Provides Uuid7State from system time and Web Crypto entropy.

Property: Default: Why

The production default is explicit while remaining replaceable by deterministic service layers.

Property: Default: Ownership and lifetime

Layer acquisition creates one mutable sequence state owned by the surrounding Layer Scope.

Property: next

Reads the next validated seed from the current Uuid7State.

Property: next: Why

The accessor exposes ordered state through Effect’s service channel and reports timestamp exhaustion as IllegalArgumentError.

Property: next: Ownership and lifetime

The Effect uses the state owned by its provided Layer and acquires no separate persistent resource.

Examples

import { uuid7, Uuid7State } from "@typed/id/Uuid7"
import { Effect } from "effect"
const id = Effect.provide(uuid7, Uuid7State.Default)

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source