prisma-effect-kysely 1.8.2 → 1.9.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 CHANGED
@@ -5,83 +5,193 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [1.8.2] - 2025-10-13
8
+ ## [1.9.0] - 2025-10-13
9
9
 
10
10
  ### Fixed
11
11
 
12
- #### Kysely Join Type Inference
13
- - **DB interface now uses pre-resolved SelectEncoded types**: Fixed TypeScript compilation errors when using Kysely `innerJoin()` with junction tables
14
- - **Problem**: `Schema.Schema.Encoded<typeof _table>` created conditional types too complex for Kysely's deep generic inference
15
- - **Solution**: Use existing pre-resolved `*SelectEncoded` type aliases that already exist in generated code
16
- - **Impact**: Kysely can now properly infer types for join operations without "Type instantiation is excessively deep" errors
17
- - **Breaking**: None - only internal DB interface generation changed, user API remains identical
18
- - Location: `src/kysely/type.ts:61-72`
19
-
20
- #### Unused Enum Type Imports
21
- - **types.ts now imports only Schema wrappers**: Eliminated TypeScript "declared but never read" warnings for enum types
22
- - **Problem**: Generated `types.ts` imported both plain enum types (e.g., `BudgetStatus`) and schema wrappers (e.g., `BudgetStatusSchema`), but only the schema wrappers were used in field definitions
23
- - **Solution**: Import generation now only includes `*Schema` wrappers, not plain enum types
24
- - **Impact**: Eliminates all unused import warnings for enum types in generated code
25
- - **Breaking**: None - users can still import plain enum types directly from `enums.ts` if needed
26
- - Location: `src/effect/generator.ts:95-107`
27
-
28
- ### Added
12
+ #### TypeScript Type Inference for Generated Fields - Explicit Omit Types
13
+ - **Generate explicit Insert type definitions using TypeScript's Omit utility for compile-time type safety**
14
+ - **Problem**: v1.8.4 fixed runtime behavior (generated fields correctly omitted from Insertable schema), but TypeScript's `Schema.Schema.Type` inference couldn't see runtime AST field filtering, causing all fields to appear in Insert types
15
+ - **Root Cause**: TypeScript's structural type inference works on static schema structure; runtime AST transformations are invisible to the type system
16
+ - **Solution**: Code generator now creates explicit type definitions: `Omit<Schema.Schema.Type<typeof Model.Insertable>, 'generatedField1' | 'generatedField2'>`
17
+ - **Result**: Compile-time type safety + runtime correctness
18
+ - **Benefits**:
19
+ - TypeScript compiler errors when attempting to insert generated fields (prevents bugs at compile-time)
20
+ - Accurate IDE autocomplete and type hints for Insert operations
21
+ - Matches code generation best practices (same approach as Prisma Client, Drizzle ORM, tRPC)
22
+ - Zero runtime overhead (types are erased at compile time)
23
+ - **Fields Automatically Omitted from Insert Types**:
24
+ - ID fields with `@default` (e.g., `@id @default(uuid())`)
25
+ - Non-ID fields with `@default` (e.g., `@default(now())`)
26
+ - Fields with `@updatedAt` directive (auto-managed by database)
27
+ - **Example**:
28
+ ```typescript
29
+ // Prisma schema:
30
+ model User {
31
+ id String @id @default(uuid()) @db.Uuid
32
+ email String
33
+ name String
34
+ createdAt DateTime @default(now())
35
+ updatedAt DateTime @updatedAt
36
+ }
29
37
 
30
- #### Test Coverage
31
- - Added comprehensive test suite for Kysely join type inference (`src/__tests__/kysely-join-inference.test.ts`)
32
- - Type-level tests verify TypeScript compilation succeeds
33
- - Tests junction table joins (e.g., `_product_tags`)
34
- - Tests complex many-to-many query patterns with aliases
35
- - Tests multiple junction table joins in single query
36
- - All tests use TDD approach (failing test first, then fix)
38
+ // Generated types (v1.9.0):
39
+ export type UserInsert = Omit<
40
+ Schema.Schema.Type<typeof User.Insertable>,
41
+ 'id' | 'createdAt' | 'updatedAt'
42
+ >;
43
+
44
+ // TypeScript now enforces:
45
+ const validInsert: UserInsert = {
46
+ email: 'user@example.com',
47
+ name: 'John Doe'
48
+ }; // ✅ Compiles successfully
49
+
50
+ const invalidInsert: UserInsert = {
51
+ id: 'some-uuid', // ❌ TypeScript error: 'id' does not exist in type 'UserInsert'
52
+ email: 'user@example.com',
53
+ name: 'John Doe'
54
+ };
55
+ ```
56
+ - **Implementation**:
57
+ - Added `getOmittedInsertFields()` helper in `src/effect/generator.ts` to identify fields during code generation
58
+ - Uses DMMF properties: `hasDefaultValue` and `isUpdatedAt`
59
+ - Fields are alphabetically sorted in Omit union for deterministic output
60
+ - Location: `src/effect/generator.ts:10-36, 83-110`
61
+ - Orchestrator: `src/generator/orchestrator.ts:98`
62
+ - Tests: `src/__tests__/type-inference-generated.test.ts` (10 new tests, all passing)
37
63
 
38
64
  ### Technical Details
