# CuidState

Process-local Effect service that supplies sequential CUID seeds.

## Signatures

```ts
export declare class CuidState extends CuidState_base {
    static readonly next: Effect.Effect<{
        timestamp: number;
        counter: number;
        random: Uint8Array<ArrayBufferLike> & {
            readonly length: 32;
        };
        fingerprint: string;
    }, never, CuidState>;
    static readonly Default: Layer.Layer<CuidState, never, never>;
}
```

## Why

Counter state and caller-provided `envData` live in an explicit service so tests and applications choose the sharing boundary instead of relying on hidden globals.

## Ownership and lifetime

Each Layer instance owns its mutable counter and captured fingerprint. A new process, worker, or Layer resets that sequence; exact SSR identity must be serialized and reused.

## Property: Default

Provides a default CuidState backed by system time and Web Crypto entropy.

## Property: Default: Why

The explicit Layer gives production code a standard service while keeping test and environment-specific alternatives replaceable.

## Property: Default: Ownership and lifetime

Layer acquisition creates one counter state; the surrounding Layer Scope owns it. Web Crypto must be available in the runtime.

## Property: next

Reads one seed from the current CuidState service.

## Property: next: Why

The accessor exposes stateful sequencing through Effect's service channel rather than a module-global counter.

## Property: next: Ownership and lifetime

The Effect requires `CuidState`; its Layer owns the counter for the Layer lifetime.

## Examples

```ts
import { cuid, CuidState } from "@typed/id/Cuid"
import { Effect } from "effect"
const program = Effect.provide(cuid, CuidState.Default)
```
See [Effect services](https://effect.website/docs/requirements-management/services/) and [Layers](https://effect.website/docs/requirements-management/layers/).
