# miragejs-uuidmanager

> miragejs custom uuid identityManager

Latest version **1.0.3** (published 2022-08-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install miragejs-uuidmanager
pnpm add miragejs-uuidmanager
yarn add miragejs-uuidmanager
bun add miragejs-uuidmanager
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-08-06 |
| First published | 2022-08-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | cxliao617 |
| Maintainers | cxliao617 |
| Keywords | miragejs |

## Links

- npm: https://www.npmjs.com/package/miragejs-uuidmanager
- Repository: https://github.com/cxliao617/miragejs-uuidManager
- Homepage: https://github.com/cxliao617/miragejs-uuidManager#readme
- Issues: https://github.com/cxliao617/miragejs-uuidManager/issues
- npm.io page: https://npm.io/package/miragejs-uuidmanager

## Dependencies (2)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [@types/uuid](https://npm.io/package/@types/uuid.md) ^8.3.4

## Recent versions

- 1.0.3 (latest) — 2022-08-06
- 1.0.2 — 2022-08-06
- 1.0.1 — 2022-08-06
- 1.0.0 — 2022-08-06

## README

# miragejs-uuidManager
miragejs custom uuid identityManager

## Custom Identity Manager into UUID v4 format
```typescript
import {v4} from 'uuid'

export default class UuidManager{
    ids = new Set()

    constructor(){
        this.ids = new Set()
    }
    fetch(){
        let id = v4()
        while(this.ids.has(id))
        {
            id = v4()
        }
        this.ids.add(id)

        return id
    }
    set(id: string)
    {
        if(this.ids.has(id))
        {
            throw new Error(`ID ${id} has already been used.`)
        }
        this.ids.add(id)
    }
    reset()
    {
        this.ids.clear()
    }
}
```

## Usage
```typescript
import {createServer,Factory,Model,Serializer} from 'miragejs'

import UuidManager from 'miragejs-uuidmanager'

export function MockServer({environment = 'development'}){
    return createServer({
        environment,
        identityManagers: {
            todo: UuidManager,
        } as any,
        ...
    })
}
```

---
_Source: https://npm.io/package/miragejs-uuidmanager · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
