prisma-effect-kysely 3.0.0 → 3.0.2
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 +45 -0
- package/dist/kysely/helpers.d.ts +56 -8
- package/dist/kysely/helpers.d.ts.map +1 -1
- package/dist/kysely/helpers.js +12 -4
- package/dist/kysely/helpers.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b2edf54`](https://github.com/samuelho-dev/prisma-effect-kysely/commit/b2edf54230d73a4e600aecdd9980f7915ea53f62) Thanks [@samuelho-dev](https://github.com/samuelho-dev)! - Fix: Exclude Never-typed fields from Insertable/Updateable at compile-time
|
|
8
|
+
|
|
9
|
+
The `columnType` function now returns a `ColumnTypeSchema` type with phantom type properties that encode the insert/update type constraints. The `Insertable<T>` and `Updateable<T>` type utilities use these phantom types to correctly exclude `never`-typed fields at the TypeScript type level.
|
|
10
|
+
|
|
11
|
+
**Changes:**
|
|
12
|
+
- `columnType()` now returns `ColumnTypeSchema<S, E, R, I, U>` with phantom types for insert/update
|
|
13
|
+
- `getSchemas()` now stores the base schema in `_base` property for type-level field extraction
|
|
14
|
+
- `Insertable<T>` and `Updateable<T>` type utilities compute correct types by:
|
|
15
|
+
- Extracting struct fields from `_base` schema
|
|
16
|
+
- Filtering out fields with `never` phantom types
|
|
17
|
+
- Computing the correct insert/update type per field
|
|
18
|
+
|
|
19
|
+
**Example:**
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
const _User = Schema.Struct({
|
|
23
|
+
id: columnType(Schema.UUID, Schema.Never, Schema.Never),
|
|
24
|
+
name: Schema.String,
|
|
25
|
+
});
|
|
26
|
+
const User = getSchemas(_User);
|
|
27
|
+
|
|
28
|
+
// At compile-time:
|
|
29
|
+
type UserInsert = Insertable<typeof User>;
|
|
30
|
+
// = { name: string } // 'id' correctly excluded
|
|
31
|
+
|
|
32
|
+
type UserUpdate = Updateable<typeof User>;
|
|
33
|
+
// = { name?: string } // 'id' correctly excluded
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 3.0.1
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- [`57771ff`](https://github.com/samuelho-dev/prisma-effect-kysely/commit/57771ff954fcf8796d8e2ad7fefd5dc5f6ce51fb) Thanks [@samuelho-dev](https://github.com/samuelho-dev)! - Fix: Exclude Never-typed fields from Updateable and Insertable schemas
|
|
41
|
+
|
|
42
|
+
Previously, fields with `columnType(T, Schema.Never, Schema.Never)` were incorrectly included in Updateable/Insertable schemas because `Schema.mutable()` wrapped the Never type in a Transformation node, changing the AST tag from `'NeverKeyword'` to `'Transformation'`. The filter at line 155 checked for `'NeverKeyword'` but couldn't detect the wrapped Never type.
|
|
43
|
+
|
|
44
|
+
**Fix**: Check for `AST.isNeverKeyword(targetSchema.ast)` before applying the `Schema.mutable()` transformation, then filter out null values.
|
|
45
|
+
|
|
46
|
+
This ensures read-only ID fields like `id: columnType(Schema.UUID, Schema.Never, Schema.Never)` are properly excluded from update and insert operations, maintaining Kysely's type safety guarantees.
|
|
47
|
+
|
|
3
48
|
## 3.0.0
|
|
4
49
|
|
|
5
50
|
### Major Changes
|
package/dist/kysely/helpers.d.ts
CHANGED
|
@@ -7,11 +7,31 @@ import type { DeepMutable } from 'effect/Types';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const ColumnTypeId: unique symbol;
|
|
9
9
|
export declare const GeneratedId: unique symbol;
|
|
10
|
+
declare const ColumnTypeInsertPhantom: unique symbol;
|
|
11
|
+
declare const ColumnTypeUpdatePhantom: unique symbol;
|
|
12
|
+
/**
|
|
13
|
+
* A schema with phantom types encoding insert/update type constraints.
|
|
14
|
+
* This allows TypeScript to know at compile time which fields have
|
|
15
|
+
* `never` insert/update types and should be excluded.
|
|
16
|
+
*/
|
|
17
|
+
export type ColumnTypeSchema<SType, SEncoded, SR, IType, UType> = Schema.Schema<SType, SEncoded, SR> & {
|
|
18
|
+
readonly [ColumnTypeInsertPhantom]: IType;
|
|
19
|
+
readonly [ColumnTypeUpdatePhantom]: UType;
|
|
20
|
+
};
|
|
21
|
+
type ExtractInsertPhantom<T> = T extends {
|
|
22
|
+
readonly [ColumnTypeInsertPhantom]: infer I;
|
|
23
|
+
} ? I : T extends Schema.Schema<infer S, unknown, unknown> ? S : never;
|
|
24
|
+
type ExtractUpdatePhantom<T> = T extends {
|
|
25
|
+
readonly [ColumnTypeUpdatePhantom]: infer U;
|
|
26
|
+
} ? U : T extends Schema.Schema<infer S, unknown, unknown> ? S : never;
|
|
10
27
|
/**
|
|
11
28
|
* Mark a field as having different types for select/insert/update
|
|
12
29
|
* Used for ID fields with @default (read-only)
|
|
30
|
+
*
|
|
31
|
+
* Returns a schema with phantom types so TypeScript knows at compile time
|
|
32
|
+
* which fields should be excluded from insert/update operations.
|
|
13
33
|
*/
|
|
14
|
-
export declare const columnType: <SType, SEncoded, SR, IType, IEncoded, IR, UType, UEncoded, UR>(selectSchema: Schema.Schema<SType, SEncoded, SR>, insertSchema: Schema.Schema<IType, IEncoded, IR>, updateSchema: Schema.Schema<UType, UEncoded, UR>) =>
|
|
34
|
+
export declare const columnType: <SType, SEncoded, SR, IType, IEncoded, IR, UType, UEncoded, UR>(selectSchema: Schema.Schema<SType, SEncoded, SR>, insertSchema: Schema.Schema<IType, IEncoded, IR>, updateSchema: Schema.Schema<UType, UEncoded, UR>) => ColumnTypeSchema<SType, SEncoded, SR, IType, UType>;
|
|
15
35
|
/**
|
|
16
36
|
* Mark a field as database-generated (omitted from insert)
|
|
17
37
|
* Used for fields with @default
|
|
@@ -36,20 +56,46 @@ export declare const Insertable: <Type, Encoded>(schema: Schema.Schema<Type, Enc
|
|
|
36
56
|
* Create Updateable schema from base schema
|
|
37
57
|
*/
|
|
38
58
|
export declare const Updateable: <Type, Encoded>(schema: Schema.Schema<Type, Encoded>) => Schema.Schema<MutableUpdate<Type>, MutableUpdate<Encoded>, never>;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Schemas interface returned by getSchemas().
|
|
61
|
+
* Includes a _base property to preserve the original schema for type-level computations.
|
|
62
|
+
*/
|
|
63
|
+
export interface Schemas<Type, Encoded, BaseSchema extends Schema.Schema<Type, Encoded> = Schema.Schema<Type, Encoded>> {
|
|
64
|
+
readonly _base: BaseSchema;
|
|
65
|
+
readonly Selectable: Schema.Schema<KyselySelectable<Type>, KyselySelectable<Encoded>, never>;
|
|
66
|
+
readonly Insertable: Schema.Schema<MutableInsert<Type>, MutableInsert<Encoded>, never>;
|
|
67
|
+
readonly Updateable: Schema.Schema<MutableUpdate<Type>, MutableUpdate<Encoded>, never>;
|
|
43
68
|
}
|
|
44
69
|
/**
|
|
45
70
|
* Generate all operational schemas (Selectable/Insertable/Updateable) from base schema
|
|
46
71
|
* Used in generated code
|
|
47
72
|
*/
|
|
48
|
-
export declare const getSchemas: <Type, Encoded
|
|
73
|
+
export declare const getSchemas: <Type, Encoded, BaseSchema extends Schema.Schema<Type, Encoded>>(baseSchema: BaseSchema) => Schemas<Type, Encoded, BaseSchema>;
|
|
49
74
|
type RemoveIndexSignature<T> = {
|
|
50
75
|
[K in keyof T as K extends string ? string extends K ? never : K : K extends number ? number extends K ? never : K : K extends symbol ? symbol extends K ? never : K : K]: T[K];
|
|
51
76
|
};
|
|
52
77
|
type StrictType<T> = RemoveIndexSignature<T>;
|
|
78
|
+
type ExtractStructFields<T> = T extends {
|
|
79
|
+
readonly _base: Schema.Struct<infer F>;
|
|
80
|
+
} ? F : never;
|
|
81
|
+
type HasNeverInsert<T> = T extends {
|
|
82
|
+
readonly [ColumnTypeInsertPhantom]: never;
|
|
83
|
+
} ? true : false;
|
|
84
|
+
type HasNeverUpdate<T> = T extends {
|
|
85
|
+
readonly [ColumnTypeUpdatePhantom]: never;
|
|
86
|
+
} ? true : false;
|
|
87
|
+
type InsertableFields<Fields> = {
|
|
88
|
+
[K in keyof Fields as HasNeverInsert<Fields[K]> extends true ? never : K]: Fields[K];
|
|
89
|
+
};
|
|
90
|
+
type UpdateableFields<Fields> = {
|
|
91
|
+
[K in keyof Fields as HasNeverUpdate<Fields[K]> extends true ? never : K]: Fields[K];
|
|
92
|
+
};
|
|
93
|
+
type ComputeInsertableType<Fields> = StrictType<{
|
|
94
|
+
[K in keyof InsertableFields<Fields>]: ExtractInsertPhantom<Fields[K]>;
|
|
95
|
+
}>;
|
|
96
|
+
type ComputeUpdateableType<Fields> = StrictType<{
|
|
97
|
+
[K in keyof UpdateableFields<Fields>]?: ExtractUpdatePhantom<Fields[K]>;
|
|
98
|
+
}>;
|
|
53
99
|
/**
|
|
54
100
|
* Extract SELECT type from schema (matches Kysely's Selectable<T> pattern)
|
|
55
101
|
* @example type UserSelect = Selectable<typeof User>
|
|
@@ -57,14 +103,16 @@ type StrictType<T> = RemoveIndexSignature<T>;
|
|
|
57
103
|
export type Selectable<T extends Schemas<unknown, unknown>> = StrictType<Schema.Schema.Type<T['Selectable']>>;
|
|
58
104
|
/**
|
|
59
105
|
* Extract INSERT type from schema (matches Kysely's Insertable<T> pattern)
|
|
106
|
+
* Excludes fields with never insert type (e.g., columnType(T, Schema.Never, ...))
|
|
60
107
|
* @example type UserInsert = Insertable<typeof User>
|
|
61
108
|
*/
|
|
62
|
-
export type Insertable<T extends Schemas<unknown, unknown>> = StrictType<Schema.Schema.Type<T['Insertable']
|
|
109
|
+
export type Insertable<T extends Schemas<unknown, unknown>> = ExtractStructFields<T> extends infer F ? [F] extends [never] ? StrictType<Schema.Schema.Type<T['Insertable']>> : ComputeInsertableType<F> : never;
|
|
63
110
|
/**
|
|
64
111
|
* Extract UPDATE type from schema (matches Kysely's Updateable<T> pattern)
|
|
112
|
+
* Excludes fields with never update type (e.g., columnType(T, ..., Schema.Never))
|
|
65
113
|
* @example type UserUpdate = Updateable<typeof User>
|
|
66
114
|
*/
|
|
67
|
-
export type Updateable<T extends Schemas<unknown, unknown>> = StrictType<Schema.Schema.Type<T['Updateable']
|
|
115
|
+
export type Updateable<T extends Schemas<unknown, unknown>> = ExtractStructFields<T> extends infer F ? [F] extends [never] ? StrictType<Schema.Schema.Type<T['Updateable']>> : ComputeUpdateableType<F> : never;
|
|
68
116
|
/**
|
|
69
117
|
* Extract branded ID type from schema
|
|
70
118
|
* @example type UserId = Id<typeof User>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/kysely/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EACV,UAAU,IAAI,gBAAgB,EAC9B,UAAU,IAAI,gBAAgB,EAC9B,UAAU,IAAI,gBAAgB,EAC/B,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;;GAGG;AAEH,eAAO,MAAM,YAAY,eAA8B,CAAC;AACxD,eAAO,MAAM,WAAW,eAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/kysely/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EACV,UAAU,IAAI,gBAAgB,EAC9B,UAAU,IAAI,gBAAgB,EAC9B,UAAU,IAAI,gBAAgB,EAC/B,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;;GAGG;AAEH,eAAO,MAAM,YAAY,eAA8B,CAAC;AACxD,eAAO,MAAM,WAAW,eAA6B,CAAC;AAGtD,OAAO,CAAC,MAAM,uBAAuB,EAAE,OAAO,M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,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CACpC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,IACxD,mBAAmB,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,GAClC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACjB,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAC/C,qBAAqB,CAAC,CAAC,CAAC,GAC1B,KAAK,CAAC;AAEZ;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,IACxD,mBAAmB,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,GAClC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACjB,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAC/C,qBAAqB,CAAC,CAAC,CAAC,GAC1B,KAAK,CAAC;AAEZ;;;GAGG;AACH,MAAM,MAAM,EAAE,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;CAAE,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAC7F,CAAC,CAAC,IAAI,CAAC,CACR,CAAC"}
|
package/dist/kysely/helpers.js
CHANGED
|
@@ -9,6 +9,9 @@ export const GeneratedId = Symbol.for('/GeneratedId');
|
|
|
9
9
|
/**
|
|
10
10
|
* Mark a field as having different types for select/insert/update
|
|
11
11
|
* Used for ID fields with @default (read-only)
|
|
12
|
+
*
|
|
13
|
+
* Returns a schema with phantom types so TypeScript knows at compile time
|
|
14
|
+
* which fields should be excluded from insert/update operations.
|
|
12
15
|
*/
|
|
13
16
|
export const columnType = (selectSchema, insertSchema, updateSchema) => {
|
|
14
17
|
const schemas = {
|
|
@@ -70,12 +73,16 @@ const extractParametersFromTypeLiteral = (ast, schemaType) => {
|
|
|
70
73
|
.map((prop) => {
|
|
71
74
|
const columnSchemas = getColumnTypeSchemas(prop.type);
|
|
72
75
|
if (columnSchemas !== null) {
|
|
76
|
+
const targetSchema = columnSchemas[schemaType];
|
|
77
|
+
// Check for Schema.Never BEFORE mutable transformation
|
|
78
|
+
// Schema.mutable() wraps in Transformation node, changing _tag
|
|
79
|
+
if (AST.isNeverKeyword(targetSchema.ast)) {
|
|
80
|
+
return null; // Will be filtered out
|
|
81
|
+
}
|
|
73
82
|
// Use Schema.mutable() for insert/update schema to make arrays mutable
|
|
74
83
|
// Kysely expects mutable T[] for insert/update operations
|
|
75
84
|
const shouldBeMutable = schemaType === 'updateSchema' || schemaType === 'insertSchema';
|
|
76
|
-
return new AST.PropertySignature(prop.name, shouldBeMutable
|
|
77
|
-
? Schema.mutable(columnSchemas[schemaType]).ast
|
|
78
|
-
: columnSchemas[schemaType].ast, prop.isOptional, prop.isReadonly, prop.annotations);
|
|
85
|
+
return new AST.PropertySignature(prop.name, shouldBeMutable ? Schema.mutable(targetSchema).ast : targetSchema.ast, prop.isOptional, prop.isReadonly, prop.annotations);
|
|
79
86
|
}
|
|
80
87
|
// Apply Schema.mutable() to regular fields for insert/updateSchema to make arrays mutable
|
|
81
88
|
// Safe for all types - no-op for non-arrays
|
|
@@ -85,7 +92,7 @@ const extractParametersFromTypeLiteral = (ast, schemaType) => {
|
|
|
85
92
|
// Generated fields are just markers now, return as-is
|
|
86
93
|
return prop;
|
|
87
94
|
})
|
|
88
|
-
.filter((prop) => prop
|
|
95
|
+
.filter((prop) => prop !== null);
|
|
89
96
|
};
|
|
90
97
|
export const Selectable = (schema) => {
|
|
91
98
|
const { ast } = schema;
|
|
@@ -131,6 +138,7 @@ export const Updateable = (schema) => {
|
|
|
131
138
|
* Used in generated code
|
|
132
139
|
*/
|
|
133
140
|
export const getSchemas = (baseSchema) => ({
|
|
141
|
+
_base: baseSchema,
|
|
134
142
|
Selectable: Selectable(baseSchema),
|
|
135
143
|
Insertable: Insertable(baseSchema),
|
|
136
144
|
Updateable: Updateable(baseSchema),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/kysely/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAQxC;;;GAGG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACxD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/kysely/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAQxC;;;GAGG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACxD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AAuCtD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,YAAgD,EAChD,YAAgD,EAChD,YAAgD,EACK,EAAE;IACvD,MAAM,OAAO,GACX;QACE,YAAY;QACZ,YAAY;QACZ,YAAY;KACb,CAAC;IACJ,OAAO,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC,CAM3E,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,M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