65
+ - **Architecture**: Explicit type generation (industry standard for code generators)
66
+ - **Rationale**: TypeScript's structural type inference works on static schema structure; runtime AST transformations are invisible to the type system
67
+ - **Not a Workaround**: Standard practice when type inference can't capture runtime behavior (same approach as Prisma Client, Drizzle ORM, tRPC)
68
+ - **Comparison to @effect/sql**: They use `VariantSchema.Field` for compile-time variant control; we use explicit `Omit` types for the same goal
69
+ - **Quality Assurance**: All 181 tests passing (including 10 new type inference tests), strict TypeScript compilation
70
+ - **Backwards Compatible**: No breaking changes to runtime behavior (maintains v1.8.4 runtime guarantees)
71
+ - **Type Safety Guarantee**: Models without generated fields continue to use plain `Schema.Schema.Type` (no unnecessary `Omit`)
72
+
73
+ ### Breaking Changes
74
+ None - This is a non-breaking enhancement. The change is purely additive at the type level:
75
+ - Runtime behavior unchanged from v1.8.4
76
+ - Generated schemas remain the same
77
+ - Only TypeScript type definitions become more restrictive (catching bugs earlier)
78
+
79
+ ## [1.8.4] - 2025-10-13
39
80
 
40
- **Kysely Join Fix:**
41
- - DB interface entries changed from `Table: Schema.Schema.Encoded<typeof _Table>` to `Table: TableSelectEncoded`
42
- - Join table entries changed from `_table: Schema.Schema.Encoded<typeof _joinTable>` to `_table: joinTableSelectEncoded`
81
+ ### Fixed
43
82
 
44
- **Enum Import Fix:**
45
- - Import generation changed from `.flatMap()` returning `[baseName, `${baseName}Schema`]` to `.map()` returning only `${baseName}Schema`
46
- - Generated imports change from `import { Role, RoleSchema, Status, StatusSchema }` to `import { RoleSchema, StatusSchema }`
47
- - Plain enum types still exported from `enums.ts` for direct use
83
+ #### Native @effect/sql Pattern for Generated Fields
84
+ - **Implemented native field filtering for `generated()` fields following @effect/sql Model.Generated pattern**
85
+ - **Problem**: Generated fields (those with `@default` in Prisma schema) were incorrectly made optional in Insertable schema using `Union(T, Undefined)`, which doesn't properly reflect TypeScript optionality and doesn't follow Effect ecosystem patterns
86
+ - **Solution**: OMIT generated fields entirely from Insertable schema (not make them optional) following @effect/sql's `Model.Generated` pattern
87
+ - **Implementation**:
88
+ - Simplified `generated()` to be just a marker annotation (no schema transformation)
89
+ - Updated `insertable()` to filter out fields with `GeneratedId` annotation during AST reconstruction
90
+ - Removed unnecessary `GeneratedSchemas` interface
91
+ - Simplified `extractParametersFromTypeLiteral` (generated fields are now just markers)
92
+ - Removed `OptionalType` detection from `isOptionalType()` (only checks for `Union(T, Undefined)` pattern)
93
+ - **Benefits**:
94
+ - Native Effect Schema pattern (zero coercions)
95
+ - Follows @effect/sql ecosystem conventions
96
+ - Runtime correctness: generated fields are completely absent from Insertable schema
97
+ - Respects TypeScript optionality semantics (property optional `?:` vs value optional `| undefined`)
98
+ - Cleaner implementation with fewer special cases
99
+ - **Example**:
100
+ ```typescript
101
+ // Prisma schema:
102
+ model Agent {
103
+ id String @id @default(uuid()) @db.Uuid
104
+ session_id String @default(uuid()) @db.Uuid
105
+ name String
106
+ }
48
107
 
49
- **Overall:**
50
- - Effect Schema functionality preserved - all 158 tests passing
51
- - No type coercions introduced
52
- - No breaking changes
108
+ // Generated Effect Schema:
109
+ export const _Agent = Schema.Struct({
110
+ id: generated(Schema.UUID), // Omitted from insert
111
+ session_id: generated(Schema.UUID), // Omitted from insert
112
+ name: Schema.String,
113
+ });
53
114
 
54
- ## [1.8.1] - 2025-10-12
115
+ // Runtime behavior:
116
+ const schemas = getSchemas(_Agent);
55
117
 
56
- ### Fixed
118
+ // Insert only requires 'name' - generated fields completely absent
119
+ const insert: AgentInsert = { name: 'test' };
120
+ ```
121
+ - **Test Coverage**: 15 tests passing including comprehensive runtime validation and AST structure verification
122
+ - Location: `src/kysely/helpers.ts:43-119, 188-224`
123
+ - Tests: `src/__tests__/kysely-helpers.test.ts:186-283`
124
+
125
+ ### Known Limitations
126
+
127
+ #### TypeScript Type Inference for Insertable Types
128
+ - **TypeScript's `Schema.Schema.Type` inference still includes all fields in Insert types**
129
+ - **Issue**: While runtime validation correctly omits generated fields, TypeScript type inference from `Schema.Schema.Type<typeof Model.Insertable>` cannot see runtime AST field filtering and still infers all fields as required
130
+ - **Root Cause**: TypeScript's structural type inference works on the base schema structure before runtime transformations
131
+ - **Workaround**: Use explicit type annotations or runtime validation (Effect Schema will filter out extra fields)
132
+ - **Planned Fix**: Update code generator (`src/effect/generator.ts`) to create explicit TypeScript type definitions using `Omit` utility type:
133
+ ```typescript
134
+ // Current:
135
+ export type AgentInsert = Schema.Schema.Type<typeof Agent.Insertable>;
57
136
 
58
- #### Dynamic Version Management
59
- - **Generator version now read from package.json**: Removed hardcoded version string in generator manifest
60
- - Generator now reports correct version dynamically
61
- - Version always stays in sync with package.json
62
- - No more manual version updates needed in multiple places
63
- - Location: `src/generator/index.ts:5,12`
137
+ // Planned:
138
+ export type AgentInsert = Omit<Schema.Schema.Type<typeof Agent.Insertable>, 'id' | 'session_id'>;
139
+ ```
140
+ - **Status**: Code generation fix planned for v1.9.0
141
+
142
+ ### Technical Details
143
+ - **Quality Assurance**: All 15 kysely-helpers tests passing, zero TypeScript errors in implementation
144
+ - **Test Approach**: TDD (Test-Driven Development) - wrote failing tests first, then implemented to make them pass
145
+ - **Research**: Validated approach against @effect/sql's `Model.Generated` pattern (official Effect ecosystem standard)
146
+ - **Effect Schema Integration**: Uses native AST filtering with `propertySignatures.filter()` (no custom type guards or coercions)
147
+ - **Backwards Compatible**: No breaking changes to existing runtime behavior
64
148
 
