prisma-effect-kysely 5.8.0 → 5.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
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5f07c8f: fix: regular tables in DB interface use `Schema.Schema.Type`, join tables use `Schema.Schema.Encoded`
8
+
9
+ 5.7.0 flipped the DB interface to `Schema.Schema.Encoded` for **all** tables to fix the join-table column-name bug (`_product_tags.product_id` was decoded-name; SQL needs `A`). That was the right fix for join tables but accidentally **stripped branded IDs** for regular tables — `Schema.Schema.Encoded<typeof X>` strips `Schema.brand(...)` because brands live on the Type side.
10
+
11
+ Concrete consequence: every Kysely consumer queried `result.seller_id: string` instead of `result.seller_id: string & Brand<"SellerId">`. Branded ID type safety silently disabled across the entire monorepo.
12
+
13
+ Fix: the two table categories need different treatment.
14
+ - **Regular tables**: `Schema.Schema.Type<typeof X>` — preserves branded IDs (`string & Brand<"SellerId">`) and the `ColumnType<S, I, U>` `__select__`/`__insert__`/`__update__` phantoms. Type === Encoded for column names anyway because regular tables don't use `Schema.fromKey`.
15
+ - **Join tables**: `Schema.Schema.Encoded<typeof X>` — only join tables use `Schema.fromKey('A')` to remap DB columns `A`/`B` to semantic names. Type would expose the decoded names that Kysely passes to SQL verbatim → "column does not exist". Encoded preserves real column names.
16
+
17
+ Effectively: pick the side that matches the _intended consumer view_. For non-`fromKey` tables, that's the Type side (richer info, brand info preserved). For `fromKey` tables, that's the Encoded side (matches DB).
18
+
19
+ **Migration**: regular-table consumers regain `Brand<...>` IDs immediately. Join-table consumers (`_product_tags.A`/`B` queries) unchanged from 5.7.0 — those still expose real DB column names.
20
+
3
21
  ## 5.8.0
4
22
 
5
23
  ### Minor Changes
@@ -32,20 +32,22 @@ export declare function buildKyselyFieldType(baseFieldType: string, field: DMMF.
32
32
  /**
33
33
  * Generate DB interface entry for a model
34
34
  *
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).
35
+ * Uses Schema.Schema.Type<Model> for regular tables. The Type side
36
+ * preserves branded IDs (e.g. `string & Brand<"SellerId">`), which is
37
+ * what Kysely's Selectable/Insertable/Updateable consumers want.
39
38
  *
40
- * For regular tables: Type === Encoded, behavior unchanged.
39
+ * Regular tables don't use Schema.fromKey, so `Type === Encoded` for
40
+ * column names — both shapes have the same key structure. The
41
+ * difference is at the leaf level: Type preserves brands and refinements,
42
+ * Encoded strips them. For a SQL contract, brand info is harmless and
43
+ * useful (Kysely passes it through to consumers).
41
44
  *
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
+ * Join tables are different see generateJoinTableDBInterfaceEntry —
46
+ * because they use Schema.fromKey to remap column names, and only
47
+ * Encoded preserves the real DB column names.
45
48
  *
46
49
  * 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.
50
+ * phantom properties on both sides, so INSERT/UPDATE inference works.
49
51
  */
50
52
  export declare function generateDBInterfaceEntry(model: DMMF.Model): string;
51
53
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/kysely/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAI3D;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,WAEhD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAA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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;;;;;;;;;;;;;;;;;;;GAmBG;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"}
@@ -63,25 +63,27 @@ export function buildKyselyFieldType(baseFieldType, field, modelName) {
63
63
  /**
64
64
  * Generate DB interface entry for a model
65
65
  *
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).
66
+ * Uses Schema.Schema.Type<Model> for regular tables. The Type side
67
+ * preserves branded IDs (e.g. `string & Brand<"SellerId">`), which is
68
+ * what Kysely's Selectable/Insertable/Updateable consumers want.
70
69
  *
71
- * For regular tables: Type === Encoded, behavior unchanged.
70
+ * Regular tables don't use Schema.fromKey, so `Type === Encoded` for
71
+ * column names — both shapes have the same key structure. The
72
+ * difference is at the leaf level: Type preserves brands and refinements,
73
+ * Encoded strips them. For a SQL contract, brand info is harmless and
74
+ * useful (Kysely passes it through to consumers).
72
75
  *
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
+ * Join tables are different see generateJoinTableDBInterfaceEntry —
77
+ * because they use Schema.fromKey to remap column names, and only
78
+ * Encoded preserves the real DB column names.
76
79
  *
77
80
  * 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.
81
+ * phantom properties on both sides, so INSERT/UPDATE inference works.
80
82
  */
81
83
  export function generateDBInterfaceEntry(model) {
82
84
  const tableName = model.dbName || model.name;
83
85
  const modelName = toPascalCase(model.name);
84
- return ` ${tableName}: Schema.Schema.Encoded<typeof ${modelName}>;`;
86
+ return ` ${tableName}: Schema.Schema.Type<typeof ${modelName}>;`;
85
87
  }
86
88
  /**
87
89
  * Generate DB interface entry for a join table
@@ -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,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB,EAAE,KAAiB,EAAE,SAAkB;IACzF,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,yEAAyE;QACzE,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QACtE,OAAO,cAAc,MAAM,+BAA+B,CAAC;IAC7D,CAAC;SAAM,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO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AS,+BAA+B,SAAS,IAAI,CAAC;AACpE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iCAAiC,CAAC,SAAwB;IACxE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC;IAC9C,MAAM,UAAU,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC9C,OAAO,KAAK,SAAS,kCAAkC,UAAU,IAAI,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA6B,EAC7B,aAA8B,EAAE;IAEhC,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjF,MAAM,gBAAgB,GACpB,UAAU,CAAC,MAAM,GAAG,CAAC;QACnB,CAAC,CAAC,KAAK,UAAU,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACrE,CAAC,CAAC,EAAE,CAAC;IAET,OAAO;;EAEP,YAAY,GAAG,gBAAgB;EAC/B,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-effect-kysely",
3
- "version": "5.8.0",
3
+ "version": "5.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",