47ng / 47ng/prisma-field-encryption

Documenting Typing the Extended PrismaClient

Aperta Adatta ai principianti
#129 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
306
Fork
40
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I've been running into an issue where the VSCode Typescript errors with errors like the following:
```
Excessive stack depth comparing types...
```
```
This expression is not callable....
```
After searching and consulting with various AI oracles I realized the issue could be solved by removing the prisma-field-encryption extension. This Github issue was a hint, although the discussion is from when clientExtensions were a preview feature.

https://github.com/prisma/prisma/issues/17236

The solution seems to be the following:

```typescript
import { PrismaClient } from '@prisma/client'
import { fieldEncryptionExtension } from 'prisma-field-encryption'
import { type PrismaClientExtends } from '@prisma/client/extension'
import type * as runtime from '@prisma/client/runtime/library'

// Define the extended client type using Prisma's extension type system
type ExtendedClient = PrismaClient & PrismaClientExtends

const globalClient = new PrismaClient()

export const client = globalClient.$extends(
// This is a function, don't forget to call it:
fieldEncryptionExtension()
) as ExtendedClient

export type { ExtendedClient as PrismaClient }
```

Does this fix make sense? It is working nicely for me. If so I'd like to open a PR to add this to the Readme. 🙏

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

The issue is about adding a TypeScript typing example to the README. Look at the existing README file to see where the usage examples are placed. The provided code snippet shows how to type an extended PrismaClient with the field encryption extension. Verify the snippet works by checking the current extension API in the source code, then update the documentation accordingly.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
1/5
Tempo stimato
Meno di un'ora
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
75/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.