65
- #### Custom Relation Name Support for Join Tables
66
- - **Prisma custom relation names now respected**: Fixed implicit many-to-many join table naming
67
- - `@relation("product_tags")` now correctly generates `_product_tags` table (not `_ProductToProductTag`)
68
- - Matches Prisma's actual database table naming convention
69
- - Both custom and default relation names work correctly
70
- - Location: `src/prisma/relation.ts:106-115`
149
+ ## [1.8.3] - 2025-10-13
71
150
 
72
151
  ### Added
73
152
 
74
- #### Test Coverage
75
- - Added test case for custom relation names in implicit many-to-many relations
76
- - Product/ProductTag models with `@relation("product_tags")`
77
- - Validates correct table name generation (`_product_tags`)
78
- - Location: `src/__tests__/fixtures/test.prisma:166-177`
153
+ #### Semantic Join Table Column Names
154
+ - **Generated join tables now use semantic snake_case field names** instead of Prisma's generic A/B columns
155
+ - **Problem**: Prisma's implicit M2M join tables use non-semantic `A` and `B` column names, causing poor developer experience and forcing developers to remember alphabetical model ordering
156
+ - **Solution**: Map semantic names like `product_id`, `product_tag_id` to actual database columns using Effect Schema's `propertySignature` with `fromKey`
157
+ - **Benefits**:
158
+ - Developer-friendly semantic names in TypeScript code
159
+ - Maintains Prisma A/B database compatibility (no migration required)
160
+ - Type-safe bidirectional transformation (encode/decode)
161
+ - Follows snake_case convention for database identifiers (Prisma best practice)
162
+ - **Example**:
163
+ ```typescript
164
+ // Before (v1.8.2):
165
+ export const _ProductToProductTag = Schema.Struct({
166
+ A: columnType(Schema.UUID, Schema.Never, Schema.Never),
167
+ B: columnType(Schema.UUID, Schema.Never, Schema.Never),
168
+ });
169
+
170
+ // After (v1.8.3):
171
+ export const _ProductToProductTag = Schema.Struct({
172
+ product_id: Schema.propertySignature(columnType(Schema.UUID, Schema.Never, Schema.Never)).pipe(Schema.fromKey("A")),
173
+ product_tag_id: Schema.propertySignature(columnType(Schema.UUID, Schema.Never, Schema.Never)).pipe(Schema.fromKey("B")),
174
+ });
175
+ ```
176
+ - Location: `src/effect/join-table.ts:37-69`
177
+ - New utility: `toSnakeCase()` in `src/utils/naming.ts:61-73`
178
+
179
+ ### Fixed
180
+
181
+ #### Unused Enum Type Imports
182
+ - **types.ts now imports only Schema wrappers**: Eliminated TypeScript "declared but never read" warnings
183
+ - **Problem**: Generated `types.ts` imported both plain enum types (e.g., `BudgetStatus`) and schema wrappers (e.g., `BudgetStatusSchema`), but only schema wrappers were used
184
+ - **Solution**: Import generation now only includes `*Schema` wrappers
185
+ - **Impact**: Cleaner generated code, no TypeScript warnings
186
+ - Location: `src/effect/generator.ts:95-107`
79
187
 
80
188
  ### Technical Details
81
- - Uses TypeScript's `resolveJsonModule` to import package.json
82
- - Prisma's `field.relationName` contains either custom name or Prisma-generated default
83
- - Maintains alphabetical model ordering for A/B column assignment in join tables
84
- - Null-safety check added for relationName (defensive programming)
189
+ - **Quality Assurance**: All 165 tests passing (15 naming tests + 10 join table tests + 140 existing), zero TypeScript errors
190
+ - **Test Coverage**: New comprehensive tests for `toSnakeCase` utility and semantic join table column generation
191
+ - **Documentation**: Updated CLAUDE.md with join table naming behavior explanation
192
+ - **Research**: Verified snake_case follows Prisma generator best practices (community standard for database identifiers)
193
+ - **Backwards Compatible**: No breaking changes - existing queries continue to work
194
+ - **Effect Schema Integration**: Uses native `propertySignature` + `fromKey` pattern (official Effect Schema column mapping approach)
85
195
 
86
196
  ## [1.8.0] - 2025-10-12
87
197
 
