Skip to content

Commit 27bbb30

Browse files
committed
feat!: support Prisma client type definitions generated outside of node_modules
1 parent 4de7cfe commit 27bbb30

19 files changed

Lines changed: 454 additions & 415 deletions

.changeset/old-bushes-hope.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
"fraci": minor
3+
---
4+
5+
**BREAKING CHANGE**: Added support for Prisma client type definitions generated outside of node_modules.
6+
7+
The type definition for `PrismaClient` is no longer imported from `@prisma/client`. As a result, you must provide a type definition when instantiating fraci options or extensions. Please migrate as follows:
8+
9+
```diff
10+
import { definePrismaFraci, prismaFraci } from "fraci/prisma";
11+
import { PrismaClient } from "./path/to/your/prisma/client"; // Adjust the import path to your Prisma client
12+
13+
const baseClient = new PrismaClient();
14+
15+
- const definition = definePrismaFraci({
16+
+ const definition = definePrismaFraci(baseClient, { // or you can use `PrismaClient` instead of `baseClient`
17+
// your options here
18+
});
19+
20+
const client = baseClient.$extends(
21+
- prismaFraci(definition),
22+
+ prismaFraci(baseClient, definition), // or you can use `PrismaClient` instead of `baseClient`
23+
);
24+
```
25+
26+
Along with this, the `PrismaClient` type argument was added first to the following related public type definitions:
27+
28+
- `prismaFraci`
29+
- `definePrismaFraci`
30+
- `FraciForPrisma`
31+
- `PrismaFraciExtension`
32+
- `PrismaFraciFieldOptionsRecord`
33+
- `PrismaFraciOptions`
34+
35+
Furthermore, we are anticipating future changes to Prisma's architecture and reducing imports from `@prisma/client`. As a result, the `PrismaClientConflictError` type no longer inherits from `PrismaClientKnownRequestError`.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
node_modules
44

5+
prisma/client
6+
57
dist
68
typedoc
79
examples-bundled

CHANGELOG.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,23 @@
2323

2424
### Minor Changes
2525

26-
- 9bc7f1d: Implementated Binary Fractional Indexing.
26+
- 9bc7f1d: Implemented Binary Fractional Indexing.
2727

2828
Added support for binary-based fractional indices using `Uint8Array` for more efficient storage and operations. This implementation provides:
29-
3029
- Improved performance with optimized binary operations for generating and comparing indices
3130
- Enhanced memory efficiency for applications handling large numbers of indices
3231
- Specialized factory functions for creating binary or string-based indices
3332

3433
New Features:
35-
3634
- Added `fraciBinary` and `fraciString` factory functions for creating specialized fractional indexing utilities
3735
- Added `base` and `brand` properties to `Fraci` for better type safety and runtime information
3836
- Enhanced validation and error handling for binary fractional indices
3937

4038
Breaking Changes:
41-
4239
- **Template Parameter Signature**: Changed template parameter signature for `fraci`, `Fraci`, and `FractionalIndex` types
4340
- **Removed Properties**: Removed `digitBase` and `lengthBase` properties from `Fraci`
4441

4542
Added comprehensive type system with clear separation between binary and string-based indices:
46-
4743
- `AnyFractionalIndex`, `AnyBinaryFractionalIndex`, `AnyStringFractionalIndex`
4844
- `AnyFractionalIndexBase`, `AnyBinaryFractionalIndexBase`, `AnyStringFractionalIndexBase`
4945
- `AnyFraci`, `AnyBinaryFraci`, `AnyStringFraci`
@@ -65,7 +61,6 @@
6561
### Minor Changes
6662

6763
- b0c4151: Enhanced error handling:
68-
6964
- Added "Fraci" prefix to error messages to make it easier to identify the source of the error
7065
- Added comprehensive "Runtime Errors" section to the documentation with detailed information about each error message
7166
- Provided clear causes and solutions for each error message to improve troubleshooting experience
@@ -75,20 +70,17 @@
7570
### Minor Changes
7671

7772
- 6451d6a: **BREAKING CHANGE**: Renamed base constants for better consistency and clarity:
78-
7973
- `BASE16` -> `BASE16L` (lowercase hex digits)
8074
- `BASE26` -> `BASE26L` (lowercase alphabets)
8175
- `BASE36` -> `BASE36L` (lowercase alphanumeric)
8276
- `BASE64` -> `BASE64URL` (URL-safe Base64 characters)
8377

8478
Added new complementary constants:
85-
8679
- `BASE16U` (uppercase hex digits)
8780

