class / @typed/id

Ids

Unified Effect service for every Typed ID generator.

Package version
1.0.0-beta.13
Category
Services
Since
1.0.0

Import

import { Ids } from "@typed/id";

Signatures

export declare class Ids extends Ids_base {
    static readonly cuid: Effect.Effect<Cuid, never, Ids>;
    static readonly ksuid: Effect.Effect<Ksuid, Cause.IllegalArgumentError, Ids>;
    static readonly nanoId: Effect.Effect<NanoId, never, Ids>;
    static readonly ulid: Effect.Effect<Ulid, Cause.IllegalArgumentError, Ids>;
    static readonly uuid4: Effect.Effect<Uuid4, never, Ids>;
    static readonly uuid5: {
        (namespace: Uuid5Namespace): (name: string) => Effect.Effect<Uuid5, Cause.IllegalArgumentError, Ids>;
        (name: string, namespace: Uuid5Namespace): Effect.Effect<Uuid5, Cause.IllegalArgumentError, Ids>;
        readonly dns: (name: string) => Effect.Effect<Uuid5, Cause.IllegalArgumentError, Ids>;
        readonly url: (name: string) => Effect.Effect<Uuid5, Cause.IllegalArgumentError, Ids>;
        readonly oid: (name: string) => Effect.Effect<Uuid5, Cause.IllegalArgumentError, Ids>;
        readonly x500: (name: string) => Effect.Effect<Uuid5, Cause.IllegalArgumentError, Ids>;
    };
    static readonly uuid7: Effect.Effect<Uuid7, Cause.IllegalArgumentError, Ids>;
    static readonly Default: Layer.Layer<Ids | DateTimes | RandomValues, never, never>;
}

Why

One facade captures time, entropy, and state services once, so application code composes generators through a single explicit dependency without hiding their behavior.

Ownership and lifetime

Each Ids Layer owns its captured services plus lazy CUID and UUIDv7 state. Recreating the Layer resets process-local sequences; serialize server IDs when identity must survive hydration.

Property: Default

Provides production Ids, DateTimes, and RandomValues services.

Property: Default: Why

The standard Layer uses system time and Web Crypto while lazily creating sequence state only when CUID or UUIDv7 is first requested.

Property: Default: Ownership and lifetime

The surrounding Layer Scope owns captured services and lazy sequence state; Web Crypto must exist in the runtime.

Property: cuid

Generates a CUID using the current Ids service.

Property: cuid: Why

The facade shares the Ids-owned CuidState instead of allocating a new sequence for every call.

Property: cuid: Ownership and lifetime

This Effect acquires no resources and uses state owned by the provided Ids Layer.

Property: ksuid

Generates a KSUID using the current Ids service.

Property: ksuid: Why

The facade reuses captured time and entropy while retaining IllegalArgumentError for invalid KSUID timestamps.

Property: ksuid: Ownership and lifetime

This Effect acquires no persistent resource and uses services owned by the provided Ids Layer.

Property: nanoId

Generates a NanoId using the current Ids service.

Property: nanoId: Why

The facade makes the selected entropy implementation available through one application dependency.

Property: nanoId: Ownership and lifetime

This Effect acquires no persistent resource and uses entropy owned by the provided Ids Layer.

Property: ulid

Generates a ULID using the current Ids service.

Property: ulid: Why

The facade reuses captured time and entropy while retaining IllegalArgumentError for invalid 48-bit timestamps.

Property: ulid: Ownership and lifetime

This Effect acquires no persistent resource and uses services owned by the provided Ids Layer.

Property: uuid4

Generates a random UUID version 4 using the current Ids service.

Property: uuid4: Why

The facade keeps entropy selection replaceable while preserving UUID version and variant semantics.

Property: uuid4: Ownership and lifetime

This Effect acquires no persistent resource and uses entropy owned by the provided Ids Layer.

Property: uuid5

Derives deterministic UUID version 5 values through the current Ids service, with DNS, URL, OID, and X.500 helpers.

Property: uuid5: Why

The facade supports data-first and namespace-first calls while keeping namespace choice and IllegalArgumentError explicit.

Property: uuid5: Ownership and lifetime

Each Effect acquires no persistent resources and reads the Ids service for one invocation; helper namespaces are stable captured copies.

Call signatures

Binds a namespace first, then derives UUIDv5 values for names.

Derives a UUIDv5 from a name and namespace through the current Ids service.

Property: uuid5.dns

Derives a UUIDv5 in the standard DNS namespace.

Property: uuid5.oid

Derives a UUIDv5 in the standard OID namespace.

Property: uuid5.url

Derives a UUIDv5 in the standard URL namespace.

Property: uuid5.x500

Derives a UUIDv5 in the standard X.500 namespace.

Property: uuid7

Generates a UUID version 7 using the current Ids service.

Property: uuid7: Why

The facade shares one lazy Uuid7State per Ids Layer, preserving local monotonicity and typed timestamp errors.

Property: uuid7: Ownership and lifetime

This Effect acquires no resources and uses sequence state owned by the provided Ids Layer.

Examples

import { Ids } from "@typed/id/Ids"
import { Effect } from "effect"
const program = Effect.gen(function* () { return yield* Ids.uuid7 }).pipe(Effect.provide(Ids.Default))

See Effect services and Layers.

import { Ids } from "@typed/id/Ids"
import { Effect } from "effect"
const program = Ids.uuid5.dns("example.com").pipe(Effect.provide(Ids.Default))

Other public imports

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

Source