@@ -19,9 +19,9 @@ export declare class EffectGenerator {
19
19
  */
20
20
  generateOperationalSchemas(model: DMMF.Model): string;
21
21
  /**
22
- * Generate TypeScript type exports
22
+ * Generate TypeScript type exports with explicit Omit for generated fields
23
23
  */
24
- generateTypeExports(model: DMMF.Model): string;
24
+ generateTypeExports(model: DMMF.Model, fields: readonly DMMF.Field[]): string;
25
25
  /**
26
26
  * Generate complete model schema (base + operational + types)
27
27
  */
@@ -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;AAMrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;GAEG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,IAA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C,KAAK,EAAE;IA6BpE;;OAEG;IACH,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE;IAQ3D;;;;OAIG;IACH,mBAAmB,CAAC,QAAQ,EAAE,OAAO;IAyBrC;;OAEG;IACH,wBAAwB,CAAC,UAAU,EAAE,aAAa,EAAE;CAGrD"}
@@ -6,6 +6,32 @@ const type_1 = require("./type");
6
6
  const naming_1 = require("../utils/naming");
7
7
  const codegen_1 = require("../utils/codegen");
8
8
  const join_table_1 = require("./join-table");
9
+ const type_2 = require("../prisma/type");
10
+ /**
11
+ * Identify fields that should be omitted from Insert types
12
+ *
13
+ * Includes:
14
+ * - Fields with @default (both ID and non-ID fields) - wrapped with generated() or columnType with Never
15
+ * - Fields with @updatedAt directive - auto-managed by database
16
+ *
17
+ * Note: These fields are already filtered at runtime by v1.8.4 implementation.
18
+ * We explicitly omit them in TypeScript types for compile-time safety.
19
+ */
20
+ function getOmittedInsertFields(fields) {
21
+ return fields
22
+ .filter((field) => {
23
+ // Fields with @default (includes IDs and regular generated fields)
24
+ if ((0, type_2.hasDefaultValue)(field)) {
25
+ return true;
26
+ }
27
+ // Fields with @updatedAt directive (DMMF provides isUpdatedAt property)
28
+ if (field.isUpdatedAt === true) {
29
+ return true;
30
+ }
31
+ return false;
32
+ })
33
+ .map((field) => field.name);
34
+ }
9
35
  /**
10
36
  * Effect domain generator - orchestrates Effect Schema generation
11
37
  */
@@ -44,18 +70,26 @@ ${fieldDefinitions}
44
70
  return `export const ${operationalSchemaName} = getSchemas(${baseSchemaName});`;
45
71
  }
46
72
  /**
47
- * Generate TypeScript type exports
73
+ * Generate TypeScript type exports with explicit Omit for generated fields
48
74
  */
