prisma-effect-kysely 1.3.1 → 1.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 +52 -19
- package/README.md +6 -0
- package/dist/effect/generator.d.ts.map +1 -1
- package/dist/effect/generator.js +3 -2
- package/dist/effect/generator.js.map +1 -1
- package/dist/generator/index.js +1 -1
- package/dist/utils/naming.d.ts +15 -0
- package/dist/utils/naming.d.ts.map +1 -0
- package/dist/utils/naming.js +41 -0
- package/dist/utils/naming.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,38 +5,71 @@ 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
|
+
## [1.4.0] - 2025-10-09
|
|
9
9
|
|
|
10
|
-
###
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **Naming Standardization** - All exported schemas and types now use PascalCase regardless of Prisma model naming convention
|
|
13
|
+
- Fixes inconsistent naming when models use snake_case (e.g., `session_model_preference`)
|
|
14
|
+
- Generated exports: `SessionModelPreference`, `SessionModelPreferenceSelect`, etc. (instead of `session_model_preferenceSelect`)
|
|
15
|
+
- Internal base schemas preserve original names with underscore prefix (e.g., `_session_model_preference`)
|
|
16
|
+
- Applies to operational schemas and all type exports (Select, Insert, Update, Encoded variants)
|
|
17
|
+
|
|
18
|
+
### Added
|
|
11
19
|
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- Fixes compatibility with Effect 3.18.4 where `never` type was propagating through all generated types
|
|
16
|
-
- No breaking changes - all existing functionality preserved
|
|
20
|
+
- New `toPascalCase()` utility function for consistent TypeScript identifier generation
|
|
21
|
+
- Comprehensive tests for naming conversion (handles snake_case, kebab-case, camelCase, PascalCase)
|
|
22
|
+
- Test fixture `session_model_preference` to verify snake_case handling
|
|
17
23
|
|
|
18
24
|
### Technical Details
|
|
19
25
|
|
|
20
|
-
The
|
|
26
|
+
The generator now converts all model names to PascalCase when creating TypeScript exports using the new `toPascalCase()` utility. This ensures consistent, idiomatic TypeScript naming while preserving the original Prisma model names for internal schemas. The conversion handles snake_case, kebab-case, camelCase, and mixed formats.
|
|
27
|
+
|
|
28
|
+
**Impact**: Projects using snake_case model names will see different export names (breaking change for those projects). Projects using PascalCase models (recommended Prisma convention) will see no changes.
|
|
21
29
|
|
|
22
30
|
**Changed files:**
|
|
23
|
-
- `src/
|
|
24
|
-
- `src/
|
|
31
|
+
- `src/utils/naming.ts`: New naming utility
|
|
32
|
+
- `src/effect/generator.ts`: Updated to use PascalCase for all exports
|
|
33
|
+
- `src/__tests__/fixtures/test.prisma`: Added snake_case test model
|
|
34
|
+
- `src/__tests__/naming.test.ts`: New tests for naming utility
|
|
35
|
+
- `src/__tests__/generator.test.ts`: Added naming standardization tests
|
|
25
36
|
|
|
26
|
-
[1.
|
|
37
|
+
[1.4.0]: https://github.com/samuelho-dev/prisma-effect-kysely/compare/v1.3.1...v1.4.0
|
|
27
38
|
|
|
28
|
-
## [1.3.0] - 2025-
|
|
39
|
+
## [1.3.0] - 2025-01-09
|
|
29
40
|
|
|
30
|
-
###
|
|
41
|
+
### Added
|
|
31
42
|
|
|
32
|
-
- **
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
43
|
+
- **Encoded type exports** - Generator now exports database-encoded types alongside application types
|
|
44
|
+
- `{Model}SelectEncoded` - Database-encoded type for `Schema.Schema.Encoded<typeof Model.Selectable>`
|
|
45
|
+
- `{Model}InsertEncoded` - Database-encoded type for `Schema.Schema.Encoded<typeof Model.Insertable>`
|
|
46
|
+
- `{Model}UpdateEncoded` - Database-encoded type for `Schema.Schema.Encoded<typeof Model.Updateable>`
|
|
47
|
+
- Comprehensive test coverage for Encoded type exports
|
|
36
48
|
|
|
37
|
-
###
|
|
49
|
+
### Changed
|
|
50
|
+
|
|
51
|
+
- `generateTypeExports()` method now generates both Application and Encoded type exports
|
|
52
|
+
- Queries layer can now use proper Encoded types instead of `any` workarounds
|
|
53
|
+
|
|
54
|
+
### Why This Matters
|
|
55
|
+
|
|
56
|
+
Effect Schema has bidirectional transformations:
|
|
57
|
+
- **Application types** (`Schema.Schema.Type`) - Decoded types with `Date` objects (for repository layer)
|
|
58
|
+
- **Database types** (`Schema.Schema.Encoded`) - Encoded types with ISO strings (for queries layer)
|
|
59
|
+
|
|
60
|
+
Previously, only Application types were exported, forcing queries to use `any` types. Now both sides of the transformation are properly typed.
|
|
61
|
+
|
|
62
|
+
**Example Usage:**
|
|
63
|
+
```typescript
|
|
64
|
+
import { agentInsertEncoded } from '@libs/types';
|
|
65
|
+
|
|
66
|
+
// Queries layer - uses Encoded types (ISO strings)
|
|
67
|
+
insert: (rowData: agentInsertEncoded) => db.insertInto('agent').values(rowData)
|
|
38
68
|
|
|
39
|
-
|
|
69
|
+
// Repository layer - uses Application types (Date objects)
|
|
70
|
+
const input: CreateAgentInput = { /* ... Date objects ... */ };
|
|
71
|
+
const encoded = Schema.encode(AgentSchemas.Insertable)(input); // Encoded to ISO strings
|
|
72
|
+
```
|
|
40
73
|
|
|
41
74
|
[1.3.0]: https://github.com/samuelho-dev/prisma-effect-kysely/compare/v1.2.1...v1.3.0
|
|
42
75
|
|
package/README.md
CHANGED
|
@@ -65,6 +65,12 @@ export const User = Schema.Struct({
|
|
|
65
65
|
export type User = Schema.Schema.Type<typeof User>;
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
+
**Naming Convention**: All exported schemas and types use PascalCase, regardless of the Prisma model naming convention:
|
|
69
|
+
- Model `User` → `User`, `UserSelect`, `UserInsert`
|
|
70
|
+
- Model `session_preference` → `SessionPreference`, `SessionPreferenceSelect`, `SessionPreferenceInsert`
|
|
71
|
+
|
|
72
|
+
This ensures consistent TypeScript identifier naming while preserving the original model names for internal schemas.
|
|
73
|
+
|
|
68
74
|
### index.ts
|
|
69
75
|
|
|
70
76
|
Re-exports all generated types for easy importing
|
|
@@ -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;
|
|
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;;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;IAiBrC;;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"}
|
package/dist/effect/generator.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EffectGenerator = void 0;
|
|
4
4
|
const enum_1 = require("./enum");
|
|
5
5
|
const type_1 = require("./type");
|
|
6
|
+
const naming_1 = require("../utils/naming");
|
|
6
7
|
/**
|
|
7
8
|
* Effect domain generator - orchestrates Effect Schema generation
|
|
8
9
|
*/
|
|
@@ -37,14 +38,14 @@ ${fieldDefinitions}
|
|
|
37
38
|
*/
|
|
38
39
|
generateOperationalSchemas(model) {
|
|
39
40
|
const baseSchemaName = `_${model.name}`;
|
|
40
|
-
const operationalSchemaName = model.name;
|
|
41
|
+
const operationalSchemaName = (0, naming_1.toPascalCase)(model.name);
|
|
41
42
|
return `export const ${operationalSchemaName} = getSchemas(${baseSchemaName});`;
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
45
|
* Generate TypeScript type exports
|
|
45
46
|
*/
|
|
46
47
|
generateTypeExports(model) {
|
|
47
|
-
const name = model.name;
|
|
48
|
+
const name = (0, naming_1.toPascalCase)(model.name);
|
|
48
49
|
// Application-side types (decoded - for repository layer)
|
|
49
50
|
const applicationTypes = `export type ${name}Select = Schema.Schema.Type<typeof ${name}.Selectable>;
|
|
50
51
|
export type ${name}Insert = Schema.Schema.Type<typeof ${name}.Insertable>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/effect/generator.ts"],"names":[],"mappings":";;;AACA,iCAA2C;AAC3C,iCAAwC;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/effect/generator.ts"],"names":[],"mappings":";;;AACA,iCAA2C;AAC3C,iCAAwC;AAExC,4CAA+C;AAE/C;;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,KA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CAAC,CAAC;QAEpD,OAAO,GAAG,UAAU,OAAO,iBAAiB,OAAO,WAAW,EAAE,CAAC;IACnE,CAAC;IAED;;OAEG;IACH,mBAAmB,CAAC,QAAiB;QACnC,MAAM,MAAM,GAAG;gBACH,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;;IAEpC,CAAC;QAED,MAAM,OAAO,GAAG;YACd,kCAAkC;YAClC,2EAA2E;SAC5E,CAAC;QAEF,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1E,OAAO,CAAC,IAAI,CAAC,YAAY,SAAS,oBAAoB,CAAC,CAAC;QAC1D,CAAC;QAED,OAAO,GAAG,MAAM,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC9C,CAAC;CACF;AA3FD,0CA2FC"}
|
package/dist/generator/index.js
CHANGED
|
@@ -22,7 +22,7 @@ const orchestrator_1 = require("./orchestrator");
|
|
|
22
22
|
__exportStar(require("../kysely/helpers"), exports);
|
|
23
23
|
exports.generator = (0, generator_helper_1.generatorHandler)({
|
|
24
24
|
onManifest: () => ({
|
|
25
|
-
version: '1.
|
|
25
|
+
version: '1.4.0',
|
|
26
26
|
defaultOutput: './generated',
|
|
27
27
|
prettyName: 'Prisma Effect Kysely Generator',
|
|
28
28
|
}),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naming utilities for consistent TypeScript identifier generation
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Convert any string to PascalCase for TypeScript type names
|
|
6
|
+
* Handles: snake_case, camelCase, kebab-case, or mixed formats
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* toPascalCase('user') // 'User'
|
|
10
|
+
* toPascalCase('session_model_preference') // 'SessionModelPreference'
|
|
11
|
+
* toPascalCase('user-profile') // 'UserProfile'
|
|
12
|
+
* toPascalCase('userProfile') // 'UserProfile'
|
|
13
|
+
*/
|
|
14
|
+
export declare function toPascalCase(str: string): string;
|
|
15
|
+
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../../src/utils/naming.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAyBhD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Naming utilities for consistent TypeScript identifier generation
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toPascalCase = toPascalCase;
|
|
7
|
+
/**
|
|
8
|
+
* Convert any string to PascalCase for TypeScript type names
|
|
9
|
+
* Handles: snake_case, camelCase, kebab-case, or mixed formats
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* toPascalCase('user') // 'User'
|
|
13
|
+
* toPascalCase('session_model_preference') // 'SessionModelPreference'
|
|
14
|
+
* toPascalCase('user-profile') // 'UserProfile'
|
|
15
|
+
* toPascalCase('userProfile') // 'UserProfile'
|
|
16
|
+
*/
|
|
17
|
+
function toPascalCase(str) {
|
|
18
|
+
// Handle empty string
|
|
19
|
+
if (!str)
|
|
20
|
+
return str;
|
|
21
|
+
// Split on underscores, dashes, or spaces
|
|
22
|
+
const words = str.split(/[_-\s]+/);
|
|
23
|
+
// If no delimiters found, check if already camelCase/PascalCase
|
|
24
|
+
if (words.length === 1) {
|
|
25
|
+
// Split camelCase/PascalCase by capital letters
|
|
26
|
+
const camelWords = str.split(/(?=[A-Z])/);
|
|
27
|
+
if (camelWords.length > 1) {
|
|
28
|
+
return camelWords
|
|
29
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
30
|
+
.join('');
|
|
31
|
+
}
|
|
32
|
+
// Single word - just capitalize first letter
|
|
33
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
34
|
+
}
|
|
35
|
+
// Convert each word to PascalCase
|
|
36
|
+
return words
|
|
37
|
+
.filter((word) => word.length > 0) // Remove empty strings
|
|
38
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
39
|
+
.join('');
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=naming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.js","sourceRoot":"","sources":["../../src/utils/naming.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAYH,oCAyBC;AAnCD;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAAC,GAAW;IACtC,sBAAsB;IACtB,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC;IAErB,0CAA0C;IAC1C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAEnC,gEAAgE;IAChE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,gDAAgD;QAChD,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC1C,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,UAAU;iBACd,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;iBACzE,IAAI,CAAC,EAAE,CAAC,CAAC;QACd,CAAC;QACD,6CAA6C;QAC7C,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAA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