prisma-effect-kysely 5.6.0 → 5.7.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
@@ -1,5 +1,42 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d272b99: fix: DB interface uses `Schema.Schema.Encoded` so Kysely sees real DB columns
8
+
9
+ The generated `interface DB` previously emitted
10
+ `<table>: Schema.Schema.Type<typeof X>`. For tables using `Schema.fromKey`
11
+ (Prisma implicit M:N join tables, where TS field `product_id` maps to DB
12
+ column `A`), the Type side has the **decoded** names. Kysely uses the TS
13
+ interface as the SQL contract — it does not run the Effect schema decoder.
14
+ So queries like `db.selectFrom('_product_tags').where('product_id', ...)`
15
+ generated `WHERE product_id = ...` and Postgres rejected with
16
+ `column _product_tags.product_id does not exist`.
17
+
18
+ Fix: emit `Schema.Schema.Encoded<typeof X>` for every DB interface entry.
19
+ Encoded is the on-the-wire / on-disk shape that matches Postgres. For
20
+ regular tables `Type === Encoded`, no behavior change. For join tables,
21
+ Kysely now sees `A`/`B` and emits valid SQL. Application code that wants
22
+ the semantic field names runs the row through `Schema.decode(X)`.
23
+
24
+ `ColumnType<S, I, U>` brand preserves `__select__`/`__insert__`/`__update__`
25
+ phantoms on both sides, so `Insertable<X>`/`Updateable<X>` inference is
26
+ unchanged.
27
+
28
+ Adds `db-interface-sql-contract.test.ts` with three regression checks:
29
+ 1. String-grep — every DB entry uses Encoded, none use Type.
30
+ 2. Encoded-side preserves real Postgres column names for implicit M:N.
31
+ 3. Kysely SQL compile — emitted SQL references the real `"A"` column,
32
+ not the `product_id` decoded name. This catches the original bug
33
+ structurally without needing a live database.
34
+
35
+ **Migration**: most consumers need no changes. If a consumer overrode
36
+ the generated DB interface entry to expose `A`/`B` directly (workaround
37
+ for this bug), the override can now be removed and the generator will
38
+ do the right thing.
39
+
3
40
  ## 5.6.0
4
41
 
5
42
  ### Minor Changes
@@ -31,16 +31,32 @@ export declare function applyMapDirective(fieldType: string, field: DMMF.Field):
31
31
  export declare function buildKyselyFieldType(baseFieldType: string, field: DMMF.Field, modelName?: string): string;
32
32
  /**
33
33
  * Generate DB interface entry for a model
34
- * Uses Schema.Schema.Type<Model> to preserve phantom properties (__select__, __insert__, __update__)
35
- * that Kysely needs for correct INSERT/UPDATE type inference.
36
34
  *
37
- * Previously used Selectable<Model> but this stripped the phantom properties,
38
- * causing Kysely to require all fields on INSERT (including generated/read-only fields).
35
+ * Uses Schema.Schema.Encoded<Model> because the DB interface IS the SQL
36
+ * contract column names and types must match what Postgres actually
37
+ * sees. Encoded is the on-the-wire / on-disk shape; Type is the decoded
38
+ * runtime shape after `Schema.decode` (which Kysely never runs).
39
+ *
40
+ * For regular tables: Type === Encoded, behavior unchanged.
41
+ *
42
+ * For tables using Schema.fromKey/propertySignature (e.g. Prisma implicit
43
+ * M:N join tables where TS field `product_id` maps to DB column `A`),
44
+ * Encoded preserves the real DB column names so Kysely emits valid SQL.
45
+ *
46
+ * ColumnType<S, I, U> brand preserves the __select__/__insert__/__update__
47
+ * phantom properties on both sides (Type and Encoded), so INSERT/UPDATE
48
+ * type inference still works correctly.
39
49
  */
40
50
  export declare function generateDBInterfaceEntry(model: DMMF.Model): string;