49
- generateTypeExports(model) {
75
+ generateTypeExports(model, fields) {
50
76
  const name = (0, naming_1.toPascalCase)(model.name);
77
+ const omittedFields = getOmittedInsertFields(fields);
78
+ // Generate Insert type with explicit Omit for generated/auto-managed fields
79
+ const insertType = omittedFields.length > 0
80
+ ? `Omit<Schema.Schema.Type<typeof ${name}.Insertable>, ${omittedFields.map((f) => `'${f}'`).join(' | ')}>`
81
+ : `Schema.Schema.Type<typeof ${name}.Insertable>`;
82
+ const insertEncodedType = omittedFields.length > 0
83
+ ? `Omit<Schema.Schema.Encoded<typeof ${name}.Insertable>, ${omittedFields.map((f) => `'${f}'`).join(' | ')}>`
84
+ : `Schema.Schema.Encoded<typeof ${name}.Insertable>`;
51
85
  // Application-side types (decoded - for repository layer)
52
86
  const applicationTypes = `export type ${name}Select = Schema.Schema.Type<typeof ${name}.Selectable>;
53
- export type ${name}Insert = Schema.Schema.Type<typeof ${name}.Insertable>;
87
+ export type ${name}Insert = ${insertType};
54
88
  export type ${name}Update = Schema.Schema.Type<typeof ${name}.Updateable>;`;
55
89
  // Database-side encoded types (for queries layer)
56
90
  const encodedTypes = `
57
91
  export type ${name}SelectEncoded = Schema.Schema.Encoded<typeof ${name}.Selectable>;
58
- export type ${name}InsertEncoded = Schema.Schema.Encoded<typeof ${name}.Insertable>;
92
+ export type ${name}InsertEncoded = ${insertEncodedType};
59
93
  export type ${name}UpdateEncoded = Schema.Schema.Encoded<typeof ${name}.Updateable>;`;
60
94
  return applicationTypes + encodedTypes;
61
95
  }
@@ -65,7 +99,7 @@ export type ${name}UpdateEncoded = Schema.Schema.Encoded<typeof ${name}.Updateab
65
99
  generateModelSchema(model, fields) {
66
100
  const baseSchema = this.generateBaseSchema(model, fields);
67
101
  const operationalSchema = this.generateOperationalSchemas(model);
68
- const typeExports = this.generateTypeExports(model);
102
+ const typeExports = this.generateTypeExports(model, fields);
69
103
  return `${baseSchema}\n\n${operationalSchema}\n\n${typeExports}`;
70
104
  }
71
105
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/effect/generator.ts"],"names":[],"mappings":";;;AACA,iCAA2C;AAC3C,iCAAwC;AACxC,4CAA+C;AAC/C,8CAAsD;AACtD,6CAAuD;AAG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AI,CAAC,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,wBAAwB,CAAC,UAA2B;QAClD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAA,oCAAuB,EAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrF,CAAC;CACF;AAtHD,0CAsHC"}
@@ -4,10 +4,15 @@ import type { JoinTableInfo } from '../prisma/relation';
4
4
  * Generate Effect Schema for an implicit many-to-many join table
5
5
  *
6
6
  * Structure:
7
- * - Base schema with A and B columns (both read-only FKs via columnType)
7
+ * - Base schema with semantic snake_case field names mapped to A/B via fromKey
8
8
  * - Operational schemas via getSchemas()
9
9
  * - Type exports (Select, Insert, Update)
10
10
  * - Encoded type exports
11
+ *
12
+ * Example:
13
+ * - Database columns: A, B (Prisma requirement)
14
+ * - TypeScript fields: product_id, product_tag_id (semantic snake_case)
15
+ * - Mapping: product_id → A, product_tag_id → B (via Schema.fromKey)
11
16
  */
12
17
  export declare function generateJoinTableSchema(joinTable: JoinTableInfo, _dmmf: DMMF.Document): string;
13
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,oBAAoB,CAAC;AAoBxD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,GAAG,MAAM,CAiC9F"}
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,oBAAoB,CAAC;AAqBxD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,GAAG,MAAM,CAgD9F"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateJoinTableSchema = generateJoinTableSchema;
4
+ const naming_1 = require("../utils/naming");
4
5
  /**
5
6
  * Map join table column type to Effect Schema type
6
7
  * Uses same mapping as regular fields
@@ -20,21 +21,32 @@ function mapColumnType(columnType, isUuid) {
20
21
  * Generate Effect Schema for an implicit many-to-many join table
21
22
  *
22
23
  * Structure:
23
- * - Base schema with A and B columns (both read-only FKs via columnType)
24
+ * - Base schema with semantic snake_case field names mapped to A/B via fromKey
24
25
  * - Operational schemas via getSchemas()
25
26
  * - Type exports (Select, Insert, Update)
26
27
  * - Encoded type exports
28
+ *
29
+ * Example:
30
+ * - Database columns: A, B (Prisma requirement)
31
+ * - TypeScript fields: product_id, product_tag_id (semantic snake_case)
32
+ * - Mapping: product_id → A, product_tag_id → B (via Schema.fromKey)
27
33
  */
28
34
  function generateJoinTableSchema(joinTable, _dmmf) {
29
- const { tableName, relationName, columnAType, columnBType, columnAIsUuid, columnBIsUuid } = joinTable;
35
+ const { tableName, relationName, modelA, modelB, columnAType, columnBType, columnAIsUuid, columnBIsUuid, } = joinTable;
30
36
  // Map column types to Effect Schema types
31
37
  const columnASchema = mapColumnType(columnAType, columnAIsUuid);
32
38
  const columnBSchema = mapColumnType(columnBType, columnBIsUuid);
39
+ // Generate semantic snake_case field names from model names
40
+ const columnAName = `${(0, naming_1.toSnakeCase)(modelA)}_id`;
41
+ const columnBName = `${(0, naming_1.toSnakeCase)(modelB)}_id`;
33
42
  // Both columns are foreign keys, so use columnType for read-only behavior
34
- const columnAField = ` A: columnType(${columnASchema}, Schema.Never, Schema.Never)`;
35
- const columnBField = ` B: columnType(${columnBSchema}, Schema.Never, Schema.Never)`;
43
+ // Use propertySignature with fromKey to map semantic names to actual A/B database columns
44
+ const columnAField = ` ${columnAName}: Schema.propertySignature(columnType(${columnASchema}, Schema.Never, Schema.Never)).pipe(Schema.fromKey("A"))`;
45
+ const columnBField = ` ${columnBName}: Schema.propertySignature(columnType(${columnBSchema}, Schema.Never, Schema.Never)).pipe(Schema.fromKey("B"))`;
36
46
  // Generate base schema
37
47
  const baseSchema = `// ${tableName} Join Table Schema
48
+ // Database columns: A (${modelA}), B (${modelB})
49
+ // TypeScript fields: ${columnAName}, ${columnBName}
38
50
  export const _${relationName} = Schema.Struct({
39
51
  ${columnAField},
40
52
  ${columnBField},
@@ -1 +1 @@
1
- {"version":3,"file":"join-table.js","sourceRoot":"","sources":["../../src/effect/join-table.ts"],"names":[],"mappings":";;AA8BA,0DAiCC;AA5DD;;;GAGG;AACH,SAAS,aAAa,CAAC,UAAkB,EAAE,MAAe;IACxD,IAAI,UAAU,KAAK,QAAQ,IAAI,MAAM,EAAE,CAAC;QACtC,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,MAAM,SAAS,GAA2B;QACxC,MAAM,EAAE,eAAe;QACvB,GAAG,EAAE,eAAe;QACpB,MAAM,EAAE,eAAe;KACxB,CAAC;IAEF,OAAO,SAAS,CAAC,UAAU,CAAC,IAAI,gBAAgB,CAAC;AACnD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,uBAAuB,CAAC,SAAwB,EAAE,KAAoB;IACpF,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,GACvF,SAAS,CAAC;IAEZ,0CAA0C;IAC1C,MAAM,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAChE,MAAM,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAEhE,0EAA0E;IAC1E,MAAM,YAAY,GAAG,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SAAS,CAAC;IAEd,0CAA0C;IAC1C,MAAM,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAChE,MAAM,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAEhE,4DAA4D;IAC5D,MAAM,WAAW,GAAG,GAAG,IAAA,oBAAW,EAAC,MAAM,CAAC,KAAK,CAAC;IAChD,MAAM,WAAW,GAAG,GAAG,IAAA,oBAAW,EAAC,MAAM,CAAC,KAAK,CAAC;IAEhD,0EAA0E;IAC1E,0FAA0F;IAC1F,MAAM,YAAY,GAAG,KAAK,WAAW,yCAAyC,aAAa,0DAA0D,CAAC;IACtJ,MAAM,YAAY,GAAG,KAAK,WAAW,yCAAyC,aAAa,0DAA0D,CAAC;IAEtJ,uBAAuB;IACvB,MAAM,UAAU,GAAG,MAAM,SAAS;0BACV,MAAM,SAAS,MAAM;wBACvB,WAAW,KAAK,WAAW;gBACnC,YAAY;EAC1B,YAAY;EACZ,YAAY;IACV,CAAC;IAEH,+BAA+B;IAC/B,MAAM,iBAAiB,GAAG,gBAAgB,YAAY,kBAAkB,YAAY,IAAI,CAAC;IAEzF,wBAAwB;IACxB,MAAM,WAAW,GAAG,eAAe,YAAY,sCAAsC,YAAY;cACrF,YAAY,sCAAsC,YAAY;cAC9D,YAAY,sCAAsC,YAAY,eAAe,CAAC;IAE1F,gCAAgC;IAChC,MAAM,cAAc,GAAG,eAAe,YAAY,gDAAgD,YAAY;cAClG,YAAY,gDAAgD,YAAY;cACxE,YAAY,gDAAgD,YAAY,eAAe,CAAC;IAEpG,OAAO,GAAG,UAAU,OAAO,iBAAiB,OAAO,WAAW,KAAK,cAAc,EAAE,CAAC;AACtF,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { GeneratorOptions } from "@prisma/generator-helper";
1
+ import type { GeneratorOptions } from '@prisma/generator-helper';
2
2
  /**
3
3
  * Orchestrates the generation of Effect Schema types from Prisma schema
4
4
  * Uses domain-driven generators: Prisma → Effect → Kysely
@@ -1 +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;IA4C3B;;OAEG;YACW,aAAa;IAK3B;;OAEG;IACH,OAAO,CAAC,QAAQ;IAYhB;;OAEG;IACH,OAAO,CAAC,WAAW;CAKpB"}
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;IAYxC;;OAEG;YACW,aAAa;IAM3B;;OAEG;YACW,aAAa;IA0C3B;;OAEG;YACW,aAAa;IAK3B;;OAEG;IACH,OAAO,CAAC,QAAQ;IAQhB;;OAEG;IACH,OAAO,CAAC,WAAW;CAKpB"}
@@ -23,7 +23,7 @@ class GeneratorOrchestrator {
23
23
  validateOutputPath(options) {
24
24
  const outputPath = options.generator.output?.value;
25
25
  if (!outputPath) {
26
- throw new Error("Prisma Effect Generator: output path not configured.\n" +
26
+ throw new Error('Prisma Effect Generator: output path not configured.\n' +
27
27
  'Add "output" to your generator block in schema.prisma');
28
28
  }
29
29
  return outputPath;
@@ -37,11 +37,7 @@ class GeneratorOrchestrator {
37
37
  // Ensure output directory exists
38
38
  await this.fileManager.ensureDirectory();
39
39
  // Generate all files in parallel for better performance
40
- await Promise.all([
41
- this.generateEnums(),
42
- this.generateTypes(),
43
- this.generateIndex(),
44
- ]);
40
+ await Promise.all([this.generateEnums(), this.generateTypes(), this.generateIndex()]);
45
41
  this.logComplete();
46
42
  }
47
43
  /**
@@ -50,7 +46,7 @@ class GeneratorOrchestrator {
50
46
  async generateEnums() {
51
47
  const enums = this.prismaGen.getEnums();
52
48
  const content = this.effectGen.generateEnums(enums);
53
- await this.fileManager.writeFile("enums.ts", content);
49
+ await this.fileManager.writeFile('enums.ts', content);
54
50
  }
55
51
  /**
56
52
  * Generate types.ts file
@@ -74,35 +70,33 @@ ${kyselyFields}
74
70
  });`;
75
71
  // Generate operational schemas and type exports
76
72
  const operationalSchema = this.effectGen.generateOperationalSchemas(model);
77
- const typeExports = this.effectGen.generateTypeExports(model);
73
+ const typeExports = this.effectGen.generateTypeExports(model, fields);
78
74
  return `${baseSchema}\n\n${operationalSchema}\n\n${typeExports}`;
79
75
  })
