prisma-effect-kysely 4.7.0 → 5.0.1
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 +69 -0
- package/README.md +33 -36
- package/dist/effect/enum.d.ts +3 -5
- package/dist/effect/enum.d.ts.map +1 -1
- package/dist/effect/enum.js +11 -24
- package/dist/effect/enum.js.map +1 -1
- package/dist/effect/generator.d.ts +4 -30
- package/dist/effect/generator.d.ts.map +1 -1
- package/dist/effect/generator.js +27 -115
- package/dist/effect/generator.js.map +1 -1
- package/dist/effect/join-table.d.ts +8 -11
- package/dist/effect/join-table.d.ts.map +1 -1
- package/dist/effect/join-table.js +37 -57
- package/dist/effect/join-table.js.map +1 -1
- package/dist/effect/type.d.ts +0 -10
- package/dist/effect/type.d.ts.map +1 -1
- package/dist/effect/type.js +7 -29
- package/dist/effect/type.js.map +1 -1
- package/dist/generator/contract-scaffolder.js +1 -1
- package/dist/generator/domain-detector.d.ts +25 -2
- package/dist/generator/domain-detector.d.ts.map +1 -1
- package/dist/generator/domain-detector.js.map +1 -1
- package/dist/generator/index.d.ts +2 -2
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +8 -4
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/orchestrator.d.ts.map +1 -1
- package/dist/generator/orchestrator.js +7 -52
- package/dist/generator/orchestrator.js.map +1 -1
- package/dist/kysely/generator.d.ts +3 -22
- package/dist/kysely/generator.d.ts.map +1 -1
- package/dist/kysely/generator.js +5 -41
- package/dist/kysely/generator.js.map +1 -1
- package/dist/kysely/helpers.d.ts +99 -88
- package/dist/kysely/helpers.d.ts.map +1 -1
- package/dist/kysely/helpers.js +40 -23
- package/dist/kysely/helpers.js.map +1 -1
- package/dist/kysely/type.d.ts +12 -33
- package/dist/kysely/type.d.ts.map +1 -1
- package/dist/kysely/type.js +22 -111
- package/dist/kysely/type.js.map +1 -1
- package/dist/prisma/enum.d.ts +6 -1
- package/dist/prisma/enum.d.ts.map +1 -1
- package/dist/prisma/generator.d.ts +40 -5
- package/dist/prisma/generator.d.ts.map +1 -1
- package/dist/prisma/generator.js.map +1 -1
- package/dist/prisma/relation.d.ts +22 -1
- package/dist/prisma/relation.d.ts.map +1 -1
- package/dist/prisma/relation.js.map +1 -1
- package/dist/prisma/type.d.ts +66 -4
- package/dist/prisma/type.d.ts.map +1 -1
- package/dist/utils/naming.d.ts +0 -11
- package/dist/utils/naming.d.ts.map +1 -1
- package/dist/utils/naming.js +0 -13
- package/dist/utils/naming.js.map +1 -1
- package/dist/utils/type-mappings.d.ts +63 -0
- package/dist/utils/type-mappings.d.ts.map +1 -0
- package/dist/utils/type-mappings.js +71 -0
- package/dist/utils/type-mappings.js.map +1 -0
- package/package.json +15 -10
- package/CODE_OF_CONDUCT.md +0 -136
- package/CONTRIBUTING.md +0 -247
- package/SECURITY.md +0 -80
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6859405: Move `@prisma/generator-helper` from `dependencies` to `devDependencies`.
|
|
8
|
+
|
|
9
|
+
### Why
|
|
10
|
+
|
|
11
|
+
The `@prisma/generator-helper` package uses Node.js internals (`node:child_process`, `node:readline`) that are only needed by the generator code, not by runtime helpers.
|
|
12
|
+
|
|
13
|
+
### Impact
|
|
14
|
+
- **Generator code**: Still works - has access to `devDependencies` during `prisma generate`
|
|
15
|
+
- **Runtime helpers** (`columnType`, `generated`, `Selectable`, `Insertable`, `Updateable`): No changes - they're pure TypeScript/Effect-TS and don't depend on `@prisma/generator-helper`
|
|
16
|
+
- **Consumers**: Cleaner install when importing from `./kysely` or `./runtime` entry points - won't install unnecessary Node.js dependencies
|
|
17
|
+
|
|
18
|
+
### Technical Details
|
|
19
|
+
|
|
20
|
+
Most files only use type-only imports (`import type { DMMF } from '@prisma/generator-helper'`), which don't load the package at runtime. Only `src/generator/index.ts` uses the actual `generatorHandler` function, which is only invoked during `prisma generate`.
|
|
21
|
+
|
|
22
|
+
## 5.0.0
|
|
23
|
+
|
|
24
|
+
### Major Changes
|
|
25
|
+
|
|
26
|
+
- c3783df: ## v5.0 - Direct Exports API
|
|
27
|
+
|
|
28
|
+
This is a **breaking change** that simplifies the generated code structure and improves the developer experience.
|
|
29
|
+
|
|
30
|
+
### Breaking Changes
|
|
31
|
+
|
|
32
|
+
**Generated Code Structure**:
|
|
33
|
+
- Schemas are now exported directly: `export const User = Schema.Struct({...})`
|
|
34
|
+
- Branded ID types are exported directly: `export const UserId = Schema.UUID.pipe(Schema.brand("UserId"))`
|
|
35
|
+
- DB interface uses `Selectable<Model>` pattern: `User: Selectable<User>`
|
|
36
|
+
- No more `_Model` underscore prefix or `getSchemas()` wrapper in generated code
|
|
37
|
+
|
|
38
|
+
**Consumer API Changes**:
|
|
39
|
+
- Import branded IDs directly: `import { UserId } from "./generated"`
|
|
40
|
+
- Use type utilities for other types: `Selectable<typeof User>`, `Insertable<typeof User>`, `Updateable<typeof User>`
|
|
41
|
+
- The `Id<typeof User>` utility is no longer needed - import `UserId` directly
|
|
42
|
+
|
|
43
|
+
### Migration Guide
|
|
44
|
+
|
|
45
|
+
Before (v4.x):
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Selectable, Insertable, Updateable, Id } from 'prisma-effect-kysely';
|
|
49
|
+
import { User, DB } from './generated';
|
|
50
|
+
|
|
51
|
+
type UserId = Id<typeof User>;
|
|
52
|
+
type UserSelect = Selectable<typeof User>;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
After (v5.0):
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { Selectable, Insertable, Updateable } from 'prisma-effect-kysely';
|
|
59
|
+
import { User, UserId, DB } from './generated';
|
|
60
|
+
|
|
61
|
+
// UserId is now imported directly
|
|
62
|
+
type UserSelect = Selectable<typeof User>;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Improvements
|
|
66
|
+
- Simpler generated code structure
|
|
67
|
+
- Branded ID types are first-class exports
|
|
68
|
+
- Better alignment with Effect Schema patterns
|
|
69
|
+
- DB interface uses `Selectable<Model>` for clearer intent
|
|
70
|
+
- Join tables use semantic snake_case field names with `Schema.fromKey` mapping
|
|
71
|
+
|
|
3
72
|
## 4.6.0
|
|
4
73
|
|
|
5
74
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -13,11 +13,9 @@ A Prisma generator that creates Effect Schema types from Prisma schema definitio
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
|
|
17
|
-
# or
|
|
18
|
-
pnpm add prisma-effect-kysely
|
|
16
|
+
bun add prisma-effect-kysely
|
|
19
17
|
# or
|
|
20
|
-
|
|
18
|
+
npm install prisma-effect-kysely
|
|
21
19
|
```
|
|
22
20
|
|
|
23
21
|
## Usage
|
|
@@ -51,32 +49,27 @@ export const UserRoleSchema = Schema.Literal('admin', 'user', 'guest');
|
|
|
51
49
|
|
|
52
50
|
### types.ts
|
|
53
51
|
|
|
54
|
-
Effect Schema structs from Prisma models with Kysely integration:
|
|
52
|
+
Effect Schema structs from Prisma models with Kysely integration (v5.0 direct exports):
|
|
55
53
|
|
|
56
54
|
```typescript
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
import { Schema } from "effect";
|
|
56
|
+
import { columnType, generated, Selectable } from "prisma-effect-kysely";
|
|
57
|
+
|
|
58
|
+
// EXPORTED - Branded ID schema
|
|
59
|
+
export const UserId = Schema.UUID.pipe(Schema.brand("UserId"));
|
|
60
|
+
export type UserId = typeof UserId.Type;
|
|
63
61
|
|
|
64
|
-
//
|
|
65
|
-
const
|
|
62
|
+
// EXPORTED - Model schema (direct export)
|
|
63
|
+
export const User = Schema.Struct({
|
|
66
64
|
id: columnType(Schema.UUID, Schema.Never, Schema.Never),
|
|
67
65
|
email: Schema.String,
|
|
68
66
|
createdAt: generated(Schema.DateFromSelf),
|
|
69
67
|
});
|
|
68
|
+
export type User = typeof User;
|
|
70
69
|
|
|
71
|
-
//
|
|
72
|
-
const UserIdSchema = Schema.UUID.pipe(Schema.brand("UserId"));
|
|
73
|
-
|
|
74
|
-
// EXPORTED - Operational schemas with branded Id
|
|
75
|
-
export const User = getSchemas(_User, UserIdSchema);
|
|
76
|
-
|
|
77
|
-
// EXPORTED - Kysely DB interface
|
|
70
|
+
// EXPORTED - Kysely DB interface with Selectable<Model>
|
|
78
71
|
export interface DB {
|
|
79
|
-
User:
|
|
72
|
+
User: Selectable<User>;
|
|
80
73
|
}
|
|
81
74
|
```
|
|
82
75
|
|
|
@@ -84,19 +77,21 @@ export interface DB {
|
|
|
84
77
|
|
|
85
78
|
Re-exports all generated types for easy importing
|
|
86
79
|
|
|
87
|
-
## Consumer Usage (
|
|
80
|
+
## Consumer Usage (v5.0)
|
|
88
81
|
|
|
89
|
-
Use type utilities from `prisma-effect-kysely`
|
|
82
|
+
Branded ID types are exported directly. Use type utilities from `prisma-effect-kysely` for other types:
|
|
90
83
|
|
|
91
84
|
```typescript
|
|
92
|
-
import { Selectable, Insertable, Updateable
|
|
93
|
-
import { User, DB } from "./generated";
|
|
85
|
+
import { Selectable, Insertable, Updateable } from "prisma-effect-kysely";
|
|
86
|
+
import { User, UserId, DB } from "./generated";
|
|
87
|
+
|
|
88
|
+
// Branded ID type - direct import (no utility needed)
|
|
89
|
+
function getUser(id: UserId): Promise<User> { ... }
|
|
94
90
|
|
|
95
91
|
// Extract types using utilities (Kysely-native pattern)
|
|
96
92
|
type UserSelect = Selectable<typeof User>;
|
|
97
93
|
type UserInsert = Insertable<typeof User>;
|
|
98
94
|
type UserUpdate = Updateable<typeof User>;
|
|
99
|
-
type UserId = Id<typeof User>;
|
|
100
95
|
|
|
101
96
|
// Use with Kysely
|
|
102
97
|
import { Kysely } from 'kysely';
|
|
@@ -147,24 +142,26 @@ model User {
|
|
|
147
142
|
|
|
148
143
|
## Development
|
|
149
144
|
|
|
145
|
+
This project uses **Bun** as the sole package manager.
|
|
146
|
+
|
|
150
147
|
```bash
|
|
151
148
|
# Install dependencies
|
|
152
|
-
|
|
149
|
+
bun install
|
|
153
150
|
|
|
154
151
|
# Run tests
|
|
155
|
-
|
|
152
|
+
bun run test
|
|
156
153
|
|
|
157
154
|
# Run tests in watch mode
|
|
158
|
-
|
|
155
|
+
bun run test:watch
|
|
159
156
|
|
|
160
157
|
# Run tests with coverage
|
|
161
|
-
|
|
158
|
+
bun run test:coverage
|
|
162
159
|
|
|
163
160
|
# Type check
|
|
164
|
-
|
|
161
|
+
bun run typecheck
|
|
165
162
|
|
|
166
163
|
# Build
|
|
167
|
-
|
|
164
|
+
bun run build
|
|
168
165
|
```
|
|
169
166
|
|
|
170
167
|
## Release Process
|
|
@@ -176,7 +173,7 @@ This project uses [Changesets](https://github.com/changesets/changesets) for aut
|
|
|
176
173
|
1. **Add a changeset** for your changes:
|
|
177
174
|
|
|
178
175
|
```bash
|
|
179
|
-
|
|
176
|
+
bun changeset
|
|
180
177
|
```
|
|
181
178
|
|
|
182
179
|
Follow the prompts to describe your changes (patch/minor/major).
|
|
@@ -203,9 +200,9 @@ This project uses [Changesets](https://github.com/changesets/changesets) for aut
|
|
|
203
200
|
|
|
204
201
|
```bash
|
|
205
202
|
# Build and run all checks
|
|
206
|
-
|
|
203
|
+
bun run prepublishOnly
|
|
207
204
|
|
|
208
|
-
# Publish
|
|
205
|
+
# Publish
|
|
209
206
|
bun publish --access public
|
|
210
207
|
```
|
|
211
208
|
|
|
@@ -218,7 +215,7 @@ This repo uses **Changesets** to automate versioning, changelog updates, npm pub
|
|
|
218
215
|
Add a changeset for any user-facing change:
|
|
219
216
|
|
|
220
217
|
```bash
|
|
221
|
-
|
|
218
|
+
bun changeset
|
|
222
219
|
```
|
|
223
220
|
|
|
224
221
|
Commit the generated file in `.changeset/`.
|
package/dist/effect/enum.d.ts
CHANGED
|
@@ -2,12 +2,10 @@ import type { DMMF } from '@prisma/generator-helper';
|
|
|
2
2
|
/**
|
|
3
3
|
* Generate TypeScript enum + Effect Schema.Enums wrapper
|
|
4
4
|
*
|
|
5
|
-
* TDD: Satisfies tests 1-6 in enum-generation.test.ts
|
|
6
|
-
*
|
|
7
5
|
* Output pattern:
|
|
8
|
-
* - Native TS enum with
|
|
9
|
-
* -
|
|
10
|
-
* - Type alias
|
|
6
|
+
* - Native TS enum with SCREAMING_SNAKE_CASE (internal, for Schema.Enums)
|
|
7
|
+
* - PascalCase export IS the Schema (so it works in Schema.Struct)
|
|
8
|
+
* - Type alias with same name (value + type pattern)
|
|
11
9
|
*/
|
|
12
10
|
export declare function generateEnumSchema(enumDef: DMMF.DatamodelEnum): string;
|
|
13
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/effect/enum.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAKrD
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/effect/enum.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAKrD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,UAuB7D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC,aAAa,EAAE,UAMrE"}
|
package/dist/effect/enum.js
CHANGED
|
@@ -4,45 +4,32 @@ import { toPascalCase } from '../utils/naming.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Generate TypeScript enum + Effect Schema.Enums wrapper
|
|
6
6
|
*
|
|
7
|
-
* TDD: Satisfies tests 1-6 in enum-generation.test.ts
|
|
8
|
-
*
|
|
9
7
|
* Output pattern:
|
|
10
|
-
* - Native TS enum with
|
|
11
|
-
* -
|
|
12
|
-
* - Type alias
|
|
8
|
+
* - Native TS enum with SCREAMING_SNAKE_CASE (internal, for Schema.Enums)
|
|
9
|
+
* - PascalCase export IS the Schema (so it works in Schema.Struct)
|
|
10
|
+
* - Type alias with same name (value + type pattern)
|
|
13
11
|
*/
|
|
14
12
|
export function generateEnumSchema(enumDef) {
|
|
15
|
-
//
|
|
13
|
+
// Raw enum keeps original name (usually SCREAMING_SNAKE_CASE)
|
|
16
14
|
const enumName = enumDef.name;
|
|
17
|
-
//
|
|
15
|
+
// PascalCase name is exported as BOTH the Schema value AND the type
|
|
18
16
|
const pascalName = toPascalCase(enumDef.name);
|
|
19
|
-
|
|
20
|
-
const typeName = `${pascalName}Type`;
|
|
21
|
-
// Generate native TypeScript enum members (Tests 1-2)
|
|
17
|
+
// Generate native TypeScript enum members
|
|
22
18
|
const enumMembers = enumDef.values
|
|
23
19
|
.map((v) => {
|
|
24
20
|
const value = getEnumValueDbName(v);
|
|
25
21
|
return ` ${v.name} = "${value}"`;
|
|
26
22
|
})
|
|
27
23
|
.join(',\n');
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
// Also generate PascalCase aliases for better ergonomics if name is different
|
|
32
|
-
const aliases = pascalName !== enumName
|
|
33
|
-
? `
|
|
34
|
-
|
|
35
|
-
// PascalCase aliases for better ergonomics
|
|
36
|
-
export const ${pascalName} = ${enumName};
|
|
37
|
-
export type ${pascalName} = ${typeName};`
|
|
38
|
-
: '';
|
|
24
|
+
// Export PascalCase as the Schema (not raw enum)
|
|
25
|
+
// This allows PayoutStatus to be used directly in Schema.Struct fields
|
|
26
|
+
// Also export type with same name for Insertable<User> pattern
|
|
39
27
|
return `export enum ${enumName} {
|
|
40
28
|
${enumMembers}
|
|
41
29
|
}
|
|
42
30
|
|
|
43
|
-
export const ${
|
|
44
|
-
|
|
45
|
-
export type ${typeName} = Schema.Schema.Type<typeof ${schemaName}>;${aliases}`;
|
|
31
|
+
export const ${pascalName} = Schema.Enums(${enumName});
|
|
32
|
+
export type ${pascalName} = Schema.Schema.Type<typeof ${pascalName}>;`;
|
|
46
33
|
}
|
|
47
34
|
/**
|
|
48
35
|
* Generate all enum schemas as a single file content
|
package/dist/effect/enum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/effect/enum.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/effect/enum.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA2B;IAC5D,8DAA8D;IAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAC9B,oEAAoE;IACpE,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C,0CAA0C;IAC1C,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM;SAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,KAAK,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;QACpC,OAAO,KAAK,CAAC,CAAC,IAAI,OAAO,KAAK,GAAG,CAAC;IACpC,CAAC,CAAC;SACD,IAAI,CAAC,KAAK,CAAC,CAAC;IAEf,iDAAiD;IACjD,uEAAuE;IACvE,+DAA+D;IAC/D,OAAO,eAAe,QAAQ;EAC9B,WAAW;;;eAGE,UAAU,mBAAmB,QAAQ;cACtC,UAAU,gCAAgC,UAAU,IAAI,CAAC;AACvE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAoC;IACpE,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,kCAAkC,CAAC;IACnD,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE/D,OAAO,GAAG,MAAM,OAAO,OAAO,OAAO,WAAW,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -10,50 +10,24 @@ export declare class EffectGenerator {
|
|
|
10
10
|
* Generate enums.ts file content
|
|
11
11
|
*/
|
|
12
12
|
generateEnums(enums: readonly DMMF.DatamodelEnum[]): string;
|
|
13
|
-
/**
|
|
14
|
-
* Generate base schema for a model (_ModelName)
|
|
15
|
-
* EXPORTED to allow TypeScript to reference by name in declaration emit
|
|
16
|
-
* (prevents type expansion that breaks SchemasWithId type params)
|
|
17
|
-
*/
|
|
18
|
-
generateBaseSchema(model: DMMF.Model, fields: readonly DMMF.Field[]): string;
|
|
19
13
|
/**
|
|
20
14
|
* Generate branded ID schema for a model
|
|
21
15
|
* @returns The branded ID schema declaration + exported type, or null if no ID field
|
|
22
16
|
*/
|
|
23
17
|
generateBrandedIdSchema(model: DMMF.Model, fields: readonly DMMF.Field[]): string | null;
|
|
24
18
|
/**
|
|
25
|
-
* Generate
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* This is the key fix for declaration emit issues:
|
|
30
|
-
* - The base schema uses generated()/columnType() wrappers which get simplified in .d.ts
|
|
31
|
-
* - This explicit schema has no wrappers, so TypeScript preserves the exact types
|
|
32
|
-
*/
|
|
33
|
-
generateInsertableSchema(model: DMMF.Model, fields: readonly DMMF.Field[]): string;
|
|
34
|
-
/**
|
|
35
|
-
* Generate operational schemas with branded Id
|
|
36
|
-
* Uses explicit Insertable schema instead of computed one to survive declaration emit
|
|
19
|
+
* Generate the main model schema
|
|
20
|
+
* Exports as `User` directly (not `_User`)
|
|
21
|
+
* Package's type utilities derive Insertable<User>, Selectable<User>
|
|
37
22
|
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Generate complete model schema (base + branded ID + insertable + operational)
|
|
41
|
-
* No type exports - consumers use type utilities: Selectable<typeof User>
|
|
42
|
-
*/
|
|
43
|
-
generateModelSchema(model: DMMF.Model, fields: DMMF.Field[]): string;
|
|
23
|
+
generateModelSchema(model: DMMF.Model, fields: readonly DMMF.Field[]): string;
|
|
44
24
|
/**
|
|
45
25
|
* Generate types.ts file header
|
|
46
|
-
*
|
|
47
|
-
* TDD: Satisfies tests 13-15 in import-generation.test.ts
|
|
48
26
|
*/
|
|
49
27
|
generateTypesHeader(hasEnums: boolean): string;
|
|
50
28
|
/**
|
|
51
29
|
* Generate schemas for all join tables
|
|
52
30
|
*/
|
|
53
31
|
generateJoinTableSchemas(joinTables: JoinTableInfo[]): string;
|
|
54
|
-
/**
|
|
55
|
-
* Generate Kysely table interfaces for join tables
|
|
56
|
-
*/
|
|
57
|
-
generateJoinTableKyselyInterfaces(joinTables: JoinTableInfo[]): string;
|
|
58
32
|
}
|
|
59
33
|
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/effect/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/effect/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAQ/E;;GAEG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,IAAI,CAAC,QAAQ;IAEhD;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC,aAAa,EAAE;IAIlD;;;OAGG;IACH,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,IAAI,CAAC,KAAK,EAAE;IAexE;;;;OAIG;IACH,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,IAAI,CAAC,KAAK,EAAE;IAqBpE;;OAEG;IACH,mBAAmB,CAAC,QAAQ,EAAE,OAAO;IAoBrC;;OAEG;IACH,wBAAwB,CAAC,UAAU,EAAE,aAAa,EAAE;CAGrD"}
|
package/dist/effect/generator.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
+
import { buildKyselyFieldType } from '../kysely/type.js';
|
|
1
2
|
import { buildForeignKeyMap } from '../prisma/relation.js';
|
|
2
|
-
import {
|
|
3
|
+
import { isUuidField } from '../prisma/type.js';
|
|
3
4
|
import { generateFileHeader } from '../utils/codegen.js';
|
|
4
5
|
import { toPascalCase } from '../utils/naming.js';
|
|
5
6
|
import { generateEnumsFile } from './enum.js';
|
|
6
|
-
import {
|
|
7
|
-
import { buildFieldType
|
|
8
|
-
/**
|
|
9
|
-
* Determine if field should be omitted from explicit Insertable schema
|
|
10
|
-
* ID fields with @default and non-ID fields with @default are omitted
|
|
11
|
-
*/
|
|
12
|
-
function needsOmitFromInsert(field) {
|
|
13
|
-
return hasDefaultValue(field);
|
|
14
|
-
}
|
|
7
|
+
import { generateJoinTableSchema } from './join-table.js';
|
|
8
|
+
import { buildFieldType } from './type.js';
|
|
15
9
|
/**
|
|
16
10
|
* Effect domain generator - orchestrates Effect Schema generation
|
|
17
11
|
*/
|
|
@@ -26,27 +20,6 @@ export class EffectGenerator {
|
|
|
26
20
|
generateEnums(enums) {
|
|
27
21
|
return generateEnumsFile(enums);
|
|
28
22
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Generate base schema for a model (_ModelName)
|
|
31
|
-
* EXPORTED to allow TypeScript to reference by name in declaration emit
|
|
32
|
-
* (prevents type expansion that breaks SchemasWithId type params)
|
|
33
|
-
*/
|
|
34
|
-
generateBaseSchema(model, fields) {
|
|
35
|
-
// Build FK map to determine which fields should use branded FK types
|
|
36
|
-
// Only includes FKs that reference the target model's ID field
|
|
37
|
-
const fkMap = buildForeignKeyMap(model, this.dmmf.datamodel.models);
|
|
38
|
-
const fieldDefinitions = fields
|
|
39
|
-
.map((field) => {
|
|
40
|
-
const fieldType = buildFieldType(field, this.dmmf, fkMap);
|
|
41
|
-
return ` ${field.name}: ${fieldType}`;
|
|
42
|
-
})
|
|
43
|
-
.join(',\n');
|
|
44
|
-
const baseSchemaName = `_${model.name}`;
|
|
45
|
-
return `// ${model.name} Base Schema (exported for TypeScript declaration emit)
|
|
46
|
-
export const ${baseSchemaName} = Schema.Struct({
|
|
47
|
-
${fieldDefinitions}
|
|
48
|
-
});`;
|
|
49
|
-
}
|
|
50
23
|
/**
|
|
51
24
|
* Generate branded ID schema for a model
|
|
52
25
|
* @returns The branded ID schema declaration + exported type, or null if no ID field
|
|
@@ -59,103 +32,48 @@ ${fieldDefinitions}
|
|
|
59
32
|
const name = toPascalCase(model.name);
|
|
60
33
|
const isUuid = isUuidField(idField);
|
|
61
34
|
const baseType = isUuid ? 'Schema.UUID' : 'Schema.String';
|
|
62
|
-
// Export
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export type ${name}Id = typeof ${name}IdSchema.Type;`;
|
|
35
|
+
// Export Id as both value and type with same name
|
|
36
|
+
return `export const ${name}Id = ${baseType}.pipe(Schema.brand("${name}Id"));
|
|
37
|
+
export type ${name}Id = typeof ${name}Id.Type;`;
|
|
66
38
|
}
|
|
67
39
|
/**
|
|
68
|
-
* Generate
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* This is the key fix for declaration emit issues:
|
|
73
|
-
* - The base schema uses generated()/columnType() wrappers which get simplified in .d.ts
|
|
74
|
-
* - This explicit schema has no wrappers, so TypeScript preserves the exact types
|
|
40
|
+
* Generate the main model schema
|
|
41
|
+
* Exports as `User` directly (not `_User`)
|
|
42
|
+
* Package's type utilities derive Insertable<User>, Selectable<User>
|
|
75
43
|
*/
|
|
76
|
-
|
|
44
|
+
generateModelSchema(model, fields) {
|
|
77
45
|
const fkMap = buildForeignKeyMap(model, this.dmmf.datamodel.models);
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
const fieldDefinitions = insertableFields
|
|
46
|
+
const name = toPascalCase(model.name);
|
|
47
|
+
const fieldDefinitions = fields
|
|
81
48
|
.map((field) => {
|
|
82
|
-
|
|
49
|
+
// Get base Effect type
|
|
50
|
+
const baseType = buildFieldType(field, this.dmmf, fkMap);
|
|
51
|
+
// Apply Kysely helpers (columnType, generated) and @map directive
|
|
52
|
+
// Pass model.name so @id fields use the model's branded ID type
|
|
53
|
+
const fieldType = buildKyselyFieldType(baseType, field, model.name);
|
|
83
54
|
return ` ${field.name}: ${fieldType}`;
|
|
84
55
|
})
|
|
85
56
|
.join(',\n');
|
|
86
|
-
|
|
87
|
-
return `// ${model.name} Insertable Schema (explicit - avoids declaration emit issues)
|
|
88
|
-
export const ${insertableSchemaName} = Schema.Struct({
|
|
57
|
+
return `export const ${name} = Schema.Struct({
|
|
89
58
|
${fieldDefinitions}
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Generate operational schemas with branded Id
|
|
94
|
-
* Uses explicit Insertable schema instead of computed one to survive declaration emit
|
|
95
|
-
*/
|
|
96
|
-
generateOperationalSchemas(model, fields) {
|
|
97
|
-
const baseSchemaName = `_${model.name}`;
|
|
98
|
-
const insertableSchemaName = `_${model.name}_insertable`;
|
|
99
|
-
const name = toPascalCase(model.name);
|
|
100
|
-
const idField = fields.find((f) => f.isId);
|
|
101
|
-
if (idField) {
|
|
102
|
-
// Model with ID field - override Insertable with explicit schema
|
|
103
|
-
return `// Operational schemas for ${name}
|
|
104
|
-
export const ${name} = {
|
|
105
|
-
...getSchemas(${baseSchemaName}, ${name}IdSchema),
|
|
106
|
-
Insertable: ${insertableSchemaName},
|
|
107
|
-
};`;
|
|
108
|
-
}
|
|
109
|
-
// Model without ID field - override Insertable with explicit schema
|
|
110
|
-
return `// Operational schemas for ${name}
|
|
111
|
-
export const ${name} = {
|
|
112
|
-
...getSchemas(${baseSchemaName}),
|
|
113
|
-
Insertable: ${insertableSchemaName},
|
|
114
|
-
};`;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Generate complete model schema (base + branded ID + insertable + operational)
|
|
118
|
-
* No type exports - consumers use type utilities: Selectable<typeof User>
|
|
119
|
-
*/
|
|
120
|
-
generateModelSchema(model, fields) {
|
|
121
|
-
const parts = [];
|
|
122
|
-
// Branded ID schema (if model has ID field)
|
|
123
|
-
const brandedIdSchema = this.generateBrandedIdSchema(model, fields);
|
|
124
|
-
if (brandedIdSchema) {
|
|
125
|
-
parts.push(brandedIdSchema);
|
|
126
|
-
}
|
|
127
|
-
// Base schema (with generated()/columnType() wrappers)
|
|
128
|
-
parts.push(this.generateBaseSchema(model, fields));
|
|
129
|
-
// Explicit Insertable schema (without wrappers - survives declaration emit)
|
|
130
|
-
parts.push(this.generateInsertableSchema(model, fields));
|
|
131
|
-
// Operational schemas with Id (uses explicit Insertable)
|
|
132
|
-
parts.push(this.generateOperationalSchemas(model, fields));
|
|
133
|
-
return parts.join('\n\n');
|
|
59
|
+
});
|
|
60
|
+
export type ${name} = typeof ${name};`;
|
|
134
61
|
}
|
|
135
62
|
/**
|
|
136
63
|
* Generate types.ts file header
|
|
137
|
-
*
|
|
138
|
-
* TDD: Satisfies tests 13-15 in import-generation.test.ts
|
|
139
64
|
*/
|
|
140
65
|
generateTypesHeader(hasEnums) {
|
|
141
66
|
const header = generateFileHeader();
|
|
142
|
-
// Import
|
|
67
|
+
// Import runtime helpers from prisma-effect-kysely
|
|
68
|
+
// Selectable is used for DB interface: Selectable<Model>
|
|
143
69
|
const imports = [
|
|
144
70
|
`import { Schema } from "effect";`,
|
|
145
|
-
`import
|
|
146
|
-
`import { columnType, generated, getSchemas } from "prisma-effect-kysely";`,
|
|
71
|
+
`import { columnType, generated, Selectable } from "prisma-effect-kysely";`,
|
|
147
72
|
];
|
|
148
73
|
if (hasEnums) {
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const enumImports = this.dmmf.datamodel.enums
|
|
153
|
-
.map((e) => {
|
|
154
|
-
const baseName = toPascalCase(e.name);
|
|
155
|
-
return `${baseName}Schema`;
|
|
156
|
-
})
|
|
157
|
-
.join(', ');
|
|
158
|
-
imports.push(`import { ${enumImports} } from "./enums.js";`);
|
|
74
|
+
// Import PascalCase enum schemas
|
|
75
|
+
const enumImports = this.dmmf.datamodel.enums.map((e) => toPascalCase(e.name)).join(', ');
|
|
76
|
+
imports.push(`import { ${enumImports} } from "./enums";`);
|
|
159
77
|
}
|
|
160
78
|
return `${header}\n\n${imports.join('\n')}`;
|
|
161
79
|
}
|
|
@@ -165,11 +83,5 @@ export const ${name} = {
|
|
|
165
83
|
generateJoinTableSchemas(joinTables) {
|
|
166
84
|
return joinTables.map((jt) => generateJoinTableSchema(jt, this.dmmf)).join('\n\n');
|
|
167
85
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Generate Kysely table interfaces for join tables
|
|
170
|
-
*/
|
|
171
|
-
generateJoinTableKyselyInterfaces(joinTables) {
|
|
172
|
-
return joinTables.map(generateJoinTableKyselyInterface).join('\n\n');
|
|
173
|
-
}
|
|
174
86
|
}
|
|
175
87
|
//# sourceMappingURL=generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/effect/generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAsB,MAAM,uBAAuB,CA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WAAW,oBAAoB,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,GAAG,MAAM,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,wBAAwB,CAAC,UAA2B;QAClD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,uBAAuB,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrF,CAAC;CACF"}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import type { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
import type { JoinTableInfo } from '../prisma/relation.js';
|
|
3
|
-
/**
|
|
4
|
-
* Generate Kysely table interface for a join table
|
|
5
|
-
*/
|
|
6
|
-
export declare function generateJoinTableKyselyInterface(joinTable: JoinTableInfo): string;
|
|
7
3
|
/**
|
|
8
4
|
* Generate Effect Schema for an implicit many-to-many join table
|
|
9
5
|
*
|
|
10
6
|
* Structure:
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
13
|
-
* -
|
|
7
|
+
* - Direct export with semantic snake_case field names
|
|
8
|
+
* - Maps TypeScript names to database A/B columns using Schema.fromKey
|
|
9
|
+
* - Uses columnType for read-only foreign keys (can't insert/update join table rows directly)
|
|
10
|
+
* - No type exports - consumers use type utilities: Selectable<JoinTable>
|
|
14
11
|
*
|
|
15
12
|
* Example:
|
|
16
|
-
* - Database columns: A, B (Prisma requirement)
|
|
17
|
-
* - TypeScript fields: product_id, product_tag_id (semantic
|
|
18
|
-
* -
|
|
13
|
+
* - Database columns: A, B (Prisma requirement for implicit many-to-many)
|
|
14
|
+
* - TypeScript fields: product_id, product_tag_id (semantic names)
|
|
15
|
+
* - Types: columnType(Schema.UUID, Schema.Never, Schema.Never) (read-only)
|
|
19
16
|
*/
|
|
20
|
-
export declare function generateJoinTableSchema(joinTable: JoinTableInfo,
|
|
17
|
+
export declare function generateJoinTableSchema(joinTable: JoinTableInfo, dmmf: DMMF.Document): string;
|
|
21
18
|
//# sourceMappingURL=join-table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"join-table.d.ts","sourceRoot":"","sources":["../../src/effect/join-table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"join-table.d.ts","sourceRoot":"","sources":["../../src/effect/join-table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAI3D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,UA0CpF"}
|