prisma-effect-kysely 4.2.4 → 4.2.7
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 +11 -0
- package/dist/generator/index.js +0 -0
- package/dist/kysely/helpers.d.ts +93 -32
- package/dist/kysely/helpers.d.ts.map +1 -1
- package/dist/kysely/helpers.js +10 -4
- package/dist/kysely/helpers.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.2.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix StripFieldBranding type to correctly extract base types from branded ColumnType and Generated types.
|
|
8
|
+
|
|
9
|
+
Previously used `Omit` which doesn't work for intersection types like `S & { [brand]: ... }`.
|
|
10
|
+
Now uses conditional type inference (`T extends ColumnType<infer S, ...> ? S : ...`) to properly extract the base type.
|
|
11
|
+
|
|
12
|
+
This fixes type errors where `Selectable<T>` was returning `Omit<ColumnType<string, never, never>, symbol>` instead of `string`.
|
|
13
|
+
|
|
3
14
|
## 4.1.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/dist/generator/index.js
CHANGED
|
File without changes
|
package/dist/kysely/helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
|
-
import type { Insertable as KyselyInsertable, Selectable as KyselySelectable, Updateable as KyselyUpdateable } from 'kysely';
|
|
2
|
+
import type { Insertable as KyselyInsertable, Selectable as KyselySelectable, Updateable as KyselyUpdateable, ColumnType as KyselyColumnType, Generated as KyselyGenerated } from 'kysely';
|
|
3
3
|
import type { DeepMutable } from 'effect/Types';
|
|
4
4
|
/**
|
|
5
5
|
* Runtime helpers for Kysely schema integration
|
|
@@ -7,31 +7,58 @@ import type { DeepMutable } from 'effect/Types';
|
|
|
7
7
|
*
|
|
8
8
|
* ## Type Extraction Patterns
|
|
9
9
|
*
|
|
10
|
-
* For
|
|
10
|
+
* For Effect Schemas (recommended - full type safety):
|
|
11
11
|
* ```typescript
|
|
12
|
-
* import
|
|
13
|
-
* import { UserTable } from './generated/types';
|
|
14
|
-
*
|
|
15
|
-
* type UserSelect = Selectable<UserTable>; // All fields
|
|
16
|
-
* type UserInsert = Insertable<UserTable>; // Excludes ColumnType<S, never, U>
|
|
17
|
-
* type UserUpdate = Updateable<UserTable>; // Excludes ColumnType<S, I, never>
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* For Effect Schemas (runtime validation):
|
|
21
|
-
* ```typescript
|
|
22
|
-
* import { Selectable, Insertable, Updateable } from 'prisma-effect-kysely/kysely';
|
|
12
|
+
* import { Selectable, Insertable, Updateable, ColumnType, Generated } from 'prisma-effect-kysely/kysely';
|
|
23
13
|
* import { User } from './generated/types';
|
|
24
14
|
*
|
|
25
15
|
* type UserSelect = Selectable<typeof User>;
|
|
26
16
|
* type UserInsert = Insertable<typeof User>;
|
|
27
17
|
* type UserUpdate = Updateable<typeof User>;
|
|
28
18
|
* ```
|
|
19
|
+
*
|
|
20
|
+
* Note: This package exports branded versions of ColumnType and Generated that
|
|
21
|
+
* are compatible with Effect Schema's type inference. These extend the base
|
|
22
|
+
* select type (S) while carrying phantom insert/update type information.
|
|
29
23
|
*/
|
|
30
|
-
export type { KyselySelectable, KyselyInsertable, KyselyUpdateable };
|
|
24
|
+
export type { KyselySelectable, KyselyInsertable, KyselyUpdateable, KyselyColumnType, KyselyGenerated, };
|
|
31
25
|
export declare const ColumnTypeId: unique symbol;
|
|
32
26
|
export declare const GeneratedId: unique symbol;
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Branded ColumnType that extends S while carrying phantom insert/update type information.
|
|
29
|
+
*
|
|
30
|
+
* This replaces Kysely's ColumnType because:
|
|
31
|
+
* 1. Kysely's ColumnType<S,I,U> = { __select__: S, __insert__: I, __update__: U } is NOT a subtype of S
|
|
32
|
+
* 2. Schema.make<KyselyColumnType<...>>(ast) doesn't work because AST represents S, not the struct
|
|
33
|
+
* 3. Our ColumnType<S,I,U> = S & Brand IS a subtype of S, so Schema.make works correctly
|
|
34
|
+
*
|
|
35
|
+
* Usage is identical to Kysely's ColumnType:
|
|
36
|
+
* ```typescript
|
|
37
|
+
* type IdField = ColumnType<string, never, never>; // Read-only ID
|
|
38
|
+
* type CreatedAt = ColumnType<Date, Date | undefined, Date>; // Optional on insert
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export type ColumnType<S, I = S, U = S> = S & {
|
|
42
|
+
readonly [ColumnTypeId]: {
|
|
43
|
+
readonly __insert__: I;
|
|
44
|
+
readonly __update__: U;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Branded Generated type for database-generated fields.
|
|
49
|
+
*
|
|
50
|
+
* Equivalent to ColumnType<T, T | undefined, T> - the field is:
|
|
51
|
+
* - Required on select (T)
|
|
52
|
+
* - Optional on insert (T | undefined)
|
|
53
|
+
* - Allowed on update (T)
|
|
54
|
+
*/
|
|
55
|
+
export type Generated<T> = T & {
|
|
56
|
+
readonly [GeneratedId]: true;
|
|
57
|
+
readonly [ColumnTypeId]: {
|
|
58
|
+
readonly __insert__: T | undefined;
|
|
59
|
+
readonly __update__: T;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
35
62
|
/**
|
|
36
63
|
* Mark a field as having different types for select/insert/update
|
|
37
64
|
* Used for ID fields with @default (read-only)
|
|
@@ -39,8 +66,10 @@ export type { ColumnType, Generated };
|
|
|
39
66
|
* The insert/update schemas are stored in annotations and used at runtime
|
|
40
67
|
* to determine which fields to include in Insertable/Updateable schemas.
|
|
41
68
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
69
|
+
* Returns a schema with our branded ColumnType<S,I,U> that extends S, ensuring:
|
|
70
|
+
* 1. TypeScript correctly infers the return type across module boundaries
|
|
71
|
+
* 2. Runtime decode returns S values (not wrapped structs)
|
|
72
|
+
* 3. Type utilities can extract I and U from the brand
|
|
44
73
|
*/
|
|
45
74
|
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>) => Schema.Schema<ColumnType<SType, IType, UType>, SEncoded, SR>;
|
|
46
75
|
/**
|
|
@@ -51,23 +80,33 @@ export declare const columnType: <SType, SEncoded, SR, IType, IEncoded, IR, UTyp
|
|
|
51
80
|
* - Present in select and update schemas
|
|
52
81
|
* - OMITTED from insert schema (not optional, completely absent)
|
|
53
82
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
83
|
+
* Returns a schema with our branded Generated<T> that extends T, ensuring:
|
|
84
|
+
* 1. TypeScript correctly infers the return type across module boundaries
|
|
85
|
+
* 2. Runtime decode returns T values (not wrapped structs)
|
|
56
86
|
*/
|
|
57
87
|
export declare const generated: <SType, SEncoded, R>(schema: Schema.Schema<SType, SEncoded, R>) => Schema.Schema<Generated<SType>, SEncoded, R>;
|
|
58
88
|
/**
|
|
59
89
|
* Extract the insert type from a field:
|
|
60
|
-
* - ColumnType<S, I, U> -> I
|
|
61
|
-
* - Generated<T> -> T | undefined (
|
|
90
|
+
* - ColumnType<S, I, U> -> I (via brand)
|
|
91
|
+
* - Generated<T> -> T | undefined (via brand)
|
|
62
92
|
* - Other types -> as-is
|
|
63
93
|
*/
|
|
64
|
-
type ExtractInsertType<T> = T extends
|
|
94
|
+
type ExtractInsertType<T> = T extends {
|
|
95
|
+
readonly [ColumnTypeId]: {
|
|
96
|
+
readonly __insert__: infer I;
|
|
97
|
+
};
|
|
98
|
+
} ? I : T;
|
|
65
99
|
/**
|
|
66
100
|
* Extract the update type from a field:
|
|
67
|
-
* - ColumnType<S, I, U> -> U
|
|
101
|
+
* - ColumnType<S, I, U> -> U (via brand)
|
|
102
|
+
* - Generated<T> -> T (via brand)
|
|
68
103
|
* - Other types -> as-is
|
|
69
104
|
*/
|
|
70
|
-
type ExtractUpdateType<T> = T extends
|
|
105
|
+
type ExtractUpdateType<T> = T extends {
|
|
106
|
+
readonly [ColumnTypeId]: {
|
|
107
|
+
readonly __update__: infer U;
|
|
108
|
+
};
|
|
109
|
+
} ? U : T;
|
|
71
110
|
/**
|
|
72
111
|
* Custom Insertable type that properly omits fields with `never` insert types.
|
|
73
112
|
* This is needed because Kysely's Insertable includes never fields which makes types unusable.
|
|
@@ -83,7 +122,28 @@ type CustomUpdateable<T> = DeepMutable<{
|
|
|
83
122
|
}>;
|
|
84
123
|
type MutableInsert<Type> = CustomInsertable<Type>;
|
|
85
124
|
type MutableUpdate<Type> = CustomUpdateable<Type>;
|
|
86
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Strip branding from a single field type using conditional type inference.
|
|
127
|
+
* Uses inference to extract the base type S from branded types.
|
|
128
|
+
*
|
|
129
|
+
* - Generated<T> = T & {...} -> T (via infer)
|
|
130
|
+
* - ColumnType<S, I, U> = S & {...} -> S (via infer)
|
|
131
|
+
* - Other types -> as-is
|
|
132
|
+
*/
|
|
133
|
+
type StripFieldBranding<T> = T extends Generated<infer S> ? S : T extends ColumnType<infer S, unknown, unknown> ? S : T;
|
|
134
|
+
/**
|
|
135
|
+
* Strip branding from all properties in an object type.
|
|
136
|
+
* Converts ColumnType<S,I,U> to S and Generated<T> to T.
|
|
137
|
+
*/
|
|
138
|
+
type StripBrandingFromObject<T> = {
|
|
139
|
+
[K in keyof T]: StripFieldBranding<T[K]>;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Selectable type with branding stripped - used for Schema function return types.
|
|
143
|
+
* This ensures that `Schema.Type` returns plain types without ColumnType/Generated branding.
|
|
144
|
+
*/
|
|
145
|
+
type SelectableType<T> = KyselySelectable<StripBrandingFromObject<T>>;
|
|
146
|
+
export declare const Selectable: <Type, Encoded>(schema: Schema.Schema<Type, Encoded>) => Schema.Schema<SelectableType<Type>, SelectableType<Encoded>, never>;
|
|
87
147
|
/**
|
|
88
148
|
* Create Insertable schema from base schema
|
|
89
149
|
* Filters out generated fields (@effect/sql Model.Generated pattern)
|
|
@@ -102,7 +162,7 @@ export declare const Updateable: <Type, Encoded>(schema: Schema.Schema<Type, Enc
|
|
|
102
162
|
*/
|
|
103
163
|
export interface Schemas<BaseSchema extends Schema.Schema<unknown, unknown, unknown>> {
|
|
104
164
|
readonly _base: BaseSchema;
|
|
105
|
-
readonly Selectable: Schema.Schema<
|
|
165
|
+
readonly Selectable: Schema.Schema<SelectableType<Schema.Schema.Type<BaseSchema>>, SelectableType<Schema.Schema.Encoded<BaseSchema>>, never>;
|
|
106
166
|
readonly Insertable: Schema.Schema<MutableInsert<Schema.Schema.Type<BaseSchema>>, MutableInsert<Schema.Schema.Encoded<BaseSchema>>, never>;
|
|
107
167
|
readonly Updateable: Schema.Schema<MutableUpdate<Schema.Schema.Type<BaseSchema>>, MutableUpdate<Schema.Schema.Encoded<BaseSchema>>, never>;
|
|
108
168
|
}
|
|
@@ -139,30 +199,31 @@ type OmitNever<T> = {
|
|
|
139
199
|
type StrictType<T> = OmitNever<RemoveIndexSignature<T>>;
|
|
140
200
|
/**
|
|
141
201
|
* Extract SELECT type from schema (matches Kysely's Selectable<T> pattern)
|
|
202
|
+
* Strips ColumnType/Generated branding to return plain types.
|
|
142
203
|
* @example type UserSelect = Selectable<typeof User>
|
|
143
204
|
*/
|
|
144
205
|
export type Selectable<T extends {
|
|
145
|
-
readonly Selectable: Schema.Schema<
|
|
146
|
-
}> = StrictType<Schema.Schema.Type<T['Selectable']
|
|
206
|
+
readonly Selectable: Schema.Schema<any, any, any>;
|
|
207
|
+
}> = StrictType<StripBrandingFromObject<Schema.Schema.Type<T['Selectable']>>>;
|
|
147
208
|
/**
|
|
148
209
|
* Extract INSERT type from schema (matches Kysely's Insertable<T> pattern)
|
|
149
210
|
* @example type UserInsert = Insertable<typeof User>
|
|
150
211
|
*/
|
|
151
212
|
export type Insertable<T extends {
|
|
152
|
-
readonly Insertable: Schema.Schema<
|
|
213
|
+
readonly Insertable: Schema.Schema<any, any, any>;
|
|
153
214
|
}> = StrictType<Schema.Schema.Type<T['Insertable']>>;
|
|
154
215
|
/**
|
|
155
216
|
* Extract UPDATE type from schema (matches Kysely's Updateable<T> pattern)
|
|
156
217
|
* @example type UserUpdate = Updateable<typeof User>
|
|
157
218
|
*/
|
|
158
219
|
export type Updateable<T extends {
|
|
159
|
-
readonly Updateable: Schema.Schema<
|
|
220
|
+
readonly Updateable: Schema.Schema<any, any, any>;
|
|
160
221
|
}> = StrictType<Schema.Schema.Type<T['Updateable']>>;
|
|
161
222
|
/**
|
|
162
223
|
* Extract branded ID type from schema
|
|
163
224
|
* @example type UserId = Id<typeof User>
|
|
164
225
|
*/
|
|
165
226
|
export type Id<T extends {
|
|
166
|
-
Id: Schema.Schema<
|
|
227
|
+
Id: Schema.Schema<any, any, any>;
|
|
167
228
|
}> = Schema.Schema.Type<T['Id']>;
|
|
168
229
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -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,
|
|
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,EAC9B,UAAU,IAAI,gBAAgB,EAC9B,SAAS,IAAI,eAAe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C,SAAS;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CAAE,IAC7D,UAAU,CAAC,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E;;;GAGG;AACH,MAAM,MAAM,UAAU,CAEpB,CAAC,SAAS;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CAAE,IAC7D,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,UAAU,CAEpB,CAAC,SAAS;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CAAE,IAC7D,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEpD;;;GAGG;AAEH,MAAM,MAAM,EAAE,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CAAE,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC"}
|
package/dist/kysely/helpers.js
CHANGED
|
@@ -9,8 +9,10 @@ export const GeneratedId = Symbol.for('/GeneratedId');
|
|
|
9
9
|
* The insert/update schemas are stored in annotations and used at runtime
|
|
10
10
|
* to determine which fields to include in Insertable/Updateable schemas.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Returns a schema with our branded ColumnType<S,I,U> that extends S, ensuring:
|
|
13
|
+
* 1. TypeScript correctly infers the return type across module boundaries
|
|
14
|
+
* 2. Runtime decode returns S values (not wrapped structs)
|
|
15
|
+
* 3. Type utilities can extract I and U from the brand
|
|
14
16
|
*/
|
|
15
17
|
export const columnType = (selectSchema, insertSchema, updateSchema) => {
|
|
16
18
|
const schemas = {
|
|
@@ -19,6 +21,8 @@ export const columnType = (selectSchema, insertSchema, updateSchema) => {
|
|
|
19
21
|
updateSchema,
|
|
20
22
|
};
|
|
21
23
|
const annotated = selectSchema.annotations({ [ColumnTypeId]: schemas });
|
|
24
|
+
// ColumnType<S,I,U> extends S, so this type assertion is valid
|
|
25
|
+
// because the runtime value IS of type S
|
|
22
26
|
return Schema.make(annotated.ast);
|
|
23
27
|
};
|
|
24
28
|
/**
|
|
@@ -29,11 +33,13 @@ export const columnType = (selectSchema, insertSchema, updateSchema) => {
|
|
|
29
33
|
* - Present in select and update schemas
|
|
30
34
|
* - OMITTED from insert schema (not optional, completely absent)
|
|
31
35
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
36
|
+
* Returns a schema with our branded Generated<T> that extends T, ensuring:
|
|
37
|
+
* 1. TypeScript correctly infers the return type across module boundaries
|
|
38
|
+
* 2. Runtime decode returns T values (not wrapped structs)
|
|
34
39
|
*/
|
|
35
40
|
export const generated = (schema) => {
|
|
36
41
|
const annotated = schema.annotations({ [GeneratedId]: true });
|
|
42
|
+
// Generated<T> extends T, so this type assertion is valid
|
|
37
43
|
return Schema.make(annotated.ast);
|
|
38
44
|
};
|
|
39
45
|
/**
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/kysely/helpers.ts"],"names":[],"mappings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