prisma-effect-kysely 1.1.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +21 -0
  3. package/README.md +219 -0
  4. package/dist/effect/enum.d.ts +10 -0
  5. package/dist/effect/enum.d.ts.map +1 -0
  6. package/dist/effect/enum.js +33 -0
  7. package/dist/effect/enum.js.map +1 -0
  8. package/dist/effect/generator.d.ts +33 -0
  9. package/dist/effect/generator.d.ts.map +1 -0
  10. package/dist/effect/generator.js +81 -0
  11. package/dist/effect/generator.js.map +1 -0
  12. package/dist/effect/type.d.ts +11 -0
  13. package/dist/effect/type.d.ts.map +1 -0
  14. package/dist/effect/type.js +64 -0
  15. package/dist/effect/type.js.map +1 -0
  16. package/dist/generator/index.d.ts +4 -0
  17. package/dist/generator/index.d.ts.map +1 -0
  18. package/dist/generator/index.js +34 -0
  19. package/dist/generator/index.js.map +1 -0
  20. package/dist/generator/orchestrator.d.ts +42 -0
  21. package/dist/generator/orchestrator.d.ts.map +1 -0
  22. package/dist/generator/orchestrator.js +111 -0
  23. package/dist/generator/orchestrator.js.map +1 -0
  24. package/dist/kysely/generator.d.ts +26 -0
  25. package/dist/kysely/generator.d.ts.map +1 -0
  26. package/dist/kysely/generator.js +44 -0
  27. package/dist/kysely/generator.js.map +1 -0
  28. package/dist/kysely/helpers.d.ts +50 -0
  29. package/dist/kysely/helpers.d.ts.map +1 -0
  30. package/dist/kysely/helpers.js +144 -0
  31. package/dist/kysely/helpers.js.map +1 -0
  32. package/dist/kysely/type.d.ts +33 -0
  33. package/dist/kysely/type.d.ts.map +1 -0
  34. package/dist/kysely/type.js +78 -0
  35. package/dist/kysely/type.js.map +1 -0
  36. package/dist/prisma/enum.d.ts +15 -0
  37. package/dist/prisma/enum.d.ts.map +1 -0
  38. package/dist/prisma/enum.js +25 -0
  39. package/dist/prisma/enum.js.map +1 -0
  40. package/dist/prisma/generator.d.ts +22 -0
  41. package/dist/prisma/generator.d.ts.map +1 -0
  42. package/dist/prisma/generator.js +69 -0
  43. package/dist/prisma/generator.js.map +1 -0
  44. package/dist/prisma/type.d.ts +47 -0
  45. package/dist/prisma/type.d.ts.map +1 -0
  46. package/dist/prisma/type.js +96 -0
  47. package/dist/prisma/type.js.map +1 -0
  48. package/dist/utils/annotations.d.ts +33 -0
  49. package/dist/utils/annotations.d.ts.map +1 -0
  50. package/dist/utils/annotations.js +86 -0
  51. package/dist/utils/annotations.js.map +1 -0
  52. package/dist/utils/file-manager.d.ts +20 -0
  53. package/dist/utils/file-manager.d.ts.map +1 -0
  54. package/dist/utils/file-manager.js +36 -0
  55. package/dist/utils/file-manager.js.map +1 -0
  56. package/dist/utils/templates.d.ts +2 -0
  57. package/dist/utils/templates.d.ts.map +1 -0
  58. package/dist/utils/templates.js +55 -0
  59. package/dist/utils/templates.js.map +1 -0
  60. package/package.json +82 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.2] - 2025-10-03
