@shivaedev/effect-prisma 0.6.4 → 0.7.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 +21 -0
- package/dist/bin/normalize-contract.js +1 -0
- package/dist/bin/normalize-contract.js.map +1 -1
- package/dist/error.js +4 -4
- package/dist/error.js.map +1 -1
- package/dist/internal/adapters/transaction-settlement.d.ts.map +1 -1
- package/dist/internal/adapters/transaction-settlement.js +1 -1
- package/dist/internal/adapters/transaction-settlement.js.map +1 -1
- package/dist/internal/client-lifecycle.d.ts +2 -2
- 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 +0 -4
- package/dist/internal/contract-normalization.d.ts.map +1 -1
- package/dist/internal/contract-normalization.js +4 -7
- package/dist/internal/contract-normalization.js.map +1 -1
- package/dist/internal/database-facade.d.ts +0 -5
- package/dist/internal/database-facade.d.ts.map +1 -1
- package/dist/internal/database-facade.js +2 -7
- package/dist/internal/database-facade.js.map +1 -1
- package/dist/internal/database-factory.d.ts +0 -4
- package/dist/internal/database-factory.d.ts.map +1 -1
- package/dist/internal/database-factory.js +1 -7
- package/dist/internal/database-factory.js.map +1 -1
- package/dist/internal/database-types.d.ts +2 -6
- package/dist/internal/database-types.d.ts.map +1 -1
- package/dist/internal/dynamic.d.ts +1 -1
- package/dist/internal/dynamic.d.ts.map +1 -1
- package/dist/internal/dynamic.js.map +1 -1
- package/dist/internal/executor.d.ts +3 -7
- package/dist/internal/executor.d.ts.map +1 -1
- package/dist/internal/promise.js +1 -1
- package/dist/internal/promise.js.map +1 -1
- package/dist/internal/recipe.d.ts +3 -3
- package/dist/internal/recipe.d.ts.map +1 -1
- package/dist/internal/recipe.js +2 -2
- package/dist/internal/recipe.js.map +1 -1
- package/dist/internal/relation-result.js.map +1 -1
- package/dist/internal/relation-runtime.js +3 -3
- package/dist/internal/relation-runtime.js.map +1 -1
- 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 +0 -26
- package/dist/internal/sqlite-datetime.d.ts.map +1 -1
- package/dist/internal/sqlite-datetime.js +13 -34
- package/dist/internal/sqlite-datetime.js.map +1 -1
- package/dist/internal/sqlite-pragmas.d.ts +1 -13
- package/dist/internal/sqlite-pragmas.d.ts.map +1 -1
- package/dist/internal/sqlite-pragmas.js +2 -12
- package/dist/internal/sqlite-pragmas.js.map +1 -1
- package/dist/internal/transaction.d.ts +1 -1
- package/dist/internal/transaction.d.ts.map +1 -1
- package/dist/internal/transaction.js +2 -2
- package/dist/internal/transaction.js.map +1 -1
- package/dist/relation/include-metadata.d.ts +1 -1
- package/dist/relation/include-metadata.d.ts.map +1 -1
- package/dist/relation/include.d.ts +6 -3
- package/dist/relation/include.d.ts.map +1 -1
- package/dist/relation/prisma-methods.d.ts +14 -14
- 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 +2 -7
- package/dist/sqlite.d.ts.map +1 -1
- package/dist/sqlite.js.map +1 -1
- package/dist/testing/types.d.ts +5 -5
- package/dist/testing/types.d.ts.map +1 -1
- package/dist/testing/vitest.d.ts.map +1 -1
- package/dist/testing/vitest.js.map +1 -1
- package/package.json +34 -36
- package/src/bin/normalize-contract.ts +1 -0
- package/src/error.ts +4 -4
- package/src/internal/adapters/transaction-settlement.ts +4 -1
- package/src/internal/client-lifecycle.ts +2 -2
- package/src/internal/contract-normalization.ts +4 -7
- package/src/internal/database-facade.ts +2 -7
- package/src/internal/database-factory.ts +4 -8
- package/src/internal/database-types.ts +3 -7
- package/src/internal/dynamic.ts +1 -1
- package/src/internal/executor.ts +3 -7
- package/src/internal/promise.ts +1 -1
- package/src/internal/recipe.ts +8 -8
- package/src/internal/relation-result.ts +1 -1
- package/src/internal/relation-runtime.ts +4 -4
- package/src/internal/relation-stream.ts +4 -5
- package/src/internal/sqlite-datetime.ts +13 -34
- package/src/internal/sqlite-pragmas.ts +3 -13
- package/src/internal/transaction.ts +3 -3
- package/src/relation/include-metadata.ts +1 -1
- package/src/relation/include.ts +35 -33
- package/src/relation/prisma-methods.ts +19 -17
- package/src/relation.ts +2 -2
- package/src/sqlite.ts +2 -7
- package/src/testing/types.ts +6 -6
- package/src/testing/vitest.ts +1 -1
package/src/relation/include.ts
CHANGED
|
@@ -43,40 +43,42 @@ type WithIncludedRelation<Collection, Contract extends AnyPostgresContract, Mode
|
|
|
43
43
|
? PrismaCollection<Contract, Model, Simplify<Row & { readonly [Key in RelationName]: Value }>, State>
|
|
44
44
|
: never;
|
|
45
45
|
|
|
46
|
+
interface IncludeOverloads<Collection, Contract extends AnyPostgresContract, Model extends string, DatabaseId> {
|
|
47
|
+
<RelationName extends RelationNames<Contract, Model>>(
|
|
48
|
+
relationName: RelationName,
|
|
49
|
+
): Relation<
|
|
50
|
+
WithIncludedRelation<
|
|
51
|
+
Collection,
|
|
52
|
+
Contract,
|
|
53
|
+
Model,
|
|
54
|
+
RelationName,
|
|
55
|
+
IncludedRelationValue<Contract, Model, RelationName, DefaultModelRow<Contract, RelatedModelNameOf<Contract, Model, RelationName>>>
|
|
56
|
+
>,
|
|
57
|
+
Contract,
|
|
58
|
+
Model,
|
|
59
|
+
DatabaseId
|
|
60
|
+
>;
|
|
61
|
+
<RelationName extends RelationNames<Contract, Model>, Query>(
|
|
62
|
+
relationName: RelationName,
|
|
63
|
+
query: Query & AcceptRelatedQuery<Query, Contract, RelatedModelNameOf<Contract, Model, RelationName>, DatabaseId>,
|
|
64
|
+
): Relation<
|
|
65
|
+
WithIncludedRelation<Collection, Contract, Model, RelationName, IncludedQueryValue<Query, Contract, Model, RelationName>>,
|
|
66
|
+
Contract,
|
|
67
|
+
Model,
|
|
68
|
+
DatabaseId
|
|
69
|
+
>;
|
|
70
|
+
<RelationName extends RelationNames<Contract, Model>, Shape extends Readonly<Record<string, unknown>>>(
|
|
71
|
+
relationName: RelationName,
|
|
72
|
+
shape: IsToManyRelation<Contract, Model, RelationName> extends true
|
|
73
|
+
? keyof Shape extends never
|
|
74
|
+
? never
|
|
75
|
+
: Shape & AcceptRelatedQueryShape<Shape, Contract, RelatedModelNameOf<Contract, Model, RelationName>, DatabaseId>
|
|
76
|
+
: never,
|
|
77
|
+
): Relation<WithIncludedRelation<Collection, Contract, Model, RelationName, QueryShapeValue<Shape>>, Contract, Model, DatabaseId>;
|
|
78
|
+
}
|
|
79
|
+
|
|
46
80
|
export type IncludeMethod<Collection, Contract, Model extends string, DatabaseId> = Contract extends AnyPostgresContract
|
|
47
81
|
? Collection extends PrismaCollection<Contract, Model, infer _Row, infer _State>
|
|
48
|
-
? {
|
|
49
|
-
include<RelationName extends RelationNames<Contract, Model>>(
|
|
50
|
-
relationName: RelationName,
|
|
51
|
-
): Relation<
|
|
52
|
-
WithIncludedRelation<
|
|
53
|
-
Collection,
|
|
54
|
-
Contract,
|
|
55
|
-
Model,
|
|
56
|
-
RelationName,
|
|
57
|
-
IncludedRelationValue<Contract, Model, RelationName, DefaultModelRow<Contract, RelatedModelNameOf<Contract, Model, RelationName>>>
|
|
58
|
-
>,
|
|
59
|
-
Contract,
|
|
60
|
-
Model,
|
|
61
|
-
DatabaseId
|
|
62
|
-
>;
|
|
63
|
-
include<RelationName extends RelationNames<Contract, Model>, Query>(
|
|
64
|
-
relationName: RelationName,
|
|
65
|
-
query: Query & AcceptRelatedQuery<Query, Contract, RelatedModelNameOf<Contract, Model, RelationName>, DatabaseId>,
|
|
66
|
-
): Relation<
|
|
67
|
-
WithIncludedRelation<Collection, Contract, Model, RelationName, IncludedQueryValue<Query, Contract, Model, RelationName>>,
|
|
68
|
-
Contract,
|
|
69
|
-
Model,
|
|
70
|
-
DatabaseId
|
|
71
|
-
>;
|
|
72
|
-
include<RelationName extends RelationNames<Contract, Model>, Shape extends Readonly<Record<string, unknown>>>(
|
|
73
|
-
relationName: RelationName,
|
|
74
|
-
shape: IsToManyRelation<Contract, Model, RelationName> extends true
|
|
75
|
-
? keyof Shape extends never
|
|
76
|
-
? never
|
|
77
|
-
: Shape & AcceptRelatedQueryShape<Shape, Contract, RelatedModelNameOf<Contract, Model, RelationName>, DatabaseId>
|
|
78
|
-
: never,
|
|
79
|
-
): Relation<WithIncludedRelation<Collection, Contract, Model, RelationName, QueryShapeValue<Shape>>, Contract, Model, DatabaseId>;
|
|
80
|
-
}
|
|
82
|
+
? { include: IncludeOverloads<Collection, Contract, Model, DatabaseId> }
|
|
81
83
|
: Record<never, never>
|
|
82
84
|
: Record<never, never>;
|
|
@@ -13,7 +13,7 @@ import type { PrismaError } from "../error.ts";
|
|
|
13
13
|
import type { CollectionResult, Relation, RelationQuery } from "../relation.ts";
|
|
14
14
|
import type { IncludeMethod } from "./include.ts";
|
|
15
15
|
|
|
16
|
-
type AnyFunction = (...arguments_:
|
|
16
|
+
type AnyFunction = (...arguments_: readonly 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] };
|
|
@@ -25,9 +25,9 @@ type TerminalMethod<Method> = Method extends (...arguments_: infer Arguments) =>
|
|
|
25
25
|
type SelectMethod<Collection, Contract, Model extends string, DatabaseId> = Contract extends AnyPostgresContract
|
|
26
26
|
? Collection extends PrismaCollection<Contract, Model, infer _Row, infer State>
|
|
27
27
|
? {
|
|
28
|
-
select<Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
28
|
+
select: <Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
29
29
|
...fields: Fields
|
|
30
|
-
)
|
|
30
|
+
) => Relation<PrismaCollection<Contract, Model, Pick<DefaultModelRow<Contract, Model>, Fields[number]>, State>, Contract, Model, DatabaseId>;
|
|
31
31
|
}
|
|
32
32
|
: Record<never, never>
|
|
33
33
|
: Collection extends { select: infer Select extends AnyFunction }
|
|
@@ -46,16 +46,16 @@ type AggregateConfigure<Collection> = Collection extends {
|
|
|
46
46
|
|
|
47
47
|
type AggregateSuccess<Collection, Contract extends AnyPostgresContract, Model extends string, Spec extends AggregateSpec> =
|
|
48
48
|
Collection extends GroupedCollection<Contract, Model, infer Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>
|
|
49
|
-
?
|
|
49
|
+
? Simplify<Pick<DefaultModelRow<Contract, Model>, Fields[number]> & AggregateResult<Spec>>[]
|
|
50
50
|
: AggregateResult<Spec>;
|
|
51
51
|
|
|
52
52
|
type AggregateMethod<Collection, Contract, Model extends string> = Contract extends AnyPostgresContract
|
|
53
53
|
? Collection extends { aggregate: AnyFunction }
|
|
54
54
|
? {
|
|
55
|
-
aggregate<Spec extends AggregateSpec>(
|
|
55
|
+
aggregate: <Spec extends AggregateSpec>(
|
|
56
56
|
make: (aggregate: AggregateBuilder<Contract, Model>) => Spec,
|
|
57
57
|
configure?: AggregateConfigure<Collection>,
|
|
58
|
-
)
|
|
58
|
+
) => Effect.Effect<AggregateSuccess<Collection, Contract, Model, Spec>, PrismaError>;
|
|
59
59
|
}
|
|
60
60
|
: Record<never, never>
|
|
61
61
|
: Record<never, never>;
|
|
@@ -63,16 +63,18 @@ type AggregateMethod<Collection, Contract, Model extends string> = Contract exte
|
|
|
63
63
|
type CollectionMethods<Collection, Contract, Model extends string, DatabaseId> = Contract extends AnyPostgresContract
|
|
64
64
|
? Collection extends PrismaCollection<Contract, Model, infer _Row, infer State>
|
|
65
65
|
? {
|
|
66
|
-
groupBy<Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
66
|
+
groupBy: <Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
67
67
|
...fields: Fields
|
|
68
|
-
)
|
|
69
|
-
cursor(
|
|
68
|
+
) => Relation<GroupedCollection<Contract, Model, Fields>, Contract, Model, DatabaseId>;
|
|
69
|
+
cursor: (
|
|
70
70
|
values: State extends { readonly hasOrderBy: true } ? Partial<Record<keyof DefaultModelRow<Contract, Model> & string, unknown>> : never,
|
|
71
|
-
)
|
|
72
|
-
distinct<Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
73
|
-
|
|
71
|
+
) => Relation<Collection, Contract, Model, DatabaseId>;
|
|
72
|
+
distinct: <Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
73
|
+
...fields: Fields
|
|
74
|
+
) => Relation<Collection, Contract, Model, DatabaseId>;
|
|
75
|
+
distinctOn: <Fields extends FieldTuple<DefaultModelRow<Contract, Model>>>(
|
|
74
76
|
...fields: State extends { readonly hasOrderBy: true } ? Fields : never
|
|
75
|
-
)
|
|
77
|
+
) => Relation<Collection, Contract, Model, DatabaseId>;
|
|
76
78
|
} & (State extends { readonly hasWhere: true }
|
|
77
79
|
? {
|
|
78
80
|
readonly [Key in "delete" | "deleteAll" | "deleteCount"]: TerminalMethod<Collection[Key]>;
|
|
@@ -85,15 +87,15 @@ type CollectionConveniences<Collection, Contract, Model extends string, Database
|
|
|
85
87
|
? Collection extends PrismaCollection<Contract, Model, infer Row, infer _State>
|
|
86
88
|
? {
|
|
87
89
|
readonly stream: Stream.Stream<Row, PrismaError>;
|
|
88
|
-
count()
|
|
89
|
-
exists()
|
|
90
|
+
count: () => RelationQuery<number, Contract, Model, DatabaseId>;
|
|
91
|
+
exists: () => Effect.Effect<boolean, PrismaError>;
|
|
90
92
|
}
|
|
91
93
|
: Record<never, never>
|
|
92
94
|
: CollectionResult<Collection> extends ReadonlyArray<infer Row>
|
|
93
95
|
? {
|
|
94
96
|
readonly stream: Stream.Stream<Row, PrismaError>;
|
|
95
|
-
count()
|
|
96
|
-
exists()
|
|
97
|
+
count: () => Effect.Effect<number, PrismaError>;
|
|
98
|
+
exists: () => Effect.Effect<boolean, PrismaError>;
|
|
97
99
|
}
|
|
98
100
|
: Record<never, never>;
|
|
99
101
|
|
package/src/relation.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { Effect } from "effect";
|
|
|
2
2
|
import type { PrismaError } from "./error.ts";
|
|
3
3
|
import type { PrismaRelationMethods } from "./relation/prisma-methods.ts";
|
|
4
4
|
|
|
5
|
-
type AnyFunction = (...arguments_:
|
|
5
|
+
type AnyFunction = (...arguments_: readonly never[]) => unknown;
|
|
6
6
|
|
|
7
7
|
export type CollectionResult<Collection> = Collection extends {
|
|
8
|
-
all()
|
|
8
|
+
all: () => infer Result;
|
|
9
9
|
}
|
|
10
10
|
? Awaited<Result>
|
|
11
11
|
: never;
|
package/src/sqlite.ts
CHANGED
|
@@ -10,16 +10,11 @@ import { fromPrismaPromise } from "./internal/promise.ts";
|
|
|
10
10
|
import { decodeSqliteDatetimesAsUtc } from "./internal/sqlite-datetime.ts";
|
|
11
11
|
import { applySqlitePragmas, assertFileBackedPath } from "./internal/sqlite-pragmas.ts";
|
|
12
12
|
|
|
13
|
-
export const defaultSqlitePragmas:
|
|
13
|
+
export const defaultSqlitePragmas: readonly string[] = ["journal_mode=WAL"];
|
|
14
14
|
|
|
15
15
|
export interface SqliteDatabaseLayerOptions extends SqliteOptionsBase {
|
|
16
|
-
/** Path to the database file. In-memory databases are not supported. */
|
|
17
16
|
readonly path: string;
|
|
18
|
-
|
|
19
|
-
* Pragmas applied once when the Layer connects. Defaults to
|
|
20
|
-
* {@link defaultSqlitePragmas}; pass `[]` to skip them.
|
|
21
|
-
*/
|
|
22
|
-
readonly pragmas?: ReadonlyArray<string>;
|
|
17
|
+
readonly pragmas?: readonly string[];
|
|
23
18
|
}
|
|
24
19
|
|
|
25
20
|
type SqliteFactoryOptions<Contract extends AnySqlContract> =
|
package/src/testing/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TestContext, Vitest } from "@effect/vitest";
|
|
2
|
-
import type { EffectClock, EffectTestOptions } from "@shivaedev/effect-test";
|
|
3
2
|
import type { Effect, Layer } from "effect";
|
|
3
|
+
import type { EffectClock, EffectTestOptions } from "@shivaedev/effect-test";
|
|
4
4
|
import type { AnyDatabase, DatabaseServiceOf } from "../database.ts";
|
|
5
5
|
|
|
6
6
|
export type { AnyDatabase } from "../database.ts";
|
|
@@ -13,18 +13,18 @@ export type DatabaseTest<Database extends AnyDatabase, Provided> = <A, Eff exten
|
|
|
13
13
|
) => void;
|
|
14
14
|
|
|
15
15
|
export interface DatabaseTester<Database extends AnyDatabase, Provided> extends DatabaseTest<Database, Provided> {
|
|
16
|
-
readonly skip: DatabaseTest<Database, Provided>;
|
|
17
|
-
readonly skipIf: (condition: unknown) => DatabaseTest<Database, Provided>;
|
|
18
|
-
readonly runIf: (condition: unknown) => DatabaseTest<Database, Provided>;
|
|
19
|
-
readonly only: DatabaseTest<Database, Provided>;
|
|
20
16
|
readonly each: <Item>(
|
|
21
|
-
cases:
|
|
17
|
+
cases: readonly Item[],
|
|
22
18
|
) => <A, Eff extends Effect.Effect<unknown, unknown, Provided>>(
|
|
23
19
|
name: string,
|
|
24
20
|
body: (item: Item, database: DatabaseService<Database>, context: TestContext) => Generator<Eff, A, never>,
|
|
25
21
|
options?: number | EffectTestOptions,
|
|
26
22
|
) => void;
|
|
27
23
|
readonly fails: DatabaseTest<Database, Provided>;
|
|
24
|
+
readonly only: DatabaseTest<Database, Provided>;
|
|
25
|
+
readonly runIf: (condition: unknown) => DatabaseTest<Database, Provided>;
|
|
26
|
+
readonly skip: DatabaseTest<Database, Provided>;
|
|
27
|
+
readonly skipIf: (condition: unknown) => DatabaseTest<Database, Provided>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export type DatabaseIt<Database extends AnyDatabase, Provided> = Vitest.Methods & {
|
package/src/testing/vitest.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { it as effectIt } from "@effect/vitest";
|
|
2
|
-
import { type EffectClock, makeEffectIt } from "@shivaedev/effect-test";
|
|
3
2
|
import type { Effect, Layer } from "effect";
|
|
3
|
+
import { type EffectClock, makeEffectIt } from "@shivaedev/effect-test";
|
|
4
4
|
import { withTestTransaction } from "./transaction.ts";
|
|
5
5
|
import type { AnyDatabase, DatabaseIt, MakeDatabaseItOptions } from "./types.ts";
|
|
6
6
|
|