80
- .join("\n\n");
76
+ .join('\n\n');
81
77
  // Generate join table schemas
82
- const joinTableSchemas = joinTables.length > 0
83
- ? this.effectGen.generateJoinTableSchemas(joinTables)
84
- : "";
78
+ const joinTableSchemas = joinTables.length > 0 ? this.effectGen.generateJoinTableSchemas(joinTables) : '';
85
79
  // Generate DB interface with join tables
86
80
  const dbInterface = this.kyselyGen.generateDBInterface(models, joinTables);
87
81
  const content = joinTableSchemas
88
82
  ? `${header}\n\n${modelSchemas}\n\n${joinTableSchemas}\n\n${dbInterface}`
89
83
  : `${header}\n\n${modelSchemas}\n\n${dbInterface}`;
90
- await this.fileManager.writeFile("types.ts", content);
84
+ await this.fileManager.writeFile('types.ts', content);
91
85
  }
92
86
  /**
93
87
  * Generate index.ts file
94
88
  */
95
89
  async generateIndex() {
96
90
  const content = this.kyselyGen.generateIndexFile();
97
- await this.fileManager.writeFile("index.ts", content);
91
+ await this.fileManager.writeFile('index.ts', content);
98
92
  }
99
93
  /**
100
94
  * Log generation start with stats
101
95
  */
102
96
  logStart(options) {
103
- const modelCount = options.dmmf.datamodel.models.filter((m) => !m.name.startsWith("_")).length;
97
+ const modelCount = options.dmmf.datamodel.models.filter((m) => !m.name.startsWith('_')).length;
104
98
  const enumCount = options.dmmf.datamodel.enums.length;
105
- console.log("[Prisma Effect Kysely Generator] Starting generation...");
99
+ console.log('[Prisma Effect Kysely Generator] Starting generation...');
106
100
  console.log(`[Effect Generator] Processing ${modelCount} models, ${enumCount} enums`);
107
101
  }
