# DeterministicUuidRegistry

**Kind:** Class

**Source:** [`packages/core/inspector/deterministic-uuid-registry.ts`](https://github.com/nestjs/nest/blob/master/packages/core/inspector/deterministic-uuid-registry.ts#L1)

**Part of:** [Core](subsystem-packages-core)

`DeterministicUuidRegistry` maintains stable UUID values for identifiers encountered during inspection. It returns the same UUID for a given registry key throughout a registry lifecycle and can reset its stored mappings with `clear()`.

## Methods

| Method | Signature | Returns |
|---|---|---|
| `get` | `get(str: string, inc: undefined)` | `void` |
| `clear` | `clear()` | `void` |

## Where it refuses work

- `DeterministicUuidRegistry` stops the work with an early return when `this.registry.has(id)`.

## Diagram

```mermaid
graph LR
  A[Inspector / Caller] -->|get(stable key)| B[DeterministicUuidRegistry]
  B -->|existing mapping| C[Previously assigned UUID]
  B -->|new mapping| D[Deterministically generated UUID]
  D --> E[Registry storage]
  E --> C
  A -->|clear()| B
  B -->|remove mappings| E
```

## Usage

```ts
import { DeterministicUuidRegistry } from "./deterministic-uuid-registry";

const uuidRegistry = new DeterministicUuidRegistry();

// Repeated lookups for the same stable key return the same UUID.
const firstId = uuidRegistry.get("workflow-step:validate-input");
const secondId = uuidRegistry.get("workflow-step:validate-input");

console.log(firstId === secondId); // true

// Reset mappings when starting a new inspection lifecycle.
uuidRegistry.clear();
```

## AI Coding Instructions

- Use stable, meaningful keys when calling `get()` so generated UUIDs remain consistent across related inspection operations.
- Reuse a single registry instance for the full inspection or serialization lifecycle that requires stable identifiers.
- Call `clear()` only when beginning a new independent lifecycle; clearing during processing invalidates existing mappings.
- Do not treat returned UUIDs as permanent persisted IDs unless the registry lifecycle and input keys are also persisted.

## How it works

## `DeterministicUuidRegistry`

`DeterministicUuidRegistry` is a static registry that generates string IDs from an input string and tracks IDs already returned during the registry’s current lifetime. Its state is a private static `Map<string, boolean>`, shared by every call to the class. [packages/core/inspector/deterministic-uuid-registry.ts:1-2]
