@shivaedev/effect-prisma 0.6.2 → 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 +13 -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 +6 -6
- 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
package/src/sqlite.ts
CHANGED
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
import sqlite, {
|
|
2
|
-
type SqliteClient,
|
|
3
|
-
type SqliteOptionsBase,
|
|
4
|
-
} from "@prisma-next/sqlite/runtime";
|
|
1
|
+
import sqlite, { type SqliteClient, type SqliteOptionsBase } from "@prisma-next/sqlite/runtime";
|
|
5
2
|
import { type Layer, Semaphore } from "effect";
|
|
6
|
-
import type { PrismaError } from "./error.
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "./internal/
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type DefaultModels,
|
|
16
|
-
makeSqlDatabase,
|
|
17
|
-
} from "./internal/database-factory.js";
|
|
18
|
-
import type { AnySqlContract } from "./internal/executor.js";
|
|
19
|
-
import { fromPrismaPromise } from "./internal/promise.js";
|
|
20
|
-
import { decodeSqliteDatetimesAsUtc } from "./internal/sqlite-datetime.js";
|
|
21
|
-
import {
|
|
22
|
-
applySqlitePragmas,
|
|
23
|
-
assertFileBackedPath,
|
|
24
|
-
} from "./internal/sqlite-pragmas.js";
|
|
3
|
+
import type { PrismaError } from "./error.ts";
|
|
4
|
+
import { acquireConnectedClient, assertAvailableModelNames } from "./internal/client-lifecycle.ts";
|
|
5
|
+
import { contractModels } from "./internal/database-facade.ts";
|
|
6
|
+
import { makeSqlDatabase } from "./internal/database-factory.ts";
|
|
7
|
+
import type { DatabaseIdentifier, DatabaseIdentifierLiteral, DatabaseServiceHolder, DefaultModels } from "./internal/database-types.ts";
|
|
8
|
+
import type { AnySqlContract } from "./internal/executor.ts";
|
|
9
|
+
import { fromPrismaPromise } from "./internal/promise.ts";
|
|
10
|
+
import { decodeSqliteDatetimesAsUtc } from "./internal/sqlite-datetime.ts";
|
|
11
|
+
import { applySqlitePragmas, assertFileBackedPath } from "./internal/sqlite-pragmas.ts";
|
|
25
12
|
|
|
26
13
|
export const defaultSqlitePragmas: ReadonlyArray<string> = ["journal_mode=WAL"];
|
|
27
14
|
|
|
@@ -45,15 +32,18 @@ type SqliteFactoryOptions<Contract extends AnySqlContract> =
|
|
|
45
32
|
readonly contract?: never;
|
|
46
33
|
};
|
|
47
34
|
|
|
48
|
-
export interface SqliteDatabaseDefinition<
|
|
49
|
-
Contract
|
|
50
|
-
|
|
51
|
-
> extends DatabaseServiceHolder<Contract, Identifier> {
|
|
52
|
-
readonly layer: (
|
|
53
|
-
options: SqliteDatabaseLayerOptions,
|
|
54
|
-
) => Layer.Layer<DatabaseIdentifier<Contract, Identifier>, PrismaError>;
|
|
35
|
+
export interface SqliteDatabaseDefinition<Contract extends AnySqlContract, Identifier extends string>
|
|
36
|
+
extends DatabaseServiceHolder<Contract, Identifier> {
|
|
37
|
+
readonly layer: (options: SqliteDatabaseLayerOptions) => Layer.Layer<DatabaseIdentifier<Contract, Identifier>, PrismaError>;
|
|
55
38
|
}
|
|
56
39
|
|
|
40
|
+
const clientOptions = ({ path, extensions, middleware, verifyMarker }: SqliteDatabaseLayerOptions) => ({
|
|
41
|
+
path,
|
|
42
|
+
...(extensions === undefined ? {} : { extensions }),
|
|
43
|
+
...(middleware === undefined ? {} : { middleware }),
|
|
44
|
+
...(verifyMarker === undefined ? {} : { verifyMarker }),
|
|
45
|
+
});
|
|
46
|
+
|
|
57
47
|
export const makeSqliteDatabase =
|
|
58
48
|
<const Contract extends AnySqlContract>() =>
|
|
59
49
|
<const Identifier extends string>(
|
|
@@ -62,55 +52,44 @@ export const makeSqliteDatabase =
|
|
|
62
52
|
): SqliteDatabaseDefinition<Contract, Identifier> => {
|
|
63
53
|
type Models = DefaultModels<Contract>;
|
|
64
54
|
|
|
65
|
-
return makeSqlDatabase<Contract, Identifier, SqliteDatabaseLayerOptions>(
|
|
66
|
-
|
|
67
|
-
(layerOptions
|
|
68
|
-
assertFileBackedPath(layerOptions.path);
|
|
69
|
-
applySqlitePragmas(
|
|
70
|
-
layerOptions.path,
|
|
71
|
-
layerOptions.pragmas ?? defaultSqlitePragmas,
|
|
72
|
-
);
|
|
55
|
+
return makeSqlDatabase<Contract, Identifier, SqliteDatabaseLayerOptions>(identifier, (layerOptions) => {
|
|
56
|
+
assertFileBackedPath(layerOptions.path);
|
|
57
|
+
applySqlitePragmas(layerOptions.path, layerOptions.pragmas ?? defaultSqlitePragmas);
|
|
73
58
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
})
|
|
86
|
-
: sqlite<Contract>({
|
|
87
|
-
...clientOptions,
|
|
88
|
-
contract: options.contract,
|
|
89
|
-
});
|
|
59
|
+
const forwarded = clientOptions(layerOptions);
|
|
60
|
+
const client: SqliteClient<Contract> =
|
|
61
|
+
options.contract === undefined
|
|
62
|
+
? sqlite<Contract>({
|
|
63
|
+
...forwarded,
|
|
64
|
+
contractJson: options.contractJson,
|
|
65
|
+
})
|
|
66
|
+
: sqlite<Contract>({
|
|
67
|
+
...forwarded,
|
|
68
|
+
contract: options.contract,
|
|
69
|
+
});
|
|
90
70
|
|
|
91
|
-
|
|
71
|
+
decodeSqliteDatetimesAsUtc(client.context);
|
|
92
72
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
) as SqliteDatabaseDefinition<Contract, Identifier>;
|
|
73
|
+
return fromPrismaPromise(() =>
|
|
74
|
+
acquireConnectedClient(client, () => {
|
|
75
|
+
// The SQLite client already exposes the unbound namespace.
|
|
76
|
+
const models = contractModels<Models>(client.orm);
|
|
77
|
+
const accessSemaphore = Semaphore.makeUnsafe(1);
|
|
78
|
+
assertAvailableModelNames(Object.keys(models));
|
|
79
|
+
return {
|
|
80
|
+
client,
|
|
81
|
+
identity: {},
|
|
82
|
+
liveness: {
|
|
83
|
+
closedCode: "RUNTIME.DATABASE_CLOSED",
|
|
84
|
+
open: true,
|
|
85
|
+
},
|
|
86
|
+
mode: "root",
|
|
87
|
+
models,
|
|
88
|
+
querySemaphore: accessSemaphore,
|
|
89
|
+
transactionIdentity: undefined,
|
|
90
|
+
transactionSemaphore: accessSemaphore,
|
|
91
|
+
};
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
});
|
|
116
95
|
};
|
|
@@ -1,38 +1,25 @@
|
|
|
1
1
|
import type { Effect } from "effect";
|
|
2
|
-
import type { PrismaError } from "../error.
|
|
3
|
-
import { getDatabaseTesting } from "../internal/testing.
|
|
4
|
-
import type { AnyDatabase } from "./types.
|
|
2
|
+
import type { PrismaError } from "../error.ts";
|
|
3
|
+
import { getDatabaseTesting } from "../internal/testing.ts";
|
|
4
|
+
import type { AnyDatabase } from "./types.ts";
|
|
5
5
|
|
|
6
|
-
type
|
|
7
|
-
<Database extends AnyDatabase>(
|
|
8
|
-
database: Database,
|
|
9
|
-
): <A, E, R>(
|
|
10
|
-
program: Effect.Effect<A, E, R> &
|
|
11
|
-
(Effect.Services<Database> extends R ? unknown : never),
|
|
12
|
-
) => Effect.Effect<
|
|
13
|
-
A,
|
|
14
|
-
E | PrismaError,
|
|
15
|
-
Effect.Services<Database> | Exclude<R, Effect.Services<Database>>
|
|
16
|
-
>;
|
|
17
|
-
<Database extends AnyDatabase, A, E, R>(
|
|
18
|
-
database: Database,
|
|
19
|
-
program: Effect.Effect<A, E, R> &
|
|
20
|
-
(Effect.Services<Database> extends R ? unknown : never),
|
|
21
|
-
): Effect.Effect<
|
|
22
|
-
A,
|
|
23
|
-
E | PrismaError,
|
|
24
|
-
Effect.Services<Database> | Exclude<R, Effect.Services<Database>>
|
|
25
|
-
>;
|
|
26
|
-
};
|
|
6
|
+
type TestProgram<Database extends AnyDatabase, A, E, R> = Effect.Effect<A, E, R> & (Effect.Services<Database> extends R ? unknown : never);
|
|
27
7
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
8
|
+
type TestTransaction<Database extends AnyDatabase, A, E, R> = Effect.Effect<
|
|
9
|
+
A,
|
|
10
|
+
E | PrismaError,
|
|
11
|
+
Effect.Services<Database> | Exclude<R, Effect.Services<Database>>
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
export function withTestTransaction<Database extends AnyDatabase>(
|
|
15
|
+
database: Database,
|
|
16
|
+
): <A, E, R>(program: TestProgram<Database, A, E, R>) => TestTransaction<Database, A, E, R>;
|
|
17
|
+
export function withTestTransaction<Database extends AnyDatabase, A, E, R>(
|
|
18
|
+
database: Database,
|
|
19
|
+
program: TestProgram<Database, A, E, R>,
|
|
20
|
+
): TestTransaction<Database, A, E, R>;
|
|
21
|
+
export function withTestTransaction(database: AnyDatabase, program?: Effect.Effect<unknown, unknown, unknown>): unknown {
|
|
22
|
+
const run = (effect: Effect.Effect<unknown, unknown, unknown>) => getDatabaseTesting<unknown>(database).withTestTransaction(effect);
|
|
36
23
|
|
|
37
24
|
return program === undefined ? run : run(program);
|
|
38
|
-
}
|
|
25
|
+
}
|
package/src/testing/types.ts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import type { TestContext, Vitest } from "@effect/vitest";
|
|
2
2
|
import type { EffectClock, EffectTestOptions } from "@shivaedev/effect-test";
|
|
3
3
|
import type { Effect, Layer } from "effect";
|
|
4
|
-
import type { AnyDatabase, DatabaseServiceOf } from "../database.
|
|
4
|
+
import type { AnyDatabase, DatabaseServiceOf } from "../database.ts";
|
|
5
5
|
|
|
6
|
-
export type { AnyDatabase } from "../database.
|
|
7
|
-
export type DatabaseService<Database extends AnyDatabase> =
|
|
8
|
-
DatabaseServiceOf<Database>;
|
|
6
|
+
export type { AnyDatabase } from "../database.ts";
|
|
7
|
+
export type DatabaseService<Database extends AnyDatabase> = DatabaseServiceOf<Database>;
|
|
9
8
|
|
|
10
|
-
export type DatabaseTest<Database extends AnyDatabase, Provided> = <
|
|
11
|
-
A,
|
|
12
|
-
Eff extends Effect.Effect<unknown, unknown, Provided>,
|
|
13
|
-
>(
|
|
9
|
+
export type DatabaseTest<Database extends AnyDatabase, Provided> = <A, Eff extends Effect.Effect<unknown, unknown, Provided>>(
|
|
14
10
|
name: string,
|
|
15
|
-
body: (
|
|
16
|
-
database: DatabaseService<Database>,
|
|
17
|
-
context: TestContext,
|
|
18
|
-
) => Generator<Eff, A, never>,
|
|
11
|
+
body: (database: DatabaseService<Database>, context: TestContext) => Generator<Eff, A, never>,
|
|
19
12
|
options?: number | EffectTestOptions,
|
|
20
13
|
) => void;
|
|
21
14
|
|
|
22
|
-
export interface DatabaseTester<Database extends AnyDatabase, Provided>
|
|
23
|
-
extends DatabaseTest<Database, Provided> {
|
|
15
|
+
export interface DatabaseTester<Database extends AnyDatabase, Provided> extends DatabaseTest<Database, Provided> {
|
|
24
16
|
readonly skip: DatabaseTest<Database, Provided>;
|
|
25
17
|
readonly skipIf: (condition: unknown) => DatabaseTest<Database, Provided>;
|
|
26
18
|
readonly runIf: (condition: unknown) => DatabaseTest<Database, Provided>;
|
|
@@ -29,28 +21,17 @@ export interface DatabaseTester<Database extends AnyDatabase, Provided>
|
|
|
29
21
|
cases: ReadonlyArray<Item>,
|
|
30
22
|
) => <A, Eff extends Effect.Effect<unknown, unknown, Provided>>(
|
|
31
23
|
name: string,
|
|
32
|
-
body: (
|
|
33
|
-
item: Item,
|
|
34
|
-
database: DatabaseService<Database>,
|
|
35
|
-
context: TestContext,
|
|
36
|
-
) => Generator<Eff, A, never>,
|
|
24
|
+
body: (item: Item, database: DatabaseService<Database>, context: TestContext) => Generator<Eff, A, never>,
|
|
37
25
|
options?: number | EffectTestOptions,
|
|
38
26
|
) => void;
|
|
39
27
|
readonly fails: DatabaseTest<Database, Provided>;
|
|
40
28
|
}
|
|
41
29
|
|
|
42
|
-
export type DatabaseIt<
|
|
43
|
-
Database extends AnyDatabase,
|
|
44
|
-
Provided,
|
|
45
|
-
> = Vitest.Methods & {
|
|
30
|
+
export type DatabaseIt<Database extends AnyDatabase, Provided> = Vitest.Methods & {
|
|
46
31
|
readonly effectDB: DatabaseTester<Database, Provided>;
|
|
47
32
|
};
|
|
48
33
|
|
|
49
|
-
export interface MakeDatabaseItOptions<
|
|
50
|
-
Database extends AnyDatabase,
|
|
51
|
-
Provided,
|
|
52
|
-
LayerError,
|
|
53
|
-
> {
|
|
34
|
+
export interface MakeDatabaseItOptions<Database extends AnyDatabase, Provided, LayerError> {
|
|
54
35
|
readonly clock?: EffectClock;
|
|
55
36
|
readonly database: Database;
|
|
56
37
|
readonly layer: Layer.Layer<Provided, LayerError>;
|
package/src/testing/vitest.ts
CHANGED
|
@@ -1,38 +1,24 @@
|
|
|
1
1
|
import { it as effectIt } from "@effect/vitest";
|
|
2
|
-
import { makeEffectIt } from "@shivaedev/effect-test";
|
|
2
|
+
import { type EffectClock, makeEffectIt } from "@shivaedev/effect-test";
|
|
3
3
|
import type { Effect, Layer } from "effect";
|
|
4
|
-
import { withTestTransaction } from "./transaction.
|
|
5
|
-
import type {
|
|
6
|
-
AnyDatabase,
|
|
7
|
-
DatabaseIt,
|
|
8
|
-
DatabaseService,
|
|
9
|
-
MakeDatabaseItOptions,
|
|
10
|
-
} from "./types.js";
|
|
4
|
+
import { withTestTransaction } from "./transaction.ts";
|
|
5
|
+
import type { AnyDatabase, DatabaseIt, MakeDatabaseItOptions } from "./types.ts";
|
|
11
6
|
|
|
12
|
-
export
|
|
13
|
-
Database extends AnyDatabase,
|
|
14
|
-
Provided,
|
|
15
|
-
LayerError,
|
|
16
|
-
>(
|
|
7
|
+
export function makeDatabaseIt<Database extends AnyDatabase, Provided, LayerError>(
|
|
17
8
|
options: MakeDatabaseItOptions<Database, Provided, LayerError> & {
|
|
18
|
-
readonly layer: Layer.Layer<
|
|
19
|
-
Provided | Effect.Services<Database>,
|
|
20
|
-
LayerError
|
|
21
|
-
>;
|
|
9
|
+
readonly layer: Layer.Layer<Provided | Effect.Services<Database>, LayerError>;
|
|
22
10
|
},
|
|
23
|
-
): DatabaseIt<Database, Provided | Effect.Services<Database
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
): DatabaseIt<Database, Provided | Effect.Services<Database>>;
|
|
12
|
+
export function makeDatabaseIt(options: {
|
|
13
|
+
readonly clock?: EffectClock | undefined;
|
|
14
|
+
readonly database: AnyDatabase;
|
|
15
|
+
readonly layer: Layer.Layer<unknown, unknown>;
|
|
16
|
+
}): unknown {
|
|
26
17
|
const { effectApp } = makeEffectIt({
|
|
27
18
|
around: (effect) => withTestTransaction(options.database, effect),
|
|
28
19
|
clock: options.clock,
|
|
29
20
|
layer: options.layer,
|
|
30
|
-
makeHarness: () =>
|
|
31
|
-
options.database as unknown as Effect.Effect<
|
|
32
|
-
DatabaseService<Database>,
|
|
33
|
-
never,
|
|
34
|
-
Effect.Services<Database>
|
|
35
|
-
>,
|
|
21
|
+
makeHarness: () => options.database,
|
|
36
22
|
});
|
|
37
23
|
|
|
38
24
|
return new Proxy(effectIt, {
|
|
@@ -42,5 +28,5 @@ export const makeDatabaseIt = <
|
|
|
42
28
|
}
|
|
43
29
|
return Reflect.get(target, property, receiver);
|
|
44
30
|
},
|
|
45
|
-
})
|
|
46
|
-
}
|
|
31
|
+
});
|
|
32
|
+
}
|
package/src/testing.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { withTestTransaction } from "./testing/transaction.
|
|
1
|
+
export { withTestTransaction } from "./testing/transaction.ts";
|
|
2
2
|
export type {
|
|
3
3
|
AnyDatabase,
|
|
4
4
|
DatabaseIt,
|
|
@@ -6,5 +6,5 @@ export type {
|
|
|
6
6
|
DatabaseTest,
|
|
7
7
|
DatabaseTester,
|
|
8
8
|
MakeDatabaseItOptions,
|
|
9
|
-
} from "./testing/types.
|
|
10
|
-
export { makeDatabaseIt } from "./testing/vitest.
|
|
9
|
+
} from "./testing/types.ts";
|
|
10
|
+
export { makeDatabaseIt } from "./testing/vitest.ts";
|