prisma-effect-kysely 5.3.5 → 5.4.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,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e1a7cbc: feat: use branded ID types in implicit M:N join table schemas
8
+
9
+ Join table schemas now reference branded ID types (e.g., `ProductId`, `SellerId`) instead of raw `Schema.UUID`/`Schema.String`/`Schema.Number`. This means Kysely queries on implicit many-to-many join tables return properly branded types, eliminating the need for manual `Schema.decodeSync` workarounds at query sites.
10
+
11
+ Before:
12
+
13
+ ```typescript
14
+ columnType(Schema.UUID, Schema.Never, Schema.Never);
15
+ ```
16
+
17
+ After:
18
+
19
+ ```typescript
20
+ columnType(ProductId, Schema.Never, Schema.Never);
21
+ ```
22
+
23
+ The branded ID schemas are guaranteed to exist in the generated output because they are emitted during model schema generation, which runs before join table generation.
24
+
3
25
  ## 5.3.5
4
26
 
5
27
  ### Patch Changes
@@ -12,7 +12,7 @@ import type { JoinTableInfo } from '../prisma/relation.js';
12
12
  * Example:
13
13
  * - Database columns: A, B (Prisma requirement for implicit many-to-many)
14
14
  * - TypeScript fields: product_id, product_tag_id (semantic names)
15
- * - Types: columnType(Schema.UUID, Schema.Never, Schema.Never) (read-only)
15
+ * - Types: columnType(ProductId, Schema.Never, Schema.Never) (read-only, branded)
16
16
  */
17
- export declare function generateJoinTableSchema(joinTable: JoinTableInfo, dmmf: DMMF.Document): string;
17
+ export declare function generateJoinTableSchema(joinTable: JoinTableInfo, _dmmf: DMMF.Document): string;
18
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;AAI3D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,UA0CpF"}
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;AAG3D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,UA6BrF"}
@@ -1,4 +1,3 @@
1
- import { isUuidField } from '../prisma/type.js';
2
1
  import { toPascalCase, toSnakeCase } from '../utils/naming.js';
3
2
  /**
4
3
  * Generate Effect Schema for an implicit many-to-many join table
@@ -12,25 +11,17 @@ import { toPascalCase, toSnakeCase } from '../utils/naming.js';
12
11
  * Example:
13
12
  * - Database columns: A, B (Prisma requirement for implicit many-to-many)
14
13
  * - TypeScript fields: product_id, product_tag_id (semantic names)
15
- * - Types: columnType(Schema.UUID, Schema.Never, Schema.Never) (read-only)
14
+ * - Types: columnType(ProductId, Schema.Never, Schema.Never) (read-only, branded)
16
15
  */
17
- export function generateJoinTableSchema(joinTable, dmmf) {
16
+ export function generateJoinTableSchema(joinTable, _dmmf) {
18
17
  const { tableName, relationName, modelA, modelB } = joinTable;
19
18
  // Generate semantic snake_case field names from model names
20
19
  // e.g., "Product" -> "product_id", "ProductTag" -> "product_tag_id"
21
20
  const columnAFieldName = `${toSnakeCase(modelA)}_id`;
22
21
  const columnBFieldName = `${toSnakeCase(modelB)}_id`;
23
- // Get ID field types for each model
24
- const modelADef = dmmf.datamodel.models.find((m) => m.name === modelA);
25
- const modelBDef = dmmf.datamodel.models.find((m) => m.name === modelB);
26
- const modelAIdField = modelADef?.fields.find((f) => f.isId);
27
- const modelBIdField = modelBDef?.fields.find((f) => f.isId);
28
- // Determine base schema type for each ID field
29
- const modelABaseType = modelAIdField && isUuidField(modelAIdField) ? 'Schema.UUID' : 'Schema.String';
30
- const modelBBaseType = modelBIdField && isUuidField(modelBIdField) ? 'Schema.UUID' : 'Schema.String';
31
- // Handle Int ID fields
32
- const modelASchemaType = modelAIdField?.type === 'Int' ? 'Schema.Number' : modelABaseType;
33
- const modelBSchemaType = modelBIdField?.type === 'Int' ? 'Schema.Number' : modelBBaseType;
22
+ // Reference branded ID schemas (e.g., ProductId, SellerId) generated earlier in the output
23
+ const modelASchemaType = `${toPascalCase(modelA)}Id`;
24
+ const modelBSchemaType = `${toPascalCase(modelB)}Id`;
34
25
  // Use columnType for read-only FK fields (can't insert/update join table rows directly)
35
26
  // Schema.propertySignature + Schema.fromKey maps TypeScript name to database column
36
27
  const columnAField = ` ${columnAFieldName}: Schema.propertySignature(columnType(${modelASchemaType}, Schema.Never, Schema.Never)).pipe(Schema.fromKey("A"))`;
@@ -1 +1 @@
1
- {"version":3,"file":"join-table.js","sourceRoot":"","sources":["../../src/effect/join-table.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAwB,EAAE,IAAmB;IACnF,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAE9D,4DAA4D;IAC5D,oEAAoE;IACpE,MAAM,gBAAgB,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;IACrD,MAAM,gBAAgB,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;IAErD,oCAAoC;IACpC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS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ACpD,OAAO,MAAM,SAAS;0BACE,MAAM,SAAS,MAAM;wBACvB,gBAAgB,KAAK,gBAAgB;eAC9C,UAAU;EACvB,YAAY;EACZ,YAAY;;cAEA,UAAU,aAAa,UAAU,GAAG,CAAC;AACnD,CAAC"}
1
+ {"version":3,"file":"join-table.js","sourceRoot":"","sources":["../../src/effect/join-table.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAwB,EAAE,KAAoB;IACpF,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAE9D,4DAA4D;IAC5D,oEAAoE;IACpE,MAAM,gBAAgB,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;IACrD,MAAM,gBAAgB,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;IAErD,2FAA2F;IAC3F,MAAM,gBAAgB,GAAG,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC;IACrD,MAAM,gBAAgB,GAAG,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC;IAErD,wFAAwF;IACxF,oFAAoF;IACpF,MAAM,YAAY,GAAG,KAAK,gBAAgB,yCAAyC,gBAAgB,0DAA0D,CAAC;IAC9J,MAAM,YAAY,GAAG,KAAK,gBAAgB,yCAAyC,gBAAgB,0DAA0D,CAAC;IAE9J,oEAAoE;IACpE,MAAM,UAAU,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAE9C,oDAAoD;IACpD,OAAO,MAAM,SAAS;0BACE,MAAM,SAAS,MAAM;wBACvB,gBAAgB,KAAK,gBAAgB;eAC9C,UAAU;EACvB,YAAY;EACZ,YAAY;;cAEA,UAAU,aAAa,UAAU,GAAG,CAAC;AACnD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-effect-kysely",
3
- "version": "5.3.5",
3
+ "version": "5.4.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",