108
102
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/generator/orchestrator.ts"],"names":[],"mappings":";;;AACA,wDAAoD;AACpD,mDAAsD;AACtD,mDAAsD;AACtD,mDAAsD;AAEtD;;;GAGG;AACH,MAAa,qBAAqB;IAMhC,YAAY,OAAyB;QACnC,MAAM,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEpD,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAW,CAAC,UAAU,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,GAAG,IAAI,2BAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,SAAS,GAAG,IAAI,2BAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,SAAS,G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D,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;IACxE,CAAC;CACF;AAhID,sDAgIC"}
@@ -12,8 +12,12 @@ export declare const GeneratedId: unique symbol;
12
12
  */
13
13
  export declare const columnType: <SType, SEncoded, SR, IType, IEncoded, IR, UType, UEncoded, UR>(selectSchema: S.Schema<SType, SEncoded, SR>, insertSchema: S.Schema<IType, IEncoded, IR>, updateSchema: S.Schema<UType, UEncoded, UR>) => S.Schema<SType, SEncoded, SR>;
14
14
  /**
15
- * Mark a field as database-generated (optional on insert)
15
+ * Mark a field as database-generated (omitted from insert)
16
16
  * Used for fields with @default
17
+ *
18
+ * Follows @effect/sql Model.Generated pattern:
19
+ * - Present in select and update schemas
20
+ * - OMITTED from insert schema (not optional, completely absent)
17
21
  */
18
22
  export declare const generated: <SType, SEncoded, R>(schema: S.Schema<SType, SEncoded, R>) => S.Schema<SType, SEncoded, R>;
19
23
  /**
@@ -22,6 +26,7 @@ export declare const generated: <SType, SEncoded, R>(schema: S.Schema<SType, SEn
22
26
  export declare const selectable: <Type, Encoded>(schema: S.Schema<Type, Encoded>) => S.Schema<Selectable<Type>, Selectable<Encoded>, never>;
23
27
  /**
24
28
  * Create insertable schema from base schema
29
+ * Filters out generated fields (@effect/sql Model.Generated pattern)
25
30
  */
26
31
  export declare const insertable: <Type, Encoded>(schema: S.Schema<Type, Encoded>) => S.Schema<Insertable<Type>, Insertable<Encoded>, never>;
27
32
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/kysely/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,eAAe,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEjE;;;GAGG;AAEH,eAAO,MAAM,YAAY,eAA8B,CAAC;AACxD,eAAO,MAAM,WAAW,eAA6B,CAAC;AActD;;;GAGG;AACH,eAAO,MAAM,UAA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AAC,IAAI,EAAE,OAAO;IACpC,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5D,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5D,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;CAC7D;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,IAAI,EAAE,OAAO,EACtC,YAAY,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,KAClC,OAAO,CAAC,IAAI,EAAE,OAAO,CAItB,CAAC;AAEH,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC;IAC3D,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3C,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3C,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;CAC5C"}
@@ -56,16 +56,15 @@ const columnType = (selectSchema, insertSchema, updateSchema) => {
56
56
  };
57
57
  exports.columnType = columnType;
58
58
  /**
59
- * Mark a field as database-generated (optional on insert)
59
+ * Mark a field as database-generated (omitted from insert)
60
60
  * Used for fields with @default
61
+ *
62
+ * Follows @effect/sql Model.Generated pattern:
63
+ * - Present in select and update schemas
64
+ * - OMITTED from insert schema (not optional, completely absent)
61
65
  */
62
66
  const generated = (schema) => {
63
- const schemas = {
64
- selectSchema: schema,
65
- insertSchema: S.Union(schema, S.Undefined),
66
- updateSchema: schema,
67
- };
68
- return schema.annotations({ [exports.GeneratedId]: schemas });
67
+ return schema.annotations({ [exports.GeneratedId]: true }); // Just a marker
69
68
  };
70
69
  exports.generated = generated;
71
70
  /**
@@ -81,14 +80,36 @@ const selectable = (schema) => {
81
80
  exports.selectable = selectable;
82
81
  /**
83
82
  * Create insertable schema from base schema
83
+ * Filters out generated fields (@effect/sql Model.Generated pattern)
84
84
  */
85
85
  const insertable = (schema) => {
86
86
  const { ast } = schema;
87
87
  if (!AST.isTypeLiteral(ast)) {
88
88
  return S.asSchema(S.make(ast));
89
89
  }
90
- const extracted = extractParametersFromTypeLiteral(ast, 'insertSchema');
91
- const res = new AST.TypeLiteral(extracted.map((prop) => new AST.PropertySignature(prop.name, prop.type, isOptionalType(prop.type), prop.isReadonly, prop.annotations)), ast.indexSignatures, ast.annotations);
90
+ // Extract and filter out generated fields entirely
91
+ const extracted = ast.propertySignatures
92
+ .map((prop) => {
93
+ if (isColumnType(prop.type)) {
94
+ const schemas = prop.type.annotations[exports.ColumnTypeId];
95
+ return new AST.PropertySignature(prop.name, schemas.insertSchema.ast, prop.isOptional, prop.isReadonly, prop.annotations);
96
+ }
97
+ // For generated fields, mark them for filtering
98
+ if (isGeneratedType(prop.type)) {
99
+ return null; // Will be filtered out
100
+ }
101
+ return prop;
102
+ })
103
+ .filter((prop) => {
104
+ // Filter out generated fields (null) and Never types
105
+ return prop !== null && prop.type._tag !== 'NeverKeyword';
106
+ })
107
+ .map((prop) => {
108
+ // Make Union(T, Undefined) fields optional
109
+ const isOptional = isOptionalType(prop.type);
110
+ return new AST.PropertySignature(prop.name, prop.type, isOptional, prop.isReadonly, prop.annotations);
111
+ });
112
+ const res = new AST.TypeLiteral(extracted, ast.indexSignatures, ast.annotations);
92
113
  return S.asSchema(S.make(res));
93
114
  };
