prisma-effect-kysely 5.4.0 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +66 -233
- package/package.json +21 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 52ccb28: Update all dependencies to latest versions and condense README/CLAUDE docs.
|
|
8
|
+
|
|
9
|
+
Major bumps:
|
|
10
|
+
- `typescript`: 5.9.3 → 6.0.3
|
|
11
|
+
- `eslint`, `@eslint/js`: 9.x → 10.x
|
|
12
|
+
- `@effect/vitest`: 0.27.0 → 0.29.0
|
|
13
|
+
- `@changesets/changelog-github`: 0.5.x → 0.6.0
|
|
14
|
+
|
|
15
|
+
Minor/patch bumps:
|
|
16
|
+
- `@prisma/generator-helper`, `@prisma/internals`, `prisma`: 7.2.0 → 7.8.0
|
|
17
|
+
- `prettier`: 3.7.4 → 3.8.3
|
|
18
|
+
- `@changesets/cli`: 2.29.8 → 2.31.0
|
|
19
|
+
- `@types/node`: 25.0.3 → 25.6.0
|
|
20
|
+
- `@typescript-eslint/*`, `typescript-eslint`: 8.50.0 → 8.59.1
|
|
21
|
+
- `@vitest/coverage-v8`, `vitest`: 4.0.16 → 4.1.5
|
|
22
|
+
- `@vitest/eslint-plugin`: 1.5.4 → 1.6.16
|
|
23
|
+
- `effect`: 3.19.14 → 3.21.2
|
|
24
|
+
- `kysely`: 0.28.9 → 0.28.16
|
|
25
|
+
- `lint-staged`: 16.2.7 → 16.4.0
|
|
26
|
+
|
|
3
27
|
## 5.4.0
|
|
4
28
|
|
|
5
29
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# prisma-effect-kysely
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Prisma generator producing Effect Schema types with Kysely-compatible column metadata, branded IDs, and intelligent UUID detection.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- ✅ **Type-Safe Generation**: Zero type coercion, complete type safety
|
|
8
|
-
- ✅ **Intelligent UUID Detection**: Via `@db.Uuid`, `nativeType`, or field name patterns
|
|
9
|
-
- ✅ **Enum Support**: Effect Schema enums with `@map` annotation support
|
|
10
|
-
- ✅ **Deterministic Output**: Alphabetically sorted for consistent results
|
|
11
|
-
- ✅ **Complete Type Mappings**: All Prisma types mapped to Effect Schema equivalents
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
5
|
+
## Install
|
|
14
6
|
|
|
15
7
|
```bash
|
|
16
8
|
bun add prisma-effect-kysely
|
|
17
|
-
# or
|
|
18
|
-
npm install prisma-effect-kysely
|
|
19
9
|
```
|
|
20
10
|
|
|
21
|
-
##
|
|
22
|
-
|
|
23
|
-
### 1. Add to schema.prisma
|
|
11
|
+
## Setup
|
|
24
12
|
|
|
25
13
|
```prisma
|
|
26
14
|
generator effect_schemas {
|
|
@@ -29,37 +17,23 @@ generator effect_schemas {
|
|
|
29
17
|
}
|
|
30
18
|
```
|
|
31
19
|
|
|
32
|
-
### 2. Generate Effect Schemas
|
|
33
|
-
|
|
34
20
|
```bash
|
|
35
21
|
npx prisma generate
|
|
36
22
|
```
|
|
37
23
|
|
|
38
24
|
## Output
|
|
39
25
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### enums.ts
|
|
43
|
-
|
|
44
|
-
Effect Schema enums from Prisma enums with exact literal types:
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
export const UserRoleSchema = Schema.Literal('admin', 'user', 'guest');
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### types.ts
|
|
51
|
-
|
|
52
|
-
Effect Schema structs from Prisma models with Kysely integration (v5.0 direct exports):
|
|
26
|
+
Three files: `enums.ts`, `types.ts`, `index.ts`.
|
|
53
27
|
|
|
54
28
|
```typescript
|
|
55
29
|
import { Schema } from "effect";
|
|
56
30
|
import { columnType, generated, Selectable } from "prisma-effect-kysely";
|
|
57
31
|
|
|
58
|
-
//
|
|
32
|
+
// Branded ID
|
|
59
33
|
export const UserId = Schema.UUID.pipe(Schema.brand("UserId"));
|
|
60
34
|
export type UserId = typeof UserId.Type;
|
|
61
35
|
|
|
62
|
-
//
|
|
36
|
+
// Model schema
|
|
63
37
|
export const User = Schema.Struct({
|
|
64
38
|
id: columnType(Schema.UUID, Schema.Never, Schema.Never),
|
|
65
39
|
email: Schema.String,
|
|
@@ -67,263 +41,122 @@ export const User = Schema.Struct({
|
|
|
67
41
|
});
|
|
68
42
|
export type User = typeof User;
|
|
69
43
|
|
|
70
|
-
//
|
|
44
|
+
// Kysely DB interface
|
|
71
45
|
export interface DB {
|
|
72
46
|
User: Selectable<User>;
|
|
73
47
|
}
|
|
74
48
|
```
|
|
75
49
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
Re-exports all generated types for easy importing
|
|
79
|
-
|
|
80
|
-
## Consumer Usage (v5.0)
|
|
81
|
-
|
|
82
|
-
Branded ID types are exported directly. Use type utilities from `prisma-effect-kysely` for other types:
|
|
50
|
+
## Consumer Usage
|
|
83
51
|
|
|
84
52
|
```typescript
|
|
85
53
|
import { Selectable, Insertable, Updateable } from "prisma-effect-kysely";
|
|
86
54
|
import { User, UserId, DB } from "./generated";
|
|
87
55
|
|
|
88
|
-
// Branded ID type - direct import (no utility needed)
|
|
89
56
|
function getUser(id: UserId): Promise<User> { ... }
|
|
90
57
|
|
|
91
|
-
// Extract types using utilities (Kysely-native pattern)
|
|
92
58
|
type UserSelect = Selectable<typeof User>;
|
|
93
59
|
type UserInsert = Insertable<typeof User>;
|
|
94
60
|
type UserUpdate = Updateable<typeof User>;
|
|
95
61
|
|
|
96
|
-
// Use with Kysely
|
|
97
|
-
import { Kysely } from 'kysely';
|
|
98
|
-
|
|
99
62
|
const db = new Kysely<DB>({ ... });
|
|
100
|
-
|
|
101
|
-
// Type-safe queries
|
|
102
|
-
const user = await db.selectFrom('User').selectAll().executeTakeFirst();
|
|
103
63
|
```
|
|
104
64
|
|
|
105
|
-
|
|
65
|
+
Schema names are PascalCase regardless of Prisma model name (`session_preference` → `SessionPreference`).
|
|
66
|
+
|
|
67
|
+
## Field Behavior
|
|
106
68
|
|
|
107
|
-
-
|
|
108
|
-
-
|
|
69
|
+
- `@default` / `@updatedAt` → `generated()` (omitted from insert, optional in update)
|
|
70
|
+
- `@id` with `@default` → `columnType(type, Never, Never)` (read-only)
|
|
71
|
+
- Optional fields → `Schema.NullOr(type)`
|
|
72
|
+
- Foreign keys → branded ID type from target model
|
|
109
73
|
|
|
110
74
|
## Type Mappings
|
|
111
75
|
|
|
112
|
-
| Prisma
|
|
113
|
-
| ----------- |
|
|
114
|
-
| String | `Schema.String`
|
|
115
|
-
| Int / Float | `Schema.Number`
|
|
116
|
-
| BigInt | `Schema.BigInt`
|
|
117
|
-
| Decimal | `Schema.String`
|
|
118
|
-
| Boolean | `Schema.Boolean`
|
|
119
|
-
| DateTime | `Schema.DateFromSelf` |
|
|
120
|
-
| Json | `Schema.Unknown`
|
|
121
|
-
| Bytes | `Schema.Uint8Array`
|
|
122
|
-
| Enum |
|
|
76
|
+
| Prisma | Effect Schema |
|
|
77
|
+
| ----------- | --------------------- |
|
|
78
|
+
| String | `Schema.String` |
|
|
79
|
+
| Int / Float | `Schema.Number` |
|
|
80
|
+
| BigInt | `Schema.BigInt` |
|
|
81
|
+
| Decimal | `Schema.String` |
|
|
82
|
+
| Boolean | `Schema.Boolean` |
|
|
83
|
+
| DateTime | `Schema.DateFromSelf` |
|
|
84
|
+
| Json | `Schema.Unknown` |
|
|
85
|
+
| Bytes | `Schema.Uint8Array` |
|
|
86
|
+
| Enum | `Schema.Literal(...)` |
|
|
87
|
+
| UUID | `Schema.UUID` |
|
|
88
|
+
|
|
89
|
+
Arrays → `Schema.Array(t)`. Nullable → `Schema.NullOr(t)`.
|
|
123
90
|
|
|
124
91
|
## UUID Detection
|
|
125
92
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
1. **Native Type**: `@db.Uuid` attribute (most reliable)
|
|
129
|
-
2. **Documentation**: `@db.Uuid` in field comments
|
|
130
|
-
3. **Default Value**: `dbgenerated("gen_random_uuid()")` or similar
|
|
131
|
-
4. **Field Name Patterns**: `id`, `*_id`, `*_uuid`, `uuid`
|
|
132
|
-
|
|
133
|
-
Example:
|
|
134
|
-
|
|
135
|
-
```prisma
|
|
136
|
-
model User {
|
|
137
|
-
id String @id @db.Uuid @default(dbgenerated("gen_random_uuid()"))
|
|
138
|
-
userId String @db.Uuid // Detected via native type
|
|
139
|
-
productId String // Detected via field name pattern
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Development
|
|
144
|
-
|
|
145
|
-
This project uses **Bun** as the sole package manager.
|
|
146
|
-
|
|
147
|
-
```bash
|
|
148
|
-
# Install dependencies
|
|
149
|
-
bun install
|
|
150
|
-
|
|
151
|
-
# Run tests
|
|
152
|
-
bun run test
|
|
153
|
-
|
|
154
|
-
# Run tests in watch mode
|
|
155
|
-
bun run test:watch
|
|
156
|
-
|
|
157
|
-
# Run tests with coverage
|
|
158
|
-
bun run test:coverage
|
|
159
|
-
|
|
160
|
-
# Type check
|
|
161
|
-
bun run typecheck
|
|
162
|
-
|
|
163
|
-
# Build
|
|
164
|
-
bun run build
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
## Release Process
|
|
168
|
-
|
|
169
|
-
This project uses [Changesets](https://github.com/changesets/changesets) for automated versioning and publishing:
|
|
170
|
-
|
|
171
|
-
### Creating a Release
|
|
172
|
-
|
|
173
|
-
1. **Add a changeset** for your changes:
|
|
174
|
-
|
|
175
|
-
```bash
|
|
176
|
-
bun changeset
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
Follow the prompts to describe your changes (patch/minor/major).
|
|
180
|
-
|
|
181
|
-
2. **Commit the changeset**:
|
|
93
|
+
Priority order:
|
|
182
94
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
git push
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
3. **Automated Release PR**: The CI will automatically:
|
|
190
|
-
- Create or update a "Version Packages" PR
|
|
191
|
-
- Update `package.json` version
|
|
192
|
-
- Update `CHANGELOG.md`
|
|
193
|
-
|
|
194
|
-
4. **Publish**: When you merge the "Version Packages" PR:
|
|
195
|
-
- CI automatically publishes to npm using Bun
|
|
196
|
-
- Creates a git tag (e.g., `v1.15.0`)
|
|
197
|
-
- Creates a GitHub release with auto-generated notes
|
|
198
|
-
|
|
199
|
-
### Manual Publishing (if needed)
|
|
200
|
-
|
|
201
|
-
```bash
|
|
202
|
-
# Build and run all checks
|
|
203
|
-
bun run prepublishOnly
|
|
204
|
-
|
|
205
|
-
# Publish
|
|
206
|
-
bun publish --access public
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
## Releasing (CI/CD)
|
|
210
|
-
|
|
211
|
-
This repo uses **Changesets** to automate versioning, changelog updates, npm publishing, git tags, and GitHub Releases.
|
|
212
|
-
|
|
213
|
-
### For PR authors
|
|
214
|
-
|
|
215
|
-
Add a changeset for any user-facing change:
|
|
216
|
-
|
|
217
|
-
```bash
|
|
218
|
-
bun changeset
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
Commit the generated file in `.changeset/`.
|
|
222
|
-
|
|
223
|
-
### What happens on `main`
|
|
224
|
-
|
|
225
|
-
- When changesets land on `main`, CI opens/updates a **Version Packages** PR.
|
|
226
|
-
- When the **Version Packages** PR is merged, CI:
|
|
227
|
-
- updates `package.json` + `CHANGELOG.md`
|
|
228
|
-
- publishes to npm (with provenance)
|
|
229
|
-
- creates/pushes `vX.Y.Z` tag
|
|
230
|
-
- creates a GitHub Release
|
|
231
|
-
|
|
232
|
-
### Required GitHub repo secrets
|
|
233
|
-
|
|
234
|
-
- `NPM_TOKEN`: npm access token with permission to publish `prisma-effect-kysely`
|
|
235
|
-
|
|
236
|
-
## Architecture
|
|
237
|
-
|
|
238
|
-
### Type Safety
|
|
239
|
-
|
|
240
|
-
This generator uses **EXACT DMMF types** from Prisma and implements **zero type coercion**:
|
|
241
|
-
|
|
242
|
-
- Uses `FieldDefault` type matching Prisma's exact structure
|
|
243
|
-
- Type-safe validation with structural typing
|
|
244
|
-
- No `as` assertions or unsafe casts
|
|
245
|
-
- Complete TypeScript strict mode compliance
|
|
246
|
-
|
|
247
|
-
### Generated Code Quality
|
|
248
|
-
|
|
249
|
-
- **Alphabetically sorted** fields and models for consistency
|
|
250
|
-
- **Branded types** for UUIDs via `Schema.UUID`
|
|
251
|
-
- **Exact type inference** - no widening to `any` or `unknown`
|
|
252
|
-
- **Auto-generated headers** with timestamps and edit warnings
|
|
95
|
+
1. Native type: `@db.Uuid`
|
|
96
|
+
2. Documentation: `@db.Uuid` in field comment
|
|
97
|
+
3. Field name pattern: `id`, `*_id`, `*_uuid`, `uuid`
|
|
253
98
|
|
|
254
99
|
## Custom Type Overrides
|
|
255
100
|
|
|
256
|
-
Use `@customType`
|
|
101
|
+
Use `@customType` in field docs to override Effect Schema:
|
|
257
102
|
|
|
258
103
|
```prisma
|
|
259
104
|
model User {
|
|
260
105
|
/// @customType(Schema.String.pipe(Schema.email()))
|
|
261
106
|
email String @unique
|
|
262
|
-
|
|
263
107
|
/// @customType(Schema.Number.pipe(Schema.positive()))
|
|
264
108
|
age Int
|
|
265
|
-
|
|
266
|
-
/// @customType(Schema.String.pipe(Schema.brand('UserId')))
|
|
267
|
-
userId String
|
|
268
109
|
}
|
|
269
110
|
```
|
|
270
111
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
**Use cases**:
|
|
112
|
+
Supported on all Prisma scalar types.
|
|
274
113
|
|
|
275
|
-
|
|
276
|
-
- Number constraints (positive, range, etc.)
|
|
277
|
-
- Custom branded types
|
|
278
|
-
- Refined string patterns
|
|
114
|
+
## Implicit M2M Join Tables
|
|
279
115
|
|
|
280
|
-
|
|
116
|
+
Prisma columns `A`/`B` map to semantic snake_case fields via `Schema.fromKey`:
|
|
281
117
|
|
|
282
118
|
```typescript
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
119
|
+
export const ProductToProductTag = Schema.Struct({
|
|
120
|
+
product_id: Schema.propertySignature(
|
|
121
|
+
columnType(Schema.UUID, Schema.Never, Schema.Never)
|
|
122
|
+
).pipe(Schema.fromKey("A")),
|
|
123
|
+
product_tag_id: Schema.propertySignature(
|
|
124
|
+
columnType(Schema.UUID, Schema.Never, Schema.Never)
|
|
125
|
+
).pipe(Schema.fromKey("B")),
|
|
288
126
|
});
|
|
289
127
|
```
|
|
290
128
|
|
|
291
|
-
##
|
|
129
|
+
## Package Exports
|
|
292
130
|
|
|
293
|
-
|
|
131
|
+
| Entry | Contents |
|
|
132
|
+
| -------------------------------- | ----------------------------------------------------- |
|
|
133
|
+
| `prisma-effect-kysely` | Type utilities + runtime helpers (default import) |
|
|
134
|
+
| `prisma-effect-kysely/generator` | Prisma generator binary entry |
|
|
135
|
+
| `prisma-effect-kysely/kysely` | `getSchemas`, `columnType`, `generated`, type utils |
|
|
136
|
+
| `prisma-effect-kysely/error` | `NotFoundError`, `QueryError`, `QueryParseError`, ... |
|
|
137
|
+
| `prisma-effect-kysely/runtime` | All runtime utilities |
|
|
294
138
|
|
|
295
|
-
|
|
139
|
+
## Development
|
|
296
140
|
|
|
297
141
|
```bash
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
```prisma
|
|
304
|
-
generator effect_schemas {
|
|
305
|
-
provider = "node ./path/to/dist/generator.js"
|
|
306
|
-
output = "./generated/effect"
|
|
307
|
-
}
|
|
142
|
+
bun install
|
|
143
|
+
bun run test
|
|
144
|
+
bun run typecheck
|
|
145
|
+
bun run build
|
|
146
|
+
bun run prepublishOnly # lint + typecheck + test + build
|
|
308
147
|
```
|
|
309
148
|
|
|
310
|
-
|
|
149
|
+
## Releasing
|
|
311
150
|
|
|
312
|
-
|
|
151
|
+
Uses [Changesets](https://github.com/changesets/changesets).
|
|
313
152
|
|
|
153
|
+
```bash
|
|
154
|
+
bun changeset # add changeset
|
|
155
|
+
git add .changeset/ && git commit -m "docs: changeset"
|
|
156
|
+
git push
|
|
314
157
|
```
|
|
315
|
-
[Effect Generator] Starting generation...
|
|
316
|
-
[Effect Generator] Processing 15 models, 3 enums
|
|
317
|
-
[Effect Generator] ✓ Generated to ../../libs/types/storage/src/lib/effect
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
### UUID Not Detected
|
|
321
|
-
|
|
322
|
-
Add explicit `@db.Uuid` attribute:
|
|
323
158
|
|
|
324
|
-
|
|
325
|
-
userId String @db.Uuid
|
|
326
|
-
```
|
|
159
|
+
CI opens a "Version Packages" PR. Merging it publishes to npm, tags, and creates a GitHub release. Requires `NPM_TOKEN` repo secret.
|
|
327
160
|
|
|
328
161
|
## License
|
|
329
162
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-effect-kysely",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "Prisma generator that creates Effect Schema types from Prisma schema compatible with Kysely",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Samuel Ho",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
]
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"prettier": "^3.
|
|
87
|
+
"prettier": "^3.8.3"
|
|
88
88
|
},
|
|
89
89
|
"peerDependencies": {
|
|
90
90
|
"effect": "^3.19.14",
|
|
@@ -96,28 +96,28 @@
|
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
|
-
"@
|
|
100
|
-
"@changesets/
|
|
101
|
-
"@
|
|
102
|
-
"@
|
|
103
|
-
"@
|
|
104
|
-
"@prisma/internals": "^7.
|
|
105
|
-
"@types/node": "^25.0
|
|
106
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
107
|
-
"@typescript-eslint/parser": "^8.
|
|
108
|
-
"@vitest/coverage-v8": "^4.
|
|
109
|
-
"@vitest/eslint-plugin": "^1.
|
|
110
|
-
"effect": "^3.
|
|
111
|
-
"eslint": "^
|
|
99
|
+
"@changesets/changelog-github": "^0.6.0",
|
|
100
|
+
"@changesets/cli": "^2.31.0",
|
|
101
|
+
"@effect/vitest": "^0.29.0",
|
|
102
|
+
"@eslint/js": "^10.0.0",
|
|
103
|
+
"@prisma/generator-helper": "^7.8.0",
|
|
104
|
+
"@prisma/internals": "^7.8.0",
|
|
105
|
+
"@types/node": "^25.6.0",
|
|
106
|
+
"@typescript-eslint/eslint-plugin": "^8.59.1",
|
|
107
|
+
"@typescript-eslint/parser": "^8.59.1",
|
|
108
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
109
|
+
"@vitest/eslint-plugin": "^1.6.16",
|
|
110
|
+
"effect": "^3.21.2",
|
|
111
|
+
"eslint": "^10.0.0",
|
|
112
112
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
113
113
|
"eslint-plugin-import": "^2.32.0",
|
|
114
114
|
"husky": "^9.1.7",
|
|
115
|
-
"kysely": "^0.28.
|
|
116
|
-
"lint-staged": "^16.
|
|
117
|
-
"prisma": "^7.
|
|
115
|
+
"kysely": "^0.28.16",
|
|
116
|
+
"lint-staged": "^16.4.0",
|
|
117
|
+
"prisma": "^7.8.0",
|
|
118
118
|
"ts-node": "^10.9.2",
|
|
119
|
-
"typescript": "^
|
|
120
|
-
"typescript-eslint": "^8.
|
|
121
|
-
"vitest": "^4.
|
|
119
|
+
"typescript": "^6.0.0",
|
|
120
|
+
"typescript-eslint": "^8.59.1",
|
|
121
|
+
"vitest": "^4.1.5"
|
|
122
122
|
}
|
|
123
123
|
}
|