9
+
10
+ ### Note
11
+ **Temporary release due to npm 24-hour republish restriction.**
12
+ This version will be unpublished and superseded by v1.0.0 within 24 hours.
13
+
14
+ ### Fixed
15
+ - Export configuration to allow importing runtime helpers from main package entry point
16
+ - Clean dependency tree with minimal deprecation warnings
17
+
18
+ ## [1.0.0] - 2025-10-02
19
+
20
+ ### Added
21
+
22
+ - Initial release of Prisma Effect Schema Generator
23
+ - Type-safe generation of Effect Schema types from Prisma models
24
+ - Intelligent UUID detection with 4-tier strategy:
25
+ - Native type detection via `@db.Uuid`
26
+ - Documentation-based detection
27
+ - Default value pattern matching
28
+ - Field name pattern matching
29
+ - Complete Prisma type mappings to Effect Schema equivalents
30
+ - Support for Prisma enums with `@map` annotations
31
+ - Deterministic output with alphabetical sorting
32
+ - Zero type coercion with exact DMMF types
33
+ - Automated file generation (enums.ts, types.ts, index.ts)
34
+ - Comprehensive test suite with 100% coverage paths
35
+ - TypeScript strict mode compliance
36
+ - Prettier code formatting
37
+
38
+ ### Features
39
+
40
+ - ✅ All Prisma scalar types supported (String, Int, Float, BigInt, Decimal, Boolean, DateTime, Json, Bytes)
41
+ - ✅ Array and optional field support
42
+ - ✅ Relation field exclusion (only scalar and enum fields included)
43
+ - ✅ Internal model filtering (models starting with `_`)
44
+ - ✅ DBSchema interface generation for type-safe database operations
45
+
46
+ [1.0.0]: https://github.com/samuelho-dev/prisma-effect-kysely/releases/tag/v1.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Samuel Ho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,219 @@
1
+ # Prisma Effect Generator
2
+
3
+ A Prisma generator that creates Effect Schema types from Prisma schema definitions with exact type safety and intelligent UUID detection.
4
+
5
+ ## Features
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
14
+
15
+ ```bash
16
+ npm install prisma-effect-kysely
17
+ # or
18
+ pnpm add prisma-effect-kysely
19
+ # or
20
+ yarn add prisma-effect-kysely
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### 1. Add to schema.prisma
26
+
27
+ ```prisma
28
+ generator effect_schemas {
29
+ provider = "prisma-effect-kysely"
30
+ output = "./generated/effect"
31
+ }
32
+ ```
33
+
34
+ ### 2. Generate Effect Schemas
35
+
36
+ ```bash
37
+ npx prisma generate
38
+ ```
39
+
40
+ ## Output
41
+
42
+ Generates three files in the configured output directory:
43
+
44
+ ### enums.ts
45
+
46
+ Effect Schema enums from Prisma enums with exact literal types:
47
+
48
+ ```typescript
49
+ export const UserRole = Schema.Literal('admin', 'user', 'guest');
50
+ export type UserRole = Schema.Schema.Type<typeof UserRole>;
51
+ ```
52
+
53
+ ### types.ts
54
+
55
+ Effect Schema structs from Prisma models:
56
+
57
+ ```typescript
58
+ export const User = Schema.Struct({
59
+ id: Schema.UUID,
60
+ email: Schema.String,
61
+ name: Schema.optional(Schema.String),
62
+ role: UserRole,
63
+ createdAt: Schema.Date,
64
+ });
65
+ export type User = Schema.Schema.Type<typeof User>;
66
+ ```
67
+
68
+ ### index.ts
69
+
70
+ Re-exports all generated types for easy importing
71
+
72
+ ## Type Mappings
73
+
74
+ | Prisma Type | Effect Schema Type | Notes |
75
+ | ----------- | ------------------- | -------------------------------- |
76
+ | String | `Schema.String` | `Schema.UUID` for id fields |
77
+ | Int / Float | `Schema.Number` | With `Schema.int()` for integers |
78
+ | BigInt | `Schema.BigInt` | Exact bigint type |
79
+ | Decimal | `Schema.String` | String for precision |
80
+ | Boolean | `Schema.Boolean` | - |
81
+ | DateTime | `Schema.Date` | - |
82
+ | Json | `Schema.Unknown` | Safe unknown type |
83
+ | Bytes | `Schema.Uint8Array` | - |
84
+ | Enum | Enum Schema | With `Schema.Literal` values |
85
+
86
+ ## UUID Detection
87
+
88
+ The generator intelligently detects UUID fields through multiple strategies (in order):
89
+
90
+ 1. **Native Type**: `@db.Uuid` attribute (most reliable)
91
+ 2. **Documentation**: `@db.Uuid` in field comments
92
+ 3. **Default Value**: `dbgenerated("gen_random_uuid()")` or similar
93
+ 4. **Field Name Patterns**: `id`, `*_id`, `*_uuid`, `uuid`
94
+
95
+ Example:
96
+
97
+ ```prisma
98
+ model User {
99
+ id String @id @db.Uuid @default(dbgenerated("gen_random_uuid()"))
100
+ userId String @db.Uuid // Detected via native type
101
+ productId String // Detected via field name pattern
102
+ }
103
+ ```
104
+
105
+ ## Development
106
+
107
+ ```bash
108
+ # Install dependencies
109
+ npm install
110
+
111
+ # Run tests
112
+ npm test
113
+
114
+ # Run tests in watch mode
115
+ npm run test:watch
116
+
117
+ # Run tests with coverage
118
+ npm run test:coverage
119
+
120
+ # Type check
121
+ npm run typecheck
122
+
123
+ # Build
124
+ npm run build
125
+ ```
126
+
127
+ ## Architecture
128
+
129
+ ### Type Safety
130
+
131
+ This generator uses **EXACT DMMF types** from Prisma and implements **zero type coercion**:
132
+
133
+ - Uses `FieldDefault` type matching Prisma's exact structure
134
+ - Type-safe validation with structural typing
135
+ - No `as` assertions or unsafe casts
136
+ - Complete TypeScript strict mode compliance
137
+
138
+ ### Generated Code Quality
139
+
140
+ - **Alphabetically sorted** fields and models for consistency
141
+ - **Branded types** for UUIDs via `Schema.UUID`
142
+ - **Exact type inference** - no widening to `any` or `unknown`
143
+ - **Auto-generated headers** with timestamps and edit warnings
144
+
145
+ ## Custom Type Overrides
146
+
147
+ Use `@customType` annotations to override Effect Schema types for **Prisma-supported fields**:
148
+
149
+ ```prisma
150
+ model User {
151
+ /// @customType(Schema.String.pipe(Schema.email()))
152
+ email String @unique
153
+
154
+ /// @customType(Schema.Number.pipe(Schema.positive()))
155
+ age Int
156
+
157
+ /// @customType(Schema.String.pipe(Schema.brand('UserId')))
158
+ userId String
159
+ }
160
+ ```
161
+
162
+ **Supported for**: All Prisma scalar types (String, Int, Float, Boolean, DateTime, BigInt, Decimal, Json, Bytes)
163
+
164
+ **Use cases**:
165
+ - Email/URL validation
166
+ - Number constraints (positive, range, etc.)
167
+ - Custom branded types
168
+ - Refined string patterns
169
+
170
+ **Examples**:
171
+ ```typescript
172
+ // Generated from Prisma schema with @customType annotations
173
+ export const _User = Schema.Struct({
174
+ email: Schema.String.pipe(Schema.email()),
175
+ age: Schema.Number.pipe(Schema.positive()),
176
+ userId: Schema.String.pipe(Schema.brand('UserId')),
177
+ });
178
+ ```
179
+
180
+ ## Troubleshooting
181
+
182
+ ### Generator Not Found
183
+
184
+ If you're developing the generator locally, make sure to build it first:
185
+
186
+ ```bash
187
+ npm run build
188
+ ```
189
+
190
+ Then reference it in your schema.prisma:
191
+
192
+ ```prisma
193
+ generator effect_schemas {
194
+ provider = "node ./path/to/dist/generator.js"
195
+ output = "./generated/effect"
196
+ }
197
+ ```
198
+
199
+ ### Wrong Types Generated
200
+
201
+ Check the generator output in console:
202
+
203
+ ```
204
+ [Effect Generator] Starting generation...
205
+ [Effect Generator] Processing 15 models, 3 enums
206
+ [Effect Generator] ✓ Generated to ../../libs/types/storage/src/lib/effect
207
+ ```
208
+
209
+ ### UUID Not Detected
210
+
211
+ Add explicit `@db.Uuid` attribute:
212
+
213
+ ```prisma
214
+ userId String @db.Uuid
215
+ ```
216
+
217
+ ## License
218
+
219
+ MIT
@@ -0,0 +1,10 @@
1
+ import type { DMMF } from '@prisma/generator-helper';
2
+ /**
3
+ * Generate Effect Schema Literal enum code
4
+ */
5
+ export declare function generateEnumSchema(enumDef: DMMF.DatamodelEnum): string;
6
+ /**
7
+ * Generate all enum schemas as a single file content
8
+ */
9
+ export declare function generateEnumsFile(enums: readonly DMMF.DatamodelEnum[]): string;
10
+ //# sourceMappingURL=enum.d.ts.map
@@ -0,0 +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;AAGrD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,UAa7D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC,aAAa,EAAE,UAWrE"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateEnumSchema = generateEnumSchema;
4
+ exports.generateEnumsFile = generateEnumsFile;
5
+ const enum_1 = require("../prisma/enum");
6
+ /**
7
+ * Generate Effect Schema Literal enum code
8
+ */
9
+ function generateEnumSchema(enumDef) {
10
+ const enumValues = enumDef.values
11
+ .map((v) => {
12
+ const value = (0, enum_1.getEnumValueDbName)(v);
13
+ return `"${value}"`;
14
+ })
15
+ .join(', ');
16
+ const enumName = enumDef.name;
17
+ return `export const ${enumName} = Schema.Literal(${enumValues});
18
+
19
+ export type ${enumName} = Schema.Schema.Type<typeof ${enumName}>;`;
20
+ }
21
+ /**
22
+ * Generate all enum schemas as a single file content
23
+ */
24
+ function generateEnumsFile(enums) {
25
+ const header = `/**
26
+ * Generated: ${new Date().toISOString()}
27
+ * DO NOT EDIT MANUALLY
28
+ */`;
29
+ const imports = `import { Schema } from "effect";`;
30
+ const enumSchemas = Array.from(enums).map(generateEnumSchema).join('\n\n');
31
+ return `${header}\n\n${imports}\n\n${enumSchemas}`;
32
+ }
33
+ //# sourceMappingURL=enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/effect/enum.ts"],"names":[],"mappings":";;AAMA,gDAaC;AAKD,8CAWC;AAlCD,yCAAoD;AAEpD;;GAEG;AACH,SAAgB,kBAAkB,CAAC,OAA2B;IAC5D,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM;SAC9B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,KAAK,GAAG,IAAA,yBAAkB,EAAC,CAAC,CAAC,CAAC;QACpC,OAAO,IAAI,KAAK,GAAG,CAAC;IACtB,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAE9B,OAAO,gBAAgB,QAAQ,qBAAqB,UAAU;;cAElD,QAAQ,gCAAgC,QAAQ,IAAI,CAAC;AACnE,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAAoC;IACpE,MAAM,MAAM,GAAG;gBACD,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;;IAEpC,CAAC;IAEH,MAAM,OAAO,GAAG,kCAAkC,CAAC;IAEnD,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE3E,OAAO,GAAG,MAAM,OAAO,OAAO,OAAO,WAAW,EAAE,CAAC;AACrD,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { DMMF } from '@prisma/generator-helper';
2
+ /**
3
+ * Effect domain generator - orchestrates Effect Schema generation
4
+ */
5
+ export declare class EffectGenerator {
6
+ private readonly dmmf;
7
+ constructor(dmmf: DMMF.Document);
8
+ /**
9
+ * Generate enums.ts file content
10
+ */
11
+ generateEnums(enums: readonly DMMF.DatamodelEnum[]): string;
12
+ /**
13
+ * Generate base schema for a model (_ModelName)
14
+ */
15
+ generateBaseSchema(model: DMMF.Model, fields: readonly DMMF.Field[]): string;
16
+ /**
17
+ * Generate operational schemas (ModelName.Selectable, etc.)
18
+ */
19
+ generateOperationalSchemas(model: DMMF.Model): string;
20
+ /**
21
+ * Generate TypeScript type exports
22
+ */
23
+ generateTypeExports(model: DMMF.Model): string;
24
+ /**
25
+ * Generate complete model schema (base + operational + types)
26
+ */
27
+ generateModelSchema(model: DMMF.Model, fields: DMMF.Field[]): string;
28
+ /**
29
+ * Generate types.ts file header
30
+ */
31
+ generateTypesHeader(hasEnums: boolean): string;
32
+ }
33
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +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;AAKrD;;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;;OAEG;IACH,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,IAAI,CAAC,KAAK,EAAE;IAgBnE;;OAEG;IACH,0BAA0B,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK;IAO5C;;OAEG;IACH,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK;IAOrC;;OAEG;IACH,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE;IAQ3D;;OAEG;IACH,mBAAmB,CAAC,QAAQ,EAAE,OAAO;CAkBtC"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EffectGenerator = void 0;
4
+ const enum_1 = require("./enum");
5
+ const type_1 = require("./type");
6
+ /**
7
+ * Effect domain generator - orchestrates Effect Schema generation
8
+ */
9
+ class EffectGenerator {
10
+ constructor(dmmf) {
11
+ this.dmmf = dmmf;
12
+ }
13
+ /**
14
+ * Generate enums.ts file content
15
+ */
16
+ generateEnums(enums) {
17
+ return (0, enum_1.generateEnumsFile)(enums);
18
+ }
19
+ /**
20
+ * Generate base schema for a model (_ModelName)
21
+ */
22
+ generateBaseSchema(model, fields) {
23
+ const fieldDefinitions = Array.from(fields)
24
+ .map((field) => {
25
+ const fieldType = (0, type_1.buildFieldType)(field, this.dmmf);
26
+ return ` ${field.name}: ${fieldType}`;
27
+ })
28
+ .join(',\n');
29
+ const baseSchemaName = `_${model.name}`;
30
+ return `// ${model.name} Base Schema
31
+ export const ${baseSchemaName} = Schema.Struct({
32
+ ${fieldDefinitions}
33
+ });`;
34
+ }
35
+ /**
36
+ * Generate operational schemas (ModelName.Selectable, etc.)
37
+ */
38
+ generateOperationalSchemas(model) {
39
+ const baseSchemaName = `_${model.name}`;
40
+ const operationalSchemaName = model.name;
41
+ return `export const ${operationalSchemaName} = getSchemas(${baseSchemaName});`;
42
+ }
43
+ /**
44
+ * Generate TypeScript type exports
45
+ */
46
+ generateTypeExports(model) {
47
+ const name = model.name;
48
+ return `export type ${name}Select = Schema.Schema.Type<typeof ${name}.Selectable>;
49
+ export type ${name}Insert = Schema.Schema.Type<typeof ${name}.Insertable>;
50
+ export type ${name}Update = Schema.Schema.Type<typeof ${name}.Updateable>;`;
51
+ }
52
+ /**
53
+ * Generate complete model schema (base + operational + types)
54
+ */
55
+ generateModelSchema(model, fields) {
56
+ const baseSchema = this.generateBaseSchema(model, fields);
57
+ const operationalSchema = this.generateOperationalSchemas(model);
58
+ const typeExports = this.generateTypeExports(model);
59
+ return `${baseSchema}\n\n${operationalSchema}\n\n${typeExports}`;
60
+ }
61
+ /**
62
+ * Generate types.ts file header
63
+ */
64
+ generateTypesHeader(hasEnums) {
65
+ const header = `/**
66
+ * Generated: ${new Date().toISOString()}
67
+ * DO NOT EDIT MANUALLY
68
+ */`;
69
+ const imports = [
70
+ `import { Schema } from "effect";`,
71
+ `import { columnType, generated, getSchemas } from "prisma-effect-kysely";`,
72
+ ];
73
+ if (hasEnums) {
74
+ const enumNames = this.dmmf.datamodel.enums.map((e) => e.name).join(', ');
75
+ imports.push(`import { ${enumNames} } from "./enums";`);
76
+ }
77
+ return `${header}\n\n${imports.join('\n')}`;
78
+ }
79
+ }
80
+ exports.EffectGenerator = EffectGenerator;
81
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/effect/generator.ts"],"names":[],"mappings":";;;AACA,iCAA2C;AAC3C,iCAAwC;AAGxC;;GAEG;AACH,MAAa,eAAe;IAC1B,YAA6B,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;IAAG,CAAC;IAEpD;;OAEG;IACH,aAAa,CAAC,KAAoC;QAChD,OAAO,IAAA,wBAAiB,EAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,KAAiB,EAAE,MAA6B;QACjE,MAAM,gBAAgB,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;aACxC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACb,MAAM,SAAS,GAAG,IAAA,qBAAc,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACnD,OAAO,KAAK,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACzC,CAAC,CAAC;aACD,IAAI,CAAC,KAAK,CAAC,CAAC;QAEf,MAAM,cAAc,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QAExC,OAAO,MAAM,KAAK,CAAC,IAAI;eACZ,cAAc;EAC3B,gBAAgB;IACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,0BAA0B,CAAC,KAAiB;QAC1C,MAAM,cAAc,GAAG,IAAI,KAAK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E,CAAC;IAC9C,CAAC;CACF;AAjFD,0CAiFC"}
@@ -0,0 +1,11 @@
1
+ import type { DMMF } from '@prisma/generator-helper';
2
+ /**
3
+ * Map Prisma field type to Effect Schema type
4
+ * Priority order: annotation → UUID → scalar → enum → unknown fallback
5
+ */
6
+ export declare function mapFieldToEffectType(field: DMMF.Field, dmmf: DMMF.Document): string;
7
+ /**
8
+ * Build complete field type with array and optional wrapping
9
+ */
10
+ export declare function buildFieldType(field: DMMF.Field, dmmf: DMMF.Document): string;
11
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/effect/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAyBrD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,UA2B1E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,UAcpE"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapFieldToEffectType = mapFieldToEffectType;
4
+ exports.buildFieldType = buildFieldType;
5
+ const type_1 = require("../prisma/type");
6
+ const annotations_1 = require("../utils/annotations");
7
+ /**
8
+ * Prisma scalar type mapping to Effect Schema types
9
+ * Uses const assertion to avoid type guards
10
+ */
11
+ const PRISMA_SCALAR_MAP = {
12
+ String: 'Schema.String',
13
+ Int: 'Schema.Number',
14
+ Float: 'Schema.Number',
15
+ BigInt: 'Schema.BigInt',
16
+ Decimal: 'Schema.String', // For precision
17
+ Boolean: 'Schema.Boolean',
18
+ DateTime: 'Schema.Date',
19
+ Json: 'Schema.Unknown', // Safe unknown type
20
+ Bytes: 'Schema.Uint8Array',
21
+ };
22
+ /**
23
+ * Map Prisma field type to Effect Schema type
24
+ * Priority order: annotation → UUID → scalar → enum → unknown fallback
25
+ */
26
+ function mapFieldToEffectType(field, dmmf) {
27
+ // PRIORITY 1: Check for @customType annotation
28
+ const typeOverride = (0, annotations_1.extractEffectTypeOverride)(field);
29
+ if (typeOverride) {
30
+ return typeOverride;
31
+ }
32
+ // PRIORITY 2: Handle String type with UUID detection
33
+ if (field.type === 'String' && (0, type_1.isUuidField)(field)) {
34
+ return 'Schema.UUID';
35
+ }
36
+ // PRIORITY 3: Handle scalar types with const assertion lookup
37
+ const scalarType = PRISMA_SCALAR_MAP[field.type];
38
+ if (scalarType) {
39
+ return scalarType;
40
+ }
41
+ // PRIORITY 4: Check if it's an enum
42
+ const enumDef = dmmf.datamodel.enums.find((e) => e.name === field.type);
43
+ if (enumDef) {
44
+ return field.type; // Use enum name directly
45
+ }
46
+ // PRIORITY 5: Fallback to Unknown
47
+ return 'Schema.Unknown';
48
+ }
49
+ /**
50
+ * Build complete field type with array and optional wrapping
51
+ */
52
+ function buildFieldType(field, dmmf) {
53
+ let baseType = mapFieldToEffectType(field, dmmf);
54
+ // Handle arrays
55
+ if ((0, type_1.isListField)(field)) {
56
+ baseType = `Schema.Array(${baseType})`;
57
+ }
58
+ // Handle optional fields (only if NOT already has @default)
59
+ if (!(0, type_1.isRequiredField)(field) && !(0, type_1.hasDefaultValue)(field)) {
60
+ baseType = `Schema.UndefinedOr(${baseType})`;
61
+ }
62
+ return baseType;
63
+ }
64
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/effect/type.ts"],"names":[],"mappings":";;AA6BA,oDA2BC;AAKD,wCAcC;AA1ED,yCAKwB;AACxB,sDAAiE;AAEjE;;;GAGG;AACH,MAAM,iBAAiB,GAAG;IACxB,MAAM,EAAE,eAAe;IACvB,GAAG,EAAE,eAAe;IACpB,KAAK,EAAE,eAAe;IACtB,MAAM,EAAE,eAAe;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C,CAAC;IAED,4DAA4D;IAC5D,IAAI,CAAC,IAAA,sBAAe,EAAC,KAAK,CAAC,IAAI,CAAC,IAAA,sBAAe,EAAC,KAAK,CAAC,EAAE,CAAC;QACvD,QAAQ,GAAG,sBAAsB,QAAQ,GAAG,CAAC;IAC/C,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ export * from '../kysely/helpers';
3
+ export declare const generator: void;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":";AAMA,cAAc,mBAAmB,CAAC;AAElC,eAAO,MAAM,SAAS,MAUpB,CAAC"}
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.generator = void 0;
19
+ const generator_helper_1 = require("@prisma/generator-helper");
20
+ const orchestrator_1 = require("./orchestrator");
21
+ // Re-export kysely helpers for generated code
22
+ __exportStar(require("../kysely/helpers"), exports);
23
+ exports.generator = (0, generator_helper_1.generatorHandler)({
24
+ onManifest: () => ({
25
+ version: '1.0.0',
26
+ defaultOutput: './generated',
27
+ prettyName: 'Prisma Effect Kysely Generator',
28
+ }),
29
+ onGenerate: async (options) => {
30
+ const orchestrator = new orchestrator_1.GeneratorOrchestrator(options);
31
+ await orchestrator.generate(options);
32
+ },
33
+ });
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA,+DAA4D;AAC5D,iDAAuD;AAEvD,8CAA8C;AAC9C,oDAAkC;AAErB,QAAA,SAAS,GAAG,IAAA,mCAAgB,EAAC;IACxC,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QACjB,OAAO,EAAE,OAAO;QAChB,aAAa,EAAE,aAAa;QAC5B,UAAU,EAAE,gCAAgC;KAC7C,CAAC;IACF,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QAC5B,MAAM,YAAY,GAAG,IAAI,oCAAqB,CAAC,OAAO,CAAC,CAAC;QACxD,MAAM,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { GeneratorOptions } from '@prisma/generator-helper';
2
+ /**
3
+ * Orchestrates the generation of Effect Schema types from Prisma schema
4
+ * Uses domain-driven generators: Prisma → Effect → Kysely
5
+ */
6
+ export declare class GeneratorOrchestrator {
7
+ private readonly fileManager;
8
+ private readonly prismaGen;
9
+ private readonly effectGen;
10
+ private readonly kyselyGen;
11
+ constructor(options: GeneratorOptions);
12
+ /**
13
+ * Validate and extract output path from generator options
14
+ */
15
+ private validateOutputPath;
16
+ /**
17
+ * Main generation entry point
18
+ * Orchestrates all generation steps
19
+ */
20
+ generate(options: GeneratorOptions): Promise<void>;
21
+ /**
22
+ * Generate enums.ts file
23
+ */
24
+ private generateEnums;
25
+ /**
26
+ * Generate types.ts file
27
+ */
28
+ private generateTypes;
29
+ /**
30
+ * Generate index.ts file
31
+ */
32
+ private generateIndex;
33
+ /**
34
+ * Log generation start with stats
35
+ */
36
+ private logStart;
37
+ /**
38
+ * Log generation completion
39
+ */
40
+ private logComplete;
41
+ }
42
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/generator/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAMjE;;;GAGG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;gBAEhC,OAAO,EAAE,gBAAgB;IASrC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;;OAGG;IACG,QAAQ,CAAC,OAAO,EAAE,gBAAgB;IAgBxC;;OAEG;YACW,aAAa;IAM3B;;OAEG;YACW,aAAa;IAoC3B;;OAEG;YACW,aAAa;IAK3B;;OAEG;IACH,OAAO,CAAC,QAAQ;IAYhB;;OAEG;IACH,OAAO,CAAC,WAAW;CAKpB"}