94
115
  exports.insertable = insertable;
@@ -122,10 +143,7 @@ const extractParametersFromTypeLiteral = (ast, schemaType) => {
122
143
  const schemas = prop.type.annotations[exports.ColumnTypeId];
123
144
  return new AST.PropertySignature(prop.name, schemas[schemaType].ast, prop.isOptional, prop.isReadonly, prop.annotations);
124
145
  }
125
- if (isGeneratedType(prop.type)) {
126
- const schemas = prop.type.annotations[exports.GeneratedId];
127
- return new AST.PropertySignature(prop.name, schemas[schemaType].ast, prop.isOptional, prop.isReadonly, prop.annotations);
128
- }
146
+ // Generated fields are just markers now, return as-is
129
147
  return prop;
130
148
  })
131
149
  .filter((prop) => prop.type._tag !== 'NeverKeyword');
@@ -133,6 +151,7 @@ const extractParametersFromTypeLiteral = (ast, schemaType) => {
133
151
  const isColumnType = (ast) => exports.ColumnTypeId in ast.annotations;
134
152
  const isGeneratedType = (ast) => exports.GeneratedId in ast.annotations;
135
153
  const isOptionalType = (ast) => {
154
+ // Check for Union(T, Undefined) pattern
136
155
  if (!AST.isUnion(ast)) {
137
156
  return false;
138
157
  }
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/kysely/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAwC;AACxC,iDAAmC;AAGnC;;;GAGG;AAEU,QAAA,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC3C,QAAA,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AActD;;;GAGG;AACI,MAAM,UAAU,GAAG,CACxB,YAA2C,EAC3C,YAA2C,EAC3C,YAA2C,EAC3C,EAAE;IACF,MAAM,OAAO,GACX;QACE,YAAY;QACZ,YAAY;QACZ,YAAY;KACb,CAAC;IACJ,OAAO,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC,oBAAY,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/D,CAAC,CAAC;AAZW,QAAA,UAAU,cAYrB;AAEF;;;GAGG;AACI,MAAM,SAAS,GAAG,CAAqB,MAAoC,EAAE,EAAE;IACpF,MAAM,OAAO,GAAyC;QACpD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AG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,GAAY,EAAE,EAAE,CAClC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC;IAClB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAClC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,sBAAsB,CAAC,QAAQ,EAAE,IAAI,KAAK,KAAK,MAAM,CACpF,CAAC"}
@@ -15,4 +15,16 @@
15
15
  * toPascalCase('USER_ROLE', 'Type') // 'UserRoleType'
16
16
  */
17
17
  export declare function toPascalCase(str: string, suffix?: string): string;
18
+ /**
19
+ * Convert PascalCase or camelCase string to snake_case
20
+ * Used for generating database column names from model names
21
+ *
22
+ * @param str - The string to convert
23
+ *
24
+ * @example
25
+ * toSnakeCase('User') // 'user'
26
+ * toSnakeCase('ProductTag') // 'product_tag'
27
+ * toSnakeCase('ProductStatus') // 'product_status'
28
+ */
29
+ export declare function toSnakeCase(str: string): string;
18
30
  //# sourceMappingURL=naming.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../../src/utils/naming.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CA8BjE"}
1
+ {"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../../src/utils/naming.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CA8BjE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAY/C"}
@@ -4,6 +4,7 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.toPascalCase = toPascalCase;
7
+ exports.toSnakeCase = toSnakeCase;
7
8
  /**
8
9
  * Convert any string to PascalCase with optional suffix
9
10
  * Handles: snake_case, camelCase, kebab-case, or mixed formats
@@ -47,4 +48,26 @@ function toPascalCase(str, suffix) {
47
48
  }
48
49
  return suffix ? `${pascalCase}${suffix}` : pascalCase;
49
50
  }
51
+ /**
52
+ * Convert PascalCase or camelCase string to snake_case
53
+ * Used for generating database column names from model names
54
+ *
55
+ * @param str - The string to convert
56
+ *
57
+ * @example
58
+ * toSnakeCase('User') // 'user'
59
+ * toSnakeCase('ProductTag') // 'product_tag'
60
+ * toSnakeCase('ProductStatus') // 'product_status'
61
+ */
62
+ function toSnakeCase(str) {
63
+ if (!str)
64
+ return str;
65
+ return (str
66
+ // Insert underscore before uppercase letters (except at start)
67
+ .replace(/([A-Z])/g, '_$1')
68
+ // Remove leading underscore if present
69
+ .replace(/^_/, '')
70
+ // Convert to lowercase
71
+ .toLowerCase());
72
+ }
50
73
  //# sourceMappingURL=naming.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"naming.js","sourceRoot":"","sources":["../../src/utils/naming.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAeH,oCA8BC;AA3CD;;;;;;;;;;;;GAYG;AACH,SAAgB,YAAY,CAAC,GAAW,EAAE,MAAe;IACvD,sBAAsB;IACtB,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC;IAErB,0CAA0C;IAC1C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAEnC,IAAI,UAAkB,CAAC;IAEvB,gEAAgE;IAChE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,gDAAgD;QAChD,MAA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gB,WAAW,CAAC,GAAW;IACrC,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC;IAErB,OAAO,CACL,GAAG;QACD,+DAA+D;SAC9D,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;QAC3B,uCAAuC;SACtC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QAClB,uBAAuB;SACtB,WAAW,EAAE,CACjB,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-effect-kysely",
3
- "version": "1.8.2",
3
+ "version": "1.9.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",