8881
The naming convention now uses `L` suffix for lowercase and `U` suffix for uppercase variants.
8982

9083
- 1ba4bab: **BREAKING CHANGE**: Renamed Prisma integration function and type for better consistency with other database integrations:
91-
9284
- `fraciExtension` -> `prismaFraci` - The main function for creating Prisma extensions
9385
- `FraciExtensionOptions` ->`PrismaFraciOptions` - The options interface for configuration
9486

@@ -169,7 +161,7 @@
169161

170162
### Minor Changes
171163

172-
- d46c49a: **BREAKING CHANGE** Renamed methods and types.
164+
- d46c49a: **BREAKING CHANGE**: Renamed methods and types.
173165
- c0a5d80: Support transaction.
174166

175167
### Patch Changes
@@ -186,7 +178,7 @@
186178

187179
### Minor Changes
188180

189-
- 364b106: **BREAKING CHANGE:** Removed result extension.
181+
- 364b106: **BREAKING CHANGE**: Removed result extension.
190182

191183
## 0.3.0
192184

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ Run `bun run build-examples` to see the bundle sizes for each example.
114114

115115
| Integration | Total Size (minified) | Total Size (minified + gzipped) |
116116
| ------------------------ | ------------------------- | ------------------------------- |
117-
| **Core only (Binary)** | 3.49 KiB | **1.55 KiB** |
118-
| **Core only (String)** | 4.85 KiB | **2.06 KiB** |
119-
| **Core only (Both)** | 7.95 KiB | **3.02 KiB** |
120-
| **Drizzle ORM (Binary)** | 4.55 KiB (Core +1.06 KiB) | **2.01 KiB** (Core +0.46 KiB) |
121-
| **Drizzle ORM (String)** | 5.92 KiB (Core +1.07 KiB) | **2.50 KiB** (Core +0.44 KiB) |
122-
| **Drizzle ORM (Both)** | 8.98 KiB (Core +1.03 KiB) | **3.45 KiB** (Core +0.44 KiB) |
123-
| **Prisma ORM (Both)** | 9.29 KiB (Core +1.35 KiB) | **3.63 KiB** (Core +0.62 KiB) |
117+
| **Core only (Binary)** | 3.50 KiB | **1.56 KiB** |
118+
| **Core only (String)** | 4.86 KiB | **2.07 KiB** |
119+
| **Core only (Both)** | 7.96 KiB | **3.02 KiB** |
120+
| **Drizzle ORM (Binary)** | 4.56 KiB (Core +1.06 KiB) | **2.01 KiB** (Core +0.46 KiB) |
121+
| **Drizzle ORM (String)** | 5.93 KiB (Core +1.07 KiB) | **2.51 KiB** (Core +0.44 KiB) |
122+
| **Drizzle ORM (Both)** | 8.99 KiB (Core +1.03 KiB) | **3.46 KiB** (Core +0.44 KiB) |
123+
| **Prisma ORM (Both)** | 9.30 KiB (Core +1.35 KiB) | **3.64 KiB** (Core +0.62 KiB) |
124124

125125
## Security Considerations
126126

@@ -511,12 +511,14 @@ model Article {
511511
#### 2. Configure the Prisma extension
512512
513513
```typescript
514-
import { PrismaClient } from "@prisma/client";
515514
import { BASE62 } from "fraci";
516515
import { prismaFraci } from "fraci/prisma";
516+
import { PrismaClient } from "./path/to/your/prisma/client"; // Adjust the import path as needed
517517
518518
const prisma = new PrismaClient().$extends(
519-
prismaFraci({
519+
prismaFraci(PrismaClient, {
520+
// ^ Here, you have to pass a PrismaClient constructor or instance to help TypeScript
521+
// infer the types correctly. The passed value is NOT used at runtime.
520522
fields: {
521523
// Define the fractional index column (table.column)
522524
"article.fi": {
@@ -538,11 +540,11 @@ const prisma = new PrismaClient().$extends(
538540
> To configure the Prisma extension for binary fractional indexing:
539541
>
540542
> ```typescript
541-
> import { PrismaClient } from "@prisma/client";
542543
> import { prismaFraci } from "fraci/prisma";
544+
> import { PrismaClient } from "./path/to/your/prisma/client";
543545
>
544546
> const prisma = new PrismaClient().$extends(
545-
> prismaFraci({
547+
> prismaFraci(PrismaClient, {
546548
> fields: {
547549
> // Define the binary fractional index column
548550
> "article.fi": {

0 commit comments

Comments
 (0)