41
51
  /**
42
52
  * Generate DB interface entry for a join table
43
- * Uses Schema.Schema.Type to preserve phantom properties for Kysely compatibility
53
+ *
54
+ * Critical: must use Schema.Schema.Encoded so the Kysely DB interface
55
+ * exposes Prisma's real `A`/`B` column names. Schema.fromKey mapping
56
+ * (`product_id` -> `A`) only applies during Effect Schema decode/encode;
57
+ * Kysely passes column names directly to Postgres, so the TS interface
58
+ * has to match the DB exactly. Decode through the Effect schema in
59
+ * application code if you want the semantic field names.
44
60
  */
45
61
  export declare function generateJoinTableDBInterfaceEntry(joinTable: JoinTableInfo): string;
46
62
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../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CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,WAE/C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,MAAM,UAc1F;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,UAMrE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,MAAM,UAQhG;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,UAIzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAAC,SAAS,EAAE,aAAa,UAIzE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,IAAI,CAAC,KAAK,EAAE,EAC7B,UAAU,GAAE,aAAa,EAAO,UAajC"}
@@ -62,25 +62,41 @@ export function buildKyselyFieldType(baseFieldType, field, modelName) {
62
62
  }
63
63
  /**
64
64
  * Generate DB interface entry for a model
65
- * Uses Schema.Schema.Type<Model> to preserve phantom properties (__select__, __insert__, __update__)
66
- * that Kysely needs for correct INSERT/UPDATE type inference.
67
65
  *
68
- * Previously used Selectable<Model> but this stripped the phantom properties,
69
- * causing Kysely to require all fields on INSERT (including generated/read-only fields).
66
+ * Uses Schema.Schema.Encoded<Model> because the DB interface IS the SQL
67
+ * contract column names and types must match what Postgres actually
68
+ * sees. Encoded is the on-the-wire / on-disk shape; Type is the decoded
69
+ * runtime shape after `Schema.decode` (which Kysely never runs).
70
+ *
71
+ * For regular tables: Type === Encoded, behavior unchanged.
72
+ *
73
+ * For tables using Schema.fromKey/propertySignature (e.g. Prisma implicit
74
+ * M:N join tables where TS field `product_id` maps to DB column `A`),
75
+ * Encoded preserves the real DB column names so Kysely emits valid SQL.
76
+ *
77
+ * ColumnType<S, I, U> brand preserves the __select__/__insert__/__update__
78
+ * phantom properties on both sides (Type and Encoded), so INSERT/UPDATE
79
+ * type inference still works correctly.
70
80
  */
71
81
  export function generateDBInterfaceEntry(model) {
72
82
  const tableName = model.dbName || model.name;
73
83
  const modelName = toPascalCase(model.name);
74
- return ` ${tableName}: Schema.Schema.Type<typeof ${modelName}>;`;
84
+ return ` ${tableName}: Schema.Schema.Encoded<typeof ${modelName}>;`;
75
85
  }
76
86
  /**
77
87
  * Generate DB interface entry for a join table
78
- * Uses Schema.Schema.Type to preserve phantom properties for Kysely compatibility
88
+ *
89
+ * Critical: must use Schema.Schema.Encoded so the Kysely DB interface
90
+ * exposes Prisma's real `A`/`B` column names. Schema.fromKey mapping
91
+ * (`product_id` -> `A`) only applies during Effect Schema decode/encode;
92
+ * Kysely passes column names directly to Postgres, so the TS interface
93
+ * has to match the DB exactly. Decode through the Effect schema in
94
+ * application code if you want the semantic field names.
79
95
  */
80
96
  export function generateJoinTableDBInterfaceEntry(joinTable) {
81
97
  const { tableName, relationName } = joinTable;
82
98
  const schemaName = toPascalCase(relationName);
83
- return ` ${tableName}: Schema.Schema.Type<typeof ${schemaName}>;`;
99
+ return ` ${tableName}: Schema.Schema.Encoded<typeof ${schemaName}>;`;
84
100
  }
85
101
  /**
86
102
  * Generate complete DB interface including join tables
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/kysely/type.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AACpD,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CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-effect-kysely",
3
- "version": "5.6.0",
3
+ "version": "5.7.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",