# prisma-generator-t3-enums

> Prisma generator to export enums as TypeScript types following the T3 pattern

Latest version **1.1.0** (published 2023-04-09) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install prisma-generator-t3-enums
pnpm add prisma-generator-t3-enums
yarn add prisma-generator-t3-enums
bun add prisma-generator-t3-enums
```

Provides the command `prisma-generator-t3-enums`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-04-09 |
| First published | 2023-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14.0 |
| Dependencies | 5 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Todd Judd |
| Maintainers | tracer482 |
| Keywords | prisma, prisma2, generator |

## Links

- npm: https://www.npmjs.com/package/prisma-generator-t3-enums
- Repository: https://github.com/toddjudd/prisma-generator-t3-enums
- Homepage: https://github.com/toddjudd/prisma-generator-t3-enums/README.md
- Issues: https://github.com/toddjudd/prisma-generator-t3-enums/issues
- npm.io page: https://npm.io/package/prisma-generator-t3-enums

## Dependencies (5)

- [zod](https://npm.io/package/zod.md) ^3.20.2
- [prettier](https://npm.io/package/prettier.md) 2.5.1
- [@prisma/sdk](https://npm.io/package/@prisma/sdk.md) 3.12.0
- [@prisma/client](https://npm.io/package/@prisma/client.md) 4.12.0
- [@prisma/generator-helper](https://npm.io/package/@prisma/generator-helper.md) 4.12.0

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2023-04-09
- 1.0.1 — 2023-01-12
- 1.0.0 — 2023-01-12

## README

<div align="center">
  <a href="https://www.npmjs.com/package/prisma-generator-t3-enums"><img src="https://img.shields.io/npm/v/prisma-generator-t3-enums.svg?style=flat" /></a>
  <a href="https://npmcharts.com/compare/prisma-generator-t3-enums?minimal=true"><img src="https://img.shields.io/npm/dm/prisma-generator-t3-enums.svg?style=flat"/></a>
  <a href="https://github.com/toddjudd/prisma-generator-t3-enums/blob/main/CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" /></a>
  <a href="https://github.com/toddjudd/prisma-generator-t3-enums/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" /></a>
  <br />
  <br />
  <a href="https://github.com/toddjudd/prisma-generator-t3-enums#Usage">Usage</a>
  <br />
  <hr />
</div>

# Motivation

Working with enums can be a foot gun! Theo Browne explains this well in his "[TypeScript's Worst Feature (And How To Avoid It)](youtube.com/watch?v=Anu8vHXsavo)" video.

The purpose of this is to allow [Prisma](https://www.prisma.io/) to be the source of truth when it comes enums. when running `prisma generate` the goal is to generate an out put such as this

```ts
import * as z from 'zod'

export const language = [
  'Typescript',
  'Javascript',
  'Rust',
  'Go',
  'Python',
  'Cpp',
] as const

export type Language = typeof language[number]

export const languageSchema = z.enum(language)
```

This way you can reference these values in code to populate iterate over options, validate their shape, or ensure type safety.

# Usage

## install

[zod](https://github.com/colinhacks/zod) is prety awesome, it'll be required for the `z.enum()` provided by the generator.

`npm i prisma-generator-t3-enums zod`

## Prisma Schema

add the generator to the `schema.prisma`. You can define the output dir of the generated types by replacing the `"../types"` value.

```prisma
generator custom_generator {
  provider = "prisma-generator-t3-enums"
  output   = "../types"
}
```

use `npx prisma generate` to generate the enum exports

> This generator was bootstraped using [create-prisma-generator](https://github.com/YassinEldeeb/create-prisma-generator)

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