@shivaedev/effect-prisma 0.6.3 → 0.6.4
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 +5 -1
- package/dist/database.d.ts +4 -4
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +12 -12
- package/dist/database.js.map +1 -1
- package/dist/error.d.ts +5 -5
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +1 -2
- package/dist/error.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/internal/adapters/transaction-settlement.d.ts +10 -0
- package/dist/internal/adapters/transaction-settlement.d.ts.map +1 -0
- package/dist/internal/adapters/transaction-settlement.js +56 -0
- package/dist/internal/adapters/transaction-settlement.js.map +1 -0
- package/dist/internal/client-lifecycle.d.ts.map +1 -1
- package/dist/internal/client-lifecycle.js.map +1 -1
- package/dist/internal/contract-normalization.d.ts.map +1 -1
- package/dist/internal/contract-normalization.js +1 -3
- package/dist/internal/contract-normalization.js.map +1 -1
- package/dist/internal/database-facade.d.ts +24 -0
- package/dist/internal/database-facade.d.ts.map +1 -0
- package/dist/internal/database-facade.js +84 -0
- package/dist/internal/database-facade.js.map +1 -0
- package/dist/internal/database-factory.d.ts +4 -44
- package/dist/internal/database-factory.d.ts.map +1 -1
- package/dist/internal/database-factory.js +11 -84
- package/dist/internal/database-factory.js.map +1 -1
- package/dist/internal/database-types.d.ts +37 -0
- package/dist/internal/database-types.d.ts.map +1 -0
- package/dist/internal/database-types.js +2 -0
- package/dist/internal/database-types.js.map +1 -0
- package/dist/internal/dynamic.d.ts +5 -0
- package/dist/internal/dynamic.d.ts.map +1 -0
- package/dist/internal/dynamic.js +12 -0
- package/dist/internal/dynamic.js.map +1 -0
- package/dist/internal/executor.d.ts.map +1 -1
- package/dist/internal/promise.d.ts +1 -1
- package/dist/internal/promise.d.ts.map +1 -1
- package/dist/internal/promise.js +1 -3
- package/dist/internal/promise.js.map +1 -1
- package/dist/internal/query-execution.d.ts +2 -2
- package/dist/internal/query-execution.d.ts.map +1 -1
- package/dist/internal/query-execution.js +2 -6
- package/dist/internal/query-execution.js.map +1 -1
- package/dist/internal/recipe.d.ts.map +1 -1
- package/dist/internal/recipe.js +7 -18
- package/dist/internal/recipe.js.map +1 -1
- package/dist/internal/relation-plan.d.ts +1 -1
- package/dist/internal/relation-result.d.ts +4 -0
- package/dist/internal/relation-result.d.ts.map +1 -0
- package/dist/internal/relation-result.js +19 -0
- package/dist/internal/relation-result.js.map +1 -0
- package/dist/internal/relation-runtime.d.ts +3 -3
- package/dist/internal/relation-runtime.d.ts.map +1 -1
- package/dist/internal/relation-runtime.js +9 -34
- package/dist/internal/relation-runtime.js.map +1 -1
- package/dist/internal/relation-stream.d.ts +3 -3
- package/dist/internal/relation-stream.d.ts.map +1 -1
- package/dist/internal/relation-stream.js +12 -14
- package/dist/internal/relation-stream.js.map +1 -1
- package/dist/internal/sqlite-datetime.d.ts +1 -1
- package/dist/internal/sqlite-datetime.d.ts.map +1 -1
- package/dist/internal/sqlite-datetime.js +3 -1
- package/dist/internal/sqlite-datetime.js.map +1 -1
- package/dist/internal/sqlite-pragmas.d.ts.map +1 -1
- package/dist/internal/sqlite-pragmas.js.map +1 -1
- package/dist/internal/testing.d.ts +1 -1
- package/dist/internal/testing.d.ts.map +1 -1
- package/dist/internal/testing.js +5 -2
- package/dist/internal/testing.js.map +1 -1
- package/dist/internal/transaction.d.ts +5 -5
- package/dist/internal/transaction.d.ts.map +1 -1
- package/dist/internal/transaction.js +3 -51
- package/dist/internal/transaction.js.map +1 -1
- package/dist/relation/include-metadata.d.ts.map +1 -1
- package/dist/relation/include.d.ts +2 -2
- package/dist/relation/include.d.ts.map +1 -1
- package/dist/relation/prisma-methods.d.ts +3 -3
- package/dist/relation/prisma-methods.d.ts.map +1 -1
- package/dist/relation.d.ts +2 -2
- package/dist/relation.d.ts.map +1 -1
- package/dist/sqlite.d.ts +3 -3
- package/dist/sqlite.d.ts.map +1 -1
- package/dist/sqlite.js +14 -12
- package/dist/sqlite.js.map +1 -1
- package/dist/testing/transaction.d.ts +6 -7
- package/dist/testing/transaction.d.ts.map +1 -1
- package/dist/testing/transaction.js +2 -2
- package/dist/testing/transaction.js.map +1 -1
- package/dist/testing/types.d.ts +2 -2
- package/dist/testing/types.d.ts.map +1 -1
- package/dist/testing/vitest.d.ts +3 -3
- package/dist/testing/vitest.d.ts.map +1 -1
- package/dist/testing/vitest.js +2 -2
- package/dist/testing/vitest.js.map +1 -1
- package/dist/testing.d.ts +3 -3
- package/package.json +2 -2
- package/src/bin/normalize-contract.ts +1 -1
- package/src/database.ts +49 -67
- package/src/error.ts +9 -19
- package/src/index.ts +3 -3
- package/src/internal/adapters/transaction-settlement.ts +67 -0
- package/src/internal/client-lifecycle.ts +3 -10
- package/src/internal/contract-normalization.ts +3 -8
- package/src/internal/database-facade.ts +143 -0
- package/src/internal/database-factory.ts +30 -298
- package/src/internal/database-types.ts +69 -0
- package/src/internal/dynamic.ts +16 -0
- package/src/internal/executor.ts +1 -4
- package/src/internal/promise.ts +3 -11
- package/src/internal/query-execution.ts +4 -8
- package/src/internal/recipe.ts +19 -84
- package/src/internal/relation-plan.ts +1 -1
- package/src/internal/relation-result.ts +27 -0
- package/src/internal/relation-runtime.ts +43 -133
- package/src/internal/relation-stream.ts +22 -48
- package/src/internal/sqlite-datetime.ts +10 -23
- package/src/internal/sqlite-pragmas.ts +1 -4
- package/src/internal/testing.ts +13 -15
- package/src/internal/transaction.ts +14 -107
- package/src/relation/include-metadata.ts +10 -42
- package/src/relation/include.ts +19 -115
- package/src/relation/prisma-methods.ts +23 -111
- package/src/relation.ts +18 -46
- package/src/sqlite.ts +57 -78
- package/src/testing/transaction.ts +20 -33
- package/src/testing/types.ts +9 -28
- package/src/testing/vitest.ts +14 -28
- package/src/testing.ts +3 -3
|
@@ -8,46 +8,26 @@ type RelationDefinition<
|
|
|
8
8
|
Contract extends AnyPostgresContract,
|
|
9
9
|
Model extends string,
|
|
10
10
|
RelationName extends string,
|
|
11
|
-
> = RelationName extends keyof RelationsOf<Contract, Model>
|
|
12
|
-
? RelationsOf<Contract, Model>[RelationName]
|
|
13
|
-
: never;
|
|
11
|
+
> = RelationName extends keyof RelationsOf<Contract, Model> ? RelationsOf<Contract, Model>[RelationName] : never;
|
|
14
12
|
|
|
15
|
-
type RelationCardinalityOf<
|
|
16
|
-
Contract extends AnyPostgresContract,
|
|
17
|
-
Model extends string,
|
|
18
|
-
RelationName extends string,
|
|
19
|
-
> =
|
|
13
|
+
type RelationCardinalityOf<Contract extends AnyPostgresContract, Model extends string, RelationName extends string> =
|
|
20
14
|
RelationDefinition<Contract, Model, RelationName> extends {
|
|
21
15
|
readonly cardinality: infer Cardinality extends string;
|
|
22
16
|
}
|
|
23
17
|
? Cardinality
|
|
24
18
|
: never;
|
|
25
19
|
|
|
26
|
-
export type IsToManyRelation<
|
|
27
|
-
Contract extends
|
|
28
|
-
Model extends string,
|
|
29
|
-
RelationName extends string,
|
|
30
|
-
> =
|
|
31
|
-
RelationCardinalityOf<Contract, Model, RelationName> extends "1:N" | "N:M"
|
|
32
|
-
? true
|
|
33
|
-
: false;
|
|
20
|
+
export type IsToManyRelation<Contract extends AnyPostgresContract, Model extends string, RelationName extends string> =
|
|
21
|
+
RelationCardinalityOf<Contract, Model, RelationName> extends "1:N" | "N:M" ? true : false;
|
|
34
22
|
|
|
35
|
-
export type RelatedModelNameOf<
|
|
36
|
-
Contract extends AnyPostgresContract,
|
|
37
|
-
Model extends string,
|
|
38
|
-
RelationName extends string,
|
|
39
|
-
> =
|
|
23
|
+
export type RelatedModelNameOf<Contract extends AnyPostgresContract, Model extends string, RelationName extends string> =
|
|
40
24
|
RelationDefinition<Contract, Model, RelationName> extends {
|
|
41
25
|
readonly to: { readonly model: infer Related extends string };
|
|
42
26
|
}
|
|
43
27
|
? Related
|
|
44
28
|
: never;
|
|
45
29
|
|
|
46
|
-
type RelationLocalFields<
|
|
47
|
-
Contract extends AnyPostgresContract,
|
|
48
|
-
Model extends string,
|
|
49
|
-
RelationName extends string,
|
|
50
|
-
> =
|
|
30
|
+
type RelationLocalFields<Contract extends AnyPostgresContract, Model extends string, RelationName extends string> =
|
|
51
31
|
RelationDefinition<Contract, Model, RelationName> extends {
|
|
52
32
|
readonly on: {
|
|
53
33
|
readonly localFields: infer Fields extends readonly string[];
|
|
@@ -56,8 +36,7 @@ type RelationLocalFields<
|
|
|
56
36
|
? Fields
|
|
57
37
|
: readonly [];
|
|
58
38
|
|
|
59
|
-
type DefaultNamespace<Contract extends AnyPostgresContract> =
|
|
60
|
-
Contract["domain"]["namespaces"][keyof Contract["domain"]["namespaces"]];
|
|
39
|
+
type DefaultNamespace<Contract extends AnyPostgresContract> = Contract["domain"]["namespaces"][keyof Contract["domain"]["namespaces"]];
|
|
61
40
|
|
|
62
41
|
type ModelFields<Contract extends AnyPostgresContract, Model extends string> =
|
|
63
42
|
DefaultNamespace<Contract> extends {
|
|
@@ -70,10 +49,7 @@ type ModelFields<Contract extends AnyPostgresContract, Model extends string> =
|
|
|
70
49
|
: never
|
|
71
50
|
: never;
|
|
72
51
|
|
|
73
|
-
type AnyNullableField<
|
|
74
|
-
Fields,
|
|
75
|
-
Names extends readonly string[],
|
|
76
|
-
> = Names extends readonly [
|
|
52
|
+
type AnyNullableField<Fields, Names extends readonly string[]> = Names extends readonly [
|
|
77
53
|
infer Head extends string,
|
|
78
54
|
...infer Tail extends readonly string[],
|
|
79
55
|
]
|
|
@@ -84,19 +60,11 @@ type AnyNullableField<
|
|
|
84
60
|
: true
|
|
85
61
|
: false;
|
|
86
62
|
|
|
87
|
-
export type IncludedRelationValue<
|
|
88
|
-
Contract extends AnyPostgresContract,
|
|
89
|
-
Model extends string,
|
|
90
|
-
RelationName extends string,
|
|
91
|
-
Value,
|
|
92
|
-
> =
|
|
63
|
+
export type IncludedRelationValue<Contract extends AnyPostgresContract, Model extends string, RelationName extends string, Value> =
|
|
93
64
|
RelationCardinalityOf<Contract, Model, RelationName> extends "1:N" | "N:M"
|
|
94
65
|
? Array<Value>
|
|
95
66
|
: RelationCardinalityOf<Contract, Model, RelationName> extends "N:1"
|
|
96
|
-
? AnyNullableField<
|
|
97
|
-
ModelFields<Contract, Model>,
|
|
98
|
-
RelationLocalFields<Contract, Model, RelationName>
|
|
99
|
-
> extends true
|
|
67
|
+
? AnyNullableField<ModelFields<Contract, Model>, RelationLocalFields<Contract, Model, RelationName>> extends true
|
|
100
68
|
? Value | null
|
|
101
69
|
: Value
|
|
102
70
|
: Value | null;
|
package/src/relation/include.ts
CHANGED
|
@@ -1,40 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
RelationNames,
|
|
5
|
-
} from "@prisma-next/sql-orm-client";
|
|
6
|
-
import type { Relation, RelationQuery } from "../relation.js";
|
|
7
|
-
import type {
|
|
8
|
-
AnyPostgresContract,
|
|
9
|
-
IncludedRelationValue,
|
|
10
|
-
IsToManyRelation,
|
|
11
|
-
RelatedModelNameOf,
|
|
12
|
-
} from "./include-metadata.js";
|
|
1
|
+
import type { DefaultModelRow, Collection as PrismaCollection, RelationNames } from "@prisma-next/sql-orm-client";
|
|
2
|
+
import type { Relation, RelationQuery } from "../relation.ts";
|
|
3
|
+
import type { AnyPostgresContract, IncludedRelationValue, IsToManyRelation, RelatedModelNameOf } from "./include-metadata.ts";
|
|
13
4
|
|
|
14
5
|
type Simplify<Value> = { [Key in keyof Value]: Value[Key] };
|
|
15
6
|
|
|
16
|
-
type QueryValue<Query> =
|
|
17
|
-
Query extends RelationQuery<
|
|
18
|
-
infer Value,
|
|
19
|
-
infer _Contract,
|
|
20
|
-
infer _Model,
|
|
21
|
-
infer _DatabaseId
|
|
22
|
-
>
|
|
23
|
-
? Value
|
|
24
|
-
: never;
|
|
7
|
+
type QueryValue<Query> = Query extends RelationQuery<infer Value, infer _Contract, infer _Model, infer _DatabaseId> ? Value : never;
|
|
25
8
|
|
|
26
|
-
type AcceptRelatedQuery<
|
|
27
|
-
|
|
28
|
-
Contract extends AnyPostgresContract,
|
|
29
|
-
Model extends string,
|
|
30
|
-
DatabaseId,
|
|
31
|
-
> = [Query] extends [
|
|
32
|
-
RelationQuery<
|
|
33
|
-
infer _Value,
|
|
34
|
-
infer QueryContract,
|
|
35
|
-
infer QueryModel,
|
|
36
|
-
infer QueryDatabaseId
|
|
37
|
-
>,
|
|
9
|
+
type AcceptRelatedQuery<Query, Contract extends AnyPostgresContract, Model extends string, DatabaseId> = [Query] extends [
|
|
10
|
+
RelationQuery<infer _Value, infer QueryContract, infer QueryModel, infer QueryDatabaseId>,
|
|
38
11
|
]
|
|
39
12
|
? [QueryContract] extends [Contract]
|
|
40
13
|
? [Contract] extends [QueryContract]
|
|
@@ -49,15 +22,8 @@ type AcceptRelatedQuery<
|
|
|
49
22
|
: never
|
|
50
23
|
: never;
|
|
51
24
|
|
|
52
|
-
type IncludedQueryValue<
|
|
53
|
-
Query,
|
|
54
|
-
Contract extends AnyPostgresContract,
|
|
55
|
-
Model extends string,
|
|
56
|
-
RelationName extends string,
|
|
57
|
-
> =
|
|
58
|
-
QueryValue<Query> extends ReadonlyArray<infer Row>
|
|
59
|
-
? IncludedRelationValue<Contract, Model, RelationName, Row>
|
|
60
|
-
: QueryValue<Query>;
|
|
25
|
+
type IncludedQueryValue<Query, Contract extends AnyPostgresContract, Model extends string, RelationName extends string> =
|
|
26
|
+
QueryValue<Query> extends ReadonlyArray<infer Row> ? IncludedRelationValue<Contract, Model, RelationName, Row> : QueryValue<Query>;
|
|
61
27
|
|
|
62
28
|
type QueryShapeValue<Shape extends Readonly<Record<string, unknown>>> = {
|
|
63
29
|
readonly [Key in keyof Shape]: QueryValue<Shape[Key]>;
|
|
@@ -69,38 +35,16 @@ type AcceptRelatedQueryShape<
|
|
|
69
35
|
Model extends string,
|
|
70
36
|
DatabaseId,
|
|
71
37
|
> = {
|
|
72
|
-
readonly [Key in keyof Shape]: Shape[Key] &
|
|
73
|
-
AcceptRelatedQuery<Shape[Key], Contract, Model, DatabaseId>;
|
|
38
|
+
readonly [Key in keyof Shape]: Shape[Key] & AcceptRelatedQuery<Shape[Key], Contract, Model, DatabaseId>;
|
|
74
39
|
};
|
|
75
40
|
|
|
76
|
-
type WithIncludedRelation<
|
|
77
|
-
Collection,
|
|
78
|
-
Contract extends AnyPostgresContract,
|
|
79
|
-
Model extends string,
|
|
80
|
-
RelationName extends string,
|
|
81
|
-
Value,
|
|
82
|
-
> =
|
|
41
|
+
type WithIncludedRelation<Collection, Contract extends AnyPostgresContract, Model extends string, RelationName extends string, Value> =
|
|
83
42
|
Collection extends PrismaCollection<Contract, Model, infer Row, infer State>
|
|
84
|
-
? PrismaCollection<
|
|
85
|
-
Contract,
|
|
86
|
-
Model,
|
|
87
|
-
Simplify<Row & { readonly [Key in RelationName]: Value }>,
|
|
88
|
-
State
|
|
89
|
-
>
|
|
43
|
+
? PrismaCollection<Contract, Model, Simplify<Row & { readonly [Key in RelationName]: Value }>, State>
|
|
90
44
|
: never;
|
|
91
45
|
|
|
92
|
-
export type IncludeMethod<
|
|
93
|
-
Collection,
|
|
94
|
-
Contract,
|
|
95
|
-
Model extends string,
|
|
96
|
-
DatabaseId,
|
|
97
|
-
> = Contract extends AnyPostgresContract
|
|
98
|
-
? Collection extends PrismaCollection<
|
|
99
|
-
Contract,
|
|
100
|
-
Model,
|
|
101
|
-
infer _Row,
|
|
102
|
-
infer _State
|
|
103
|
-
>
|
|
46
|
+
export type IncludeMethod<Collection, Contract, Model extends string, DatabaseId> = Contract extends AnyPostgresContract
|
|
47
|
+
? Collection extends PrismaCollection<Contract, Model, infer _Row, infer _State>
|
|
104
48
|
? {
|
|
105
49
|
include<RelationName extends RelationNames<Contract, Model>>(
|
|
106
50
|
relationName: RelationName,
|
|
@@ -110,15 +54,7 @@ export type IncludeMethod<
|
|
|
110
54
|
Contract,
|
|
111
55
|
Model,
|
|
112
56
|
RelationName,
|
|
113
|
-
IncludedRelationValue<
|
|
114
|
-
Contract,
|
|
115
|
-
Model,
|
|
116
|
-
RelationName,
|
|
117
|
-
DefaultModelRow<
|
|
118
|
-
Contract,
|
|
119
|
-
RelatedModelNameOf<Contract, Model, RelationName>
|
|
120
|
-
>
|
|
121
|
-
>
|
|
57
|
+
IncludedRelationValue<Contract, Model, RelationName, DefaultModelRow<Contract, RelatedModelNameOf<Contract, Model, RelationName>>>
|
|
122
58
|
>,
|
|
123
59
|
Contract,
|
|
124
60
|
Model,
|
|
@@ -126,53 +62,21 @@ export type IncludeMethod<
|
|
|
126
62
|
>;
|
|
127
63
|
include<RelationName extends RelationNames<Contract, Model>, Query>(
|
|
128
64
|
relationName: RelationName,
|
|
129
|
-
query: Query &
|
|
130
|
-
AcceptRelatedQuery<
|
|
131
|
-
Query,
|
|
132
|
-
Contract,
|
|
133
|
-
RelatedModelNameOf<Contract, Model, RelationName>,
|
|
134
|
-
DatabaseId
|
|
135
|
-
>,
|
|
65
|
+
query: Query & AcceptRelatedQuery<Query, Contract, RelatedModelNameOf<Contract, Model, RelationName>, DatabaseId>,
|
|
136
66
|
): Relation<
|
|
137
|
-
WithIncludedRelation<
|
|
138
|
-
Collection,
|
|
139
|
-
Contract,
|
|
140
|
-
Model,
|
|
141
|
-
RelationName,
|
|
142
|
-
IncludedQueryValue<Query, Contract, Model, RelationName>
|
|
143
|
-
>,
|
|
67
|
+
WithIncludedRelation<Collection, Contract, Model, RelationName, IncludedQueryValue<Query, Contract, Model, RelationName>>,
|
|
144
68
|
Contract,
|
|
145
69
|
Model,
|
|
146
70
|
DatabaseId
|
|
147
71
|
>;
|
|
148
|
-
include<
|
|
149
|
-
RelationName extends RelationNames<Contract, Model>,
|
|
150
|
-
Shape extends Readonly<Record<string, unknown>>,
|
|
151
|
-
>(
|
|
72
|
+
include<RelationName extends RelationNames<Contract, Model>, Shape extends Readonly<Record<string, unknown>>>(
|
|
152
73
|
relationName: RelationName,
|
|
153
74
|
shape: IsToManyRelation<Contract, Model, RelationName> extends true
|
|
154
75
|
? keyof Shape extends never
|
|
155
76
|
? never
|
|
156
|
-
: Shape &
|
|
157
|
-
AcceptRelatedQueryShape<
|
|
158
|
-
Shape,
|
|
159
|
-
Contract,
|
|
160
|
-
RelatedModelNameOf<Contract, Model, RelationName>,
|
|
161
|
-
DatabaseId
|
|
162
|
-
>
|
|
77
|
+
: Shape & AcceptRelatedQueryShape<Shape, Contract, RelatedModelNameOf<Contract, Model, RelationName>, DatabaseId>
|
|
163
78
|
: never,
|
|
164
|
-
): Relation<
|
|
165
|
-
WithIncludedRelation<
|
|
166
|
-
Collection,
|
|
167
|
-
Contract,
|
|
168
|
-
Model,
|
|
169
|
-
RelationName,
|
|
170
|
-
QueryShapeValue<Shape>
|
|
171
|
-
>,
|
|
172
|
-
Contract,
|
|
173
|
-
Model,
|
|
174
|
-
DatabaseId
|
|
175
|
-
>;
|
|
79
|
+
): Relation<WithIncludedRelation<Collection, Contract, Model, RelationName, QueryShapeValue<Shape>>, Contract, Model, DatabaseId>;
|
|
176
80
|
}
|
|
177
81
|
: Record<never, never>
|
|
178
82
|
: Record<never, never>;
|
|
@@ -9,57 +9,31 @@ import type {
|
|
|
9
9
|
Collection as PrismaCollection,
|
|
10
10
|
} from "@prisma-next/sql-orm-client";
|
|
11
11
|
import type { Effect, Stream } from "effect";
|
|
12
|
-
import type { PrismaError } from "../error.
|
|
13
|
-
import type { CollectionResult, Relation, RelationQuery } from "../relation.
|
|
14
|
-
import type { IncludeMethod } from "./include.
|
|
12
|
+
import type { PrismaError } from "../error.ts";
|
|
13
|
+
import type { CollectionResult, Relation, RelationQuery } from "../relation.ts";
|
|
14
|
+
import type { IncludeMethod } from "./include.ts";
|
|
15
15
|
|
|
16
16
|
type AnyFunction = (...arguments_: ReadonlyArray<never>) => unknown;
|
|
17
17
|
type AnyPostgresContract = PrismaContract<SqlStorage>;
|
|
18
18
|
type FieldTuple<Row> = readonly [keyof Row & string, ...(keyof Row & string)[]];
|
|
19
19
|
type Simplify<Value> = { [Key in keyof Value]: Value[Key] };
|
|
20
20
|
|
|
21
|
-
type TerminalMethod<Method> = Method extends (
|
|
22
|
-
...arguments_: infer Arguments
|
|
23
|
-
) => PromiseLike<infer Value>
|
|
21
|
+
type TerminalMethod<Method> = Method extends (...arguments_: infer Arguments) => PromiseLike<infer Value>
|
|
24
22
|
? (...arguments_: Arguments) => Effect.Effect<Awaited<Value>, PrismaError>
|
|
25
23
|
: never;
|
|
26
24
|
|
|
27
|
-
type SelectMethod<
|
|
28
|
-
Collection,
|
|
29
|
-
Contract,
|
|
30
|
-
Model extends string,
|
|
31
|
-
DatabaseId,
|
|
32
|
-
> = Contract extends AnyPostgresContract
|
|
33
|
-
? Collection extends PrismaCollection<
|
|
34
|
-
Contract,
|
|
35
|
-
Model,
|
|
36
|
-
infer _Row,
|
|
37
|
-
infer State
|
|
38
|
-
>
|
|
25
|
+
type SelectMethod<Collection, Contract, Model extends string, DatabaseId> = Contract extends AnyPostgresContract
|
|
26
|
+
? Collection extends PrismaCollection<Contract, Model, infer _Row, infer State>
|
|
39
27
|
? {
|
|
40
28
|
select<Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
41
29
|
...fields: Fields
|
|
42
|
-
): Relation<
|
|
43
|
-
PrismaCollection<
|
|
44
|
-
Contract,
|
|
45
|
-
Model,
|
|
46
|
-
Pick<DefaultModelRow<Contract, Model>, Fields[number]>,
|
|
47
|
-
State
|
|
48
|
-
>,
|
|
49
|
-
Contract,
|
|
50
|
-
Model,
|
|
51
|
-
DatabaseId
|
|
52
|
-
>;
|
|
30
|
+
): Relation<PrismaCollection<Contract, Model, Pick<DefaultModelRow<Contract, Model>, Fields[number]>, State>, Contract, Model, DatabaseId>;
|
|
53
31
|
}
|
|
54
32
|
: Record<never, never>
|
|
55
33
|
: Collection extends { select: infer Select extends AnyFunction }
|
|
56
34
|
? {
|
|
57
35
|
select: Select extends (...arguments_: infer Arguments) => infer Result
|
|
58
|
-
? (
|
|
59
|
-
...arguments_: Arguments
|
|
60
|
-
) => Result extends object
|
|
61
|
-
? Relation<Result, Contract, Model, DatabaseId>
|
|
62
|
-
: never
|
|
36
|
+
? (...arguments_: Arguments) => Result extends object ? Relation<Result, Contract, Model, DatabaseId> : never
|
|
63
37
|
: never;
|
|
64
38
|
}
|
|
65
39
|
: Record<never, never>;
|
|
@@ -70,102 +44,45 @@ type AggregateConfigure<Collection> = Collection extends {
|
|
|
70
44
|
? Exclude<Parameters<Method>[1], undefined>
|
|
71
45
|
: never;
|
|
72
46
|
|
|
73
|
-
type AggregateSuccess<
|
|
74
|
-
Collection,
|
|
75
|
-
|
|
76
|
-
Model extends string,
|
|
77
|
-
Spec extends AggregateSpec,
|
|
78
|
-
> =
|
|
79
|
-
Collection extends GroupedCollection<
|
|
80
|
-
Contract,
|
|
81
|
-
Model,
|
|
82
|
-
infer Fields extends FieldTuple<DefaultModelRow<Contract, Model>>
|
|
83
|
-
>
|
|
84
|
-
? Array<
|
|
85
|
-
Simplify<
|
|
86
|
-
Pick<DefaultModelRow<Contract, Model>, Fields[number]> &
|
|
87
|
-
AggregateResult<Spec>
|
|
88
|
-
>
|
|
89
|
-
>
|
|
47
|
+
type AggregateSuccess<Collection, Contract extends AnyPostgresContract, Model extends string, Spec extends AggregateSpec> =
|
|
48
|
+
Collection extends GroupedCollection<Contract, Model, infer Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>
|
|
49
|
+
? Array<Simplify<Pick<DefaultModelRow<Contract, Model>, Fields[number]> & AggregateResult<Spec>>>
|
|
90
50
|
: AggregateResult<Spec>;
|
|
91
51
|
|
|
92
|
-
type AggregateMethod<
|
|
93
|
-
Collection,
|
|
94
|
-
Contract,
|
|
95
|
-
Model extends string,
|
|
96
|
-
> = Contract extends AnyPostgresContract
|
|
52
|
+
type AggregateMethod<Collection, Contract, Model extends string> = Contract extends AnyPostgresContract
|
|
97
53
|
? Collection extends { aggregate: AnyFunction }
|
|
98
54
|
? {
|
|
99
55
|
aggregate<Spec extends AggregateSpec>(
|
|
100
56
|
make: (aggregate: AggregateBuilder<Contract, Model>) => Spec,
|
|
101
57
|
configure?: AggregateConfigure<Collection>,
|
|
102
|
-
): Effect.Effect<
|
|
103
|
-
AggregateSuccess<Collection, Contract, Model, Spec>,
|
|
104
|
-
PrismaError
|
|
105
|
-
>;
|
|
58
|
+
): Effect.Effect<AggregateSuccess<Collection, Contract, Model, Spec>, PrismaError>;
|
|
106
59
|
}
|
|
107
60
|
: Record<never, never>
|
|
108
61
|
: Record<never, never>;
|
|
109
62
|
|
|
110
|
-
type CollectionMethods<
|
|
111
|
-
Collection,
|
|
112
|
-
Contract,
|
|
113
|
-
Model extends string,
|
|
114
|
-
DatabaseId,
|
|
115
|
-
> = Contract extends AnyPostgresContract
|
|
116
|
-
? Collection extends PrismaCollection<
|
|
117
|
-
Contract,
|
|
118
|
-
Model,
|
|
119
|
-
infer _Row,
|
|
120
|
-
infer State
|
|
121
|
-
>
|
|
63
|
+
type CollectionMethods<Collection, Contract, Model extends string, DatabaseId> = Contract extends AnyPostgresContract
|
|
64
|
+
? Collection extends PrismaCollection<Contract, Model, infer _Row, infer State>
|
|
122
65
|
? {
|
|
123
66
|
groupBy<Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
124
67
|
...fields: Fields
|
|
125
|
-
): Relation<
|
|
126
|
-
GroupedCollection<Contract, Model, Fields>,
|
|
127
|
-
Contract,
|
|
128
|
-
Model,
|
|
129
|
-
DatabaseId
|
|
130
|
-
>;
|
|
68
|
+
): Relation<GroupedCollection<Contract, Model, Fields>, Contract, Model, DatabaseId>;
|
|
131
69
|
cursor(
|
|
132
|
-
values: State extends { readonly hasOrderBy: true }
|
|
133
|
-
? Partial<
|
|
134
|
-
Record<keyof DefaultModelRow<Contract, Model> & string, unknown>
|
|
135
|
-
>
|
|
136
|
-
: never,
|
|
137
|
-
): Relation<Collection, Contract, Model, DatabaseId>;
|
|
138
|
-
distinct<Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
139
|
-
...fields: Fields
|
|
70
|
+
values: State extends { readonly hasOrderBy: true } ? Partial<Record<keyof DefaultModelRow<Contract, Model> & string, unknown>> : never,
|
|
140
71
|
): Relation<Collection, Contract, Model, DatabaseId>;
|
|
72
|
+
distinct<Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(...fields: Fields): Relation<Collection, Contract, Model, DatabaseId>;
|
|
141
73
|
distinctOn<Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
142
|
-
...fields: State extends { readonly hasOrderBy: true }
|
|
143
|
-
? Fields
|
|
144
|
-
: never
|
|
74
|
+
...fields: State extends { readonly hasOrderBy: true } ? Fields : never
|
|
145
75
|
): Relation<Collection, Contract, Model, DatabaseId>;
|
|
146
76
|
} & (State extends { readonly hasWhere: true }
|
|
147
77
|
? {
|
|
148
|
-
readonly [Key in
|
|
149
|
-
| "delete"
|
|
150
|
-
| "deleteAll"
|
|
151
|
-
| "deleteCount"]: TerminalMethod<Collection[Key]>;
|
|
78
|
+
readonly [Key in "delete" | "deleteAll" | "deleteCount"]: TerminalMethod<Collection[Key]>;
|
|
152
79
|
}
|
|
153
80
|
: Record<never, never>)
|
|
154
81
|
: Record<never, never>
|
|
155
82
|
: Record<never, never>;
|
|
156
83
|
|
|
157
|
-
type CollectionConveniences<
|
|
158
|
-
Collection,
|
|
159
|
-
Contract,
|
|
160
|
-
Model extends string,
|
|
161
|
-
DatabaseId,
|
|
162
|
-
> = Contract extends AnyPostgresContract
|
|
163
|
-
? Collection extends PrismaCollection<
|
|
164
|
-
Contract,
|
|
165
|
-
Model,
|
|
166
|
-
infer Row,
|
|
167
|
-
infer _State
|
|
168
|
-
>
|
|
84
|
+
type CollectionConveniences<Collection, Contract, Model extends string, DatabaseId> = Contract extends AnyPostgresContract
|
|
85
|
+
? Collection extends PrismaCollection<Contract, Model, infer Row, infer _State>
|
|
169
86
|
? {
|
|
170
87
|
readonly stream: Stream.Stream<Row, PrismaError>;
|
|
171
88
|
count(): RelationQuery<number, Contract, Model, DatabaseId>;
|
|
@@ -180,12 +97,7 @@ type CollectionConveniences<
|
|
|
180
97
|
}
|
|
181
98
|
: Record<never, never>;
|
|
182
99
|
|
|
183
|
-
export type PrismaRelationMethods<
|
|
184
|
-
Collection,
|
|
185
|
-
Contract,
|
|
186
|
-
Model extends string,
|
|
187
|
-
DatabaseId,
|
|
188
|
-
> = SelectMethod<Collection, Contract, Model, DatabaseId> &
|
|
100
|
+
export type PrismaRelationMethods<Collection, Contract, Model extends string, DatabaseId> = SelectMethod<Collection, Contract, Model, DatabaseId> &
|
|
189
101
|
IncludeMethod<Collection, Contract, Model, DatabaseId> &
|
|
190
102
|
AggregateMethod<Collection, Contract, Model> &
|
|
191
103
|
CollectionMethods<Collection, Contract, Model, DatabaseId> &
|
package/src/relation.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Effect } from "effect";
|
|
2
|
-
import type { PrismaError } from "./error.
|
|
3
|
-
import type { PrismaRelationMethods } from "./relation/prisma-methods.
|
|
2
|
+
import type { PrismaError } from "./error.ts";
|
|
3
|
+
import type { PrismaRelationMethods } from "./relation/prisma-methods.ts";
|
|
4
4
|
|
|
5
5
|
type AnyFunction = (...arguments_: ReadonlyArray<never>) => unknown;
|
|
6
6
|
|
|
@@ -10,9 +10,7 @@ export type CollectionResult<Collection> = Collection extends {
|
|
|
10
10
|
? Awaited<Result>
|
|
11
11
|
: never;
|
|
12
12
|
|
|
13
|
-
type NormalizeTerminal<Name, Result> = Name extends "first"
|
|
14
|
-
? import("effect").Option.Option<Exclude<Result, null>>
|
|
15
|
-
: Result;
|
|
13
|
+
type NormalizeTerminal<Name, Result> = Name extends "first" ? import("effect").Option.Option<Exclude<Result, null>> : Result;
|
|
16
14
|
|
|
17
15
|
type WrapReturn<Name, Result, Contract, Model extends string, DatabaseId> =
|
|
18
16
|
Result extends PromiseLike<infer Value>
|
|
@@ -21,13 +19,7 @@ type WrapReturn<Name, Result, Contract, Model extends string, DatabaseId> =
|
|
|
21
19
|
? Relation<Result, Contract, Model, DatabaseId>
|
|
22
20
|
: never;
|
|
23
21
|
|
|
24
|
-
type WrapFunction<
|
|
25
|
-
Name,
|
|
26
|
-
Function_,
|
|
27
|
-
Contract,
|
|
28
|
-
Model extends string,
|
|
29
|
-
DatabaseId,
|
|
30
|
-
> = Function_ extends {
|
|
22
|
+
type WrapFunction<Name, Function_, Contract, Model extends string, DatabaseId> = Function_ extends {
|
|
31
23
|
(...arguments_: infer Arguments1): infer Result1;
|
|
32
24
|
(...arguments_: infer Arguments2): infer Result2;
|
|
33
25
|
(...arguments_: infer Arguments3): infer Result3;
|
|
@@ -35,24 +27,12 @@ type WrapFunction<
|
|
|
35
27
|
(...arguments_: infer Arguments5): infer Result5;
|
|
36
28
|
(...arguments_: infer Arguments6): infer Result6;
|
|
37
29
|
}
|
|
38
|
-
? ((
|
|
39
|
-
...arguments_:
|
|
40
|
-
|
|
41
|
-
((
|
|
42
|
-
|
|
43
|
-
) => WrapReturn<Name,
|
|
44
|
-
((
|
|
45
|
-
...arguments_: Arguments3
|
|
46
|
-
) => WrapReturn<Name, Result3, Contract, Model, DatabaseId>) &
|
|
47
|
-
((
|
|
48
|
-
...arguments_: Arguments4
|
|
49
|
-
) => WrapReturn<Name, Result4, Contract, Model, DatabaseId>) &
|
|
50
|
-
((
|
|
51
|
-
...arguments_: Arguments5
|
|
52
|
-
) => WrapReturn<Name, Result5, Contract, Model, DatabaseId>) &
|
|
53
|
-
((
|
|
54
|
-
...arguments_: Arguments6
|
|
55
|
-
) => WrapReturn<Name, Result6, Contract, Model, DatabaseId>)
|
|
30
|
+
? ((...arguments_: Arguments1) => WrapReturn<Name, Result1, Contract, Model, DatabaseId>) &
|
|
31
|
+
((...arguments_: Arguments2) => WrapReturn<Name, Result2, Contract, Model, DatabaseId>) &
|
|
32
|
+
((...arguments_: Arguments3) => WrapReturn<Name, Result3, Contract, Model, DatabaseId>) &
|
|
33
|
+
((...arguments_: Arguments4) => WrapReturn<Name, Result4, Contract, Model, DatabaseId>) &
|
|
34
|
+
((...arguments_: Arguments5) => WrapReturn<Name, Result5, Contract, Model, DatabaseId>) &
|
|
35
|
+
((...arguments_: Arguments6) => WrapReturn<Name, Result6, Contract, Model, DatabaseId>)
|
|
56
36
|
: never;
|
|
57
37
|
|
|
58
38
|
type FunctionKeys<Value> = {
|
|
@@ -79,20 +59,12 @@ type ExplicitPrismaMethod =
|
|
|
79
59
|
| "variant";
|
|
80
60
|
|
|
81
61
|
type RelationMethods<Collection, Contract, Model extends string, DatabaseId> = {
|
|
82
|
-
readonly [Key in Exclude<
|
|
83
|
-
FunctionKeys<Collection>,
|
|
84
|
-
ExplicitPrismaMethod
|
|
85
|
-
>]: WrapFunction<Key, Collection[Key], Contract, Model, DatabaseId>;
|
|
62
|
+
readonly [Key in Exclude<FunctionKeys<Collection>, ExplicitPrismaMethod>]: WrapFunction<Key, Collection[Key], Contract, Model, DatabaseId>;
|
|
86
63
|
};
|
|
87
64
|
|
|
88
65
|
declare const RelationQueryTypeId: unique symbol;
|
|
89
66
|
|
|
90
|
-
export type RelationQuery<
|
|
91
|
-
Value,
|
|
92
|
-
Contract,
|
|
93
|
-
Model extends string,
|
|
94
|
-
DatabaseId,
|
|
95
|
-
> = Effect.Effect<Value, PrismaError> & {
|
|
67
|
+
export type RelationQuery<Value, Contract, Model extends string, DatabaseId> = Effect.Effect<Value, PrismaError> & {
|
|
96
68
|
readonly [RelationQueryTypeId]: {
|
|
97
69
|
readonly contract: Contract;
|
|
98
70
|
readonly database: (database: DatabaseId) => DatabaseId;
|
|
@@ -100,11 +72,11 @@ export type RelationQuery<
|
|
|
100
72
|
};
|
|
101
73
|
};
|
|
102
74
|
|
|
103
|
-
export type Relation<
|
|
104
|
-
Collection
|
|
105
|
-
Contract
|
|
106
|
-
Model
|
|
107
|
-
DatabaseId
|
|
108
|
-
>
|
|
75
|
+
export type Relation<Collection, Contract = undefined, Model extends string = string, DatabaseId = undefined> = RelationQuery<
|
|
76
|
+
CollectionResult<Collection>,
|
|
77
|
+
Contract,
|
|
78
|
+
Model,
|
|
79
|
+
DatabaseId
|
|
80
|
+
> &
|
|
109
81
|
RelationMethods<Collection, Contract, Model, DatabaseId> &
|
|
110
82
|
PrismaRelationMethods<Collection, Contract, Model, DatabaseId>;
|