@shivaedev/effect-test-sql 0.8.5 → 0.9.1
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 +34 -0
- package/README.md +16 -3
- package/dist/server/postgres.d.ts +9 -2
- package/dist/server/postgres.d.ts.map +1 -1
- package/dist/server/postgres.js +11 -3
- package/dist/server/postgres.js.map +1 -1
- package/package.json +5 -5
- package/src/server/postgres.ts +24 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.1 - 2026-10-25
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Release with updated workspace dependencies.
|
|
8
|
+
|
|
9
|
+
## 0.9.0 - 2026-10-25
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `makePostgresTestLayer` accepts `initialize` instead of `migrations` to run an application's complete production database initializer once against the prepared template. Pass an Effect using the supplied SQL services or a callback receiving the template's redacted URL. Initialization and optional subsequent fixtures finish and release scoped resources before cloning; deployment stories can still select the empty template. Replace a dummy `migrations` loader and initializer in `fixtures` with `initialize: (url) => migrateDatabase(url)`.
|
|
14
|
+
|
|
15
|
+
### Breaking
|
|
16
|
+
|
|
17
|
+
- `PostgresTestOptions` is now a union requiring exactly one of `migrations` and `initialize`. Wrappers that read `options.migrations` must first narrow `options.initialize === undefined`. Replace interfaces extending `PostgresTestOptions` with intersection type aliases. Existing calls supplying migrations retain their behavior.
|
|
18
|
+
|
|
19
|
+
## 0.8.8 - 2026-10-25
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Release with updated workspace dependencies.
|
|
24
|
+
|
|
25
|
+
## 0.8.7 - 2026-10-25
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- Release with updated workspace dependencies.
|
|
30
|
+
|
|
31
|
+
## 0.8.6 - 2026-10-25
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- Release with updated workspace dependencies.
|
|
36
|
+
|
|
3
37
|
## 0.8.5 - 2026-10-25
|
|
4
38
|
|
|
5
39
|
### Changed
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ The next test still sees the original name. Tests that must observe a committed
|
|
|
22
22
|
|
|
23
23
|
### Prepare one fixture
|
|
24
24
|
|
|
25
|
-
`makePostgresTestLayer` creates an empty template and a migrated template through an administrative connection, runs `migratePostgres`
|
|
25
|
+
`makePostgresTestLayer` creates an empty template and a migrated template through an administrative connection, runs either `migratePostgres` or the application's initializer followed by optional fixtures in the migrated template, then closes its preparation connections. It creates a shared test database from the migrated template and provides `SqlClient`, `PgClient`, `Reactivity` and `PostgresTestDatabase`. The templates remain closed and unchanged while tests run. Each isolated database copies the template it asks for; initialization and fixtures do not run again when cloning. Set `prepare: false` for a suite that needs only empty databases: preparation and fixtures are skipped.
|
|
26
26
|
|
|
27
27
|
The Layer's scope owns the template, shared database and their connections. `makeEffectIt` builds the Layer once for its worker fixture. Each test's wrapper owns the transaction or isolated database. Closing a test scope releases its connections and queues its database drop in the background. Closing the Layer waits for all queued drops. To wait earlier, run `PostgresTestDatabase.awaitCleanup` after the isolated scope ends; it waits for drops queued before that Effect starts and reports cleanup failures as SQL defects. The shared database and templates stay available; the administrative database named by `url` remains in place.
|
|
28
28
|
|
|
@@ -32,7 +32,7 @@ Define the tester in test support:
|
|
|
32
32
|
import { expect } from "vitest";
|
|
33
33
|
import { Config, Effect, Redacted } from "effect";
|
|
34
34
|
import { Migrator, SqlClient } from "effect/sql";
|
|
35
|
-
import { makeEffectIt } from "@shivaedev/effect-test/
|
|
35
|
+
import { makeEffectIt } from "@shivaedev/effect-test/makeEffectIt.ts";
|
|
36
36
|
import { makePostgresTestLayer } from "@shivaedev/effect-test-sql/server/postgres.ts";
|
|
37
37
|
import { withTestTransaction } from "@shivaedev/effect-test-sql/server/withTestTransaction.ts";
|
|
38
38
|
|
|
@@ -79,6 +79,19 @@ const layer = makePostgresTestLayer({
|
|
|
79
79
|
});
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
### Run the production initializer
|
|
83
|
+
|
|
84
|
+
Supply `initialize` instead of `migrations` when the application already owns its complete database setup:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
const layer = makePostgresTestLayer({
|
|
88
|
+
url: testDatabaseUrl,
|
|
89
|
+
initialize: (templateUrl) => migrateDatabase(templateUrl),
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Choose exactly one of `migrations` and `initialize`. The initializer is an Effect using the supplied `SqlClient`, `PgClient` and `Reactivity`, or a `PostgresTestLoader` receiving the template's redacted URL. It runs once against the migrated template and completes before fixtures and cloning. Its scoped resources close before cloning, and additional service requirements remain requirements of the Layer. Optional `fixtures` run afterward. Ordinary stories inherit the initialized schema and data; deployment stories can still select the empty template.
|
|
94
|
+
|
|
82
95
|
### Reuse the app's SQL name mapping
|
|
83
96
|
|
|
84
97
|
`PostgresTestOptions` accepts effect-sql's native `transformQueryNames` and `transformResultNames`. Spread the same options returned by `clientOptions` that the app host uses; the test layer carries them into preparation, the shared database, `withIsolatedDatabase` and story clones:
|
|
@@ -226,7 +239,7 @@ Import each name from the module that defines it. The package has no root entry.
|
|
|
226
239
|
|
|
227
240
|
| Module | Exports |
|
|
228
241
|
| --- | --- |
|
|
229
|
-
| `@shivaedev/effect-test-sql/server/postgres.ts` | `makePostgresTestLayer({ url, migrations
|
|
242
|
+
| `@shivaedev/effect-test-sql/server/postgres.ts` | `makePostgresTestLayer({ url, migrations?, initialize?, fixtures?, maxConnections?, prepare?, transformQueryNames?, transformResultNames? })`, `PostgresTestOptions`, `PostgresTestLoader` |
|
|
230
243
|
| `@shivaedev/effect-test-sql/server/withTestTransaction.ts` | `withTestTransaction(effect)` |
|
|
231
244
|
| `@shivaedev/effect-test-sql/server/withIsolatedDatabase.ts` | `withIsolatedDatabase(effect, { template? }?)` |
|
|
232
245
|
| `@shivaedev/effect-test-sql/server/database.ts` | `PostgresTestDatabase`, `PostgresTestDatabaseService`, `PostgresTestServices`, `PostgresTestTemplate` |
|
|
@@ -4,12 +4,19 @@ import type { SqlNameTransforms } from "@shivaedev/effect-sql/clientOptions.ts";
|
|
|
4
4
|
import { type PostgresMigrationOptions } from "@shivaedev/effect-sql/migrations.ts";
|
|
5
5
|
import { PostgresTestDatabase, type PostgresTestServices } from "#database.ts";
|
|
6
6
|
export type PostgresTestLoader<E = never, R = never> = (url: Redacted.Redacted<string>) => Effect.Effect<unknown, E, R | PostgresTestServices | Scope.Scope>;
|
|
7
|
-
|
|
7
|
+
interface PostgresTestCommonOptions<E, TFixtures> extends SqlNameTransforms {
|
|
8
8
|
readonly fixtures?: Effect.Effect<unknown, E, TFixtures | PostgresTestServices | Scope.Scope> | PostgresTestLoader<E, TFixtures>;
|
|
9
9
|
readonly maxConnections?: number;
|
|
10
|
-
readonly migrations: PostgresMigrationOptions<R>;
|
|
11
10
|
readonly prepare?: boolean;
|
|
12
11
|
readonly url: Redacted.Redacted<string>;
|
|
13
12
|
}
|
|
13
|
+
export type PostgresTestOptions<E = never, R = never, TFixtures = never> = PostgresTestCommonOptions<E, TFixtures> & ({
|
|
14
|
+
readonly migrations: PostgresMigrationOptions<R>;
|
|
15
|
+
readonly initialize?: never;
|
|
16
|
+
} | {
|
|
17
|
+
readonly initialize: Effect.Effect<unknown, E, R | PostgresTestServices | Scope.Scope> | PostgresTestLoader<E, R>;
|
|
18
|
+
readonly migrations?: never;
|
|
19
|
+
});
|
|
14
20
|
export declare function makePostgresTestLayer<E = never, R = never, TFixtures = never>(options: PostgresTestOptions<E, R, TFixtures>): Layer.Layer<import("@effect/sql-pg/PgClient").PgClient | PostgresTestDatabase | Reactivity.Reactivity | import("effect/sql/SqlClient").SqlClient, E | import("effect/sql/Migrator").MigrationError | import("effect/sql/SqlError").SqlError, Exclude<Exclude<Exclude<Exclude<R, import("@effect/sql-pg/PgClient").PgClient | Reactivity.Reactivity | import("effect/sql/SqlClient").SqlClient>, Scope.Scope>, Scope.Scope>, Reactivity.Reactivity> | Exclude<Exclude<Exclude<Exclude<TFixtures, import("@effect/sql-pg/PgClient").PgClient | Reactivity.Reactivity | import("effect/sql/SqlClient").SqlClient>, Scope.Scope>, Scope.Scope>, Reactivity.Reactivity>>;
|
|
21
|
+
export {};
|
|
15
22
|
//# sourceMappingURL=postgres.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/server/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC3E,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAmB,KAAK,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAAoC,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAKjH,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,IAAI,CACtD,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,KAC1B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,oBAAoB,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;AAEvE,
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/server/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC3E,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D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AAC,GAAG,oBAAoB,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClH,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;CAC3B,CACH,CAAC;AASH,wBAAgB,qBAAqB,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,SAAS,GAAG,KAAK,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,uoBAmC3H"}
|
package/dist/server/postgres.js
CHANGED
|
@@ -5,6 +5,9 @@ import { PostgresTestDatabase } from "#database.ts";
|
|
|
5
5
|
import { connectionLimitHint } from "#internal/connectionLimitHint.ts";
|
|
6
6
|
import { databaseCleanup } from "#internal/databaseCleanup.ts";
|
|
7
7
|
import { connection, database } from "#internal/databases.ts";
|
|
8
|
+
function runLoader(loader, url) {
|
|
9
|
+
return typeof loader === "function" ? loader(url) : loader;
|
|
10
|
+
}
|
|
8
11
|
export function makePostgresTestLayer(options) {
|
|
9
12
|
return Layer.effectContext(Effect.gen(function* () {
|
|
10
13
|
const maxConnections = options.maxConnections ?? 2;
|
|
@@ -14,10 +17,15 @@ export function makePostgresTestLayer(options) {
|
|
|
14
17
|
if (options.prepare !== false) {
|
|
15
18
|
yield* Effect.scoped(Effect.gen(function* () {
|
|
16
19
|
const services = yield* Layer.build(connection(template.url, maxConnections, options));
|
|
17
|
-
|
|
20
|
+
const initialize = options.initialize;
|
|
21
|
+
if (initialize === undefined) {
|
|
22
|
+
yield* migratePostgres(options.migrations).pipe(Effect.provideContext(services));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
yield* runLoader(initialize, template.url).pipe(Effect.provideContext(services));
|
|
26
|
+
}
|
|
18
27
|
if (options.fixtures !== undefined) {
|
|
19
|
-
|
|
20
|
-
yield* fixtures.pipe(Effect.provideContext(services));
|
|
28
|
+
yield* runLoader(options.fixtures, template.url).pipe(Effect.provideContext(services));
|
|
21
29
|
}
|
|
22
30
|
}));
|
|
23
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/server/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAA6B,MAAM,QAAQ,CAAC;AAC3E,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAiC,MAAM,qCAAqC,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAA+D,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/server/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAA6B,MAAM,QAAQ,CAAC;AAC3E,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAiC,MAAM,qCAAqC,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAA+D,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAsB9D,SAAS,SAAS,CACjB,MAAyG,EACzG,GAA8B;IAE9B,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,qBAAqB,CAA0C,OAA6C;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AAE,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;IACxG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAC7C,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;AACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/effect-test-sql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "PostgreSQL rollback and real-commit test isolation for Effect",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/effect-test-sql#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"README.md"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@shivaedev/effect-sql": "0.
|
|
44
|
+
"@shivaedev/effect-sql": "0.19.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@effect/sql-pg": "4.0.5",
|
|
48
48
|
"@effect/vitest": "4.0.5",
|
|
49
|
-
"@shivaedev/effect-test": "0.
|
|
50
|
-
"@shivaedev/quality": "0.
|
|
51
|
-
"@shivaedev/test-story": "0.
|
|
49
|
+
"@shivaedev/effect-test": "0.8.1",
|
|
50
|
+
"@shivaedev/quality": "0.38.0",
|
|
51
|
+
"@shivaedev/test-story": "0.19.0",
|
|
52
52
|
"@types/node": "24.19.2",
|
|
53
53
|
"effect": "4.0.5",
|
|
54
54
|
"pg-boss": "12.38.0",
|
package/src/server/postgres.ts
CHANGED
|
@@ -11,14 +11,29 @@ export type PostgresTestLoader<E = never, R = never> = (
|
|
|
11
11
|
url: Redacted.Redacted<string>,
|
|
12
12
|
) => Effect.Effect<unknown, E, R | PostgresTestServices | Scope.Scope>;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
interface PostgresTestCommonOptions<E, TFixtures> extends SqlNameTransforms {
|
|
15
15
|
readonly fixtures?: Effect.Effect<unknown, E, TFixtures | PostgresTestServices | Scope.Scope> | PostgresTestLoader<E, TFixtures>;
|
|
16
16
|
readonly maxConnections?: number;
|
|
17
|
-
readonly migrations: PostgresMigrationOptions<R>;
|
|
18
17
|
readonly prepare?: boolean;
|
|
19
18
|
readonly url: Redacted.Redacted<string>;
|
|
20
19
|
}
|
|
21
20
|
|
|
21
|
+
export type PostgresTestOptions<E = never, R = never, TFixtures = never> = PostgresTestCommonOptions<E, TFixtures> &
|
|
22
|
+
(
|
|
23
|
+
| { readonly migrations: PostgresMigrationOptions<R>; readonly initialize?: never }
|
|
24
|
+
| {
|
|
25
|
+
readonly initialize: Effect.Effect<unknown, E, R | PostgresTestServices | Scope.Scope> | PostgresTestLoader<E, R>;
|
|
26
|
+
readonly migrations?: never;
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
function runLoader<E, R>(
|
|
31
|
+
loader: Effect.Effect<unknown, E, R> | ((url: Redacted.Redacted<string>) => Effect.Effect<unknown, E, R>),
|
|
32
|
+
url: Redacted.Redacted<string>,
|
|
33
|
+
) {
|
|
34
|
+
return typeof loader === "function" ? loader(url) : loader;
|
|
35
|
+
}
|
|
36
|
+
|
|
22
37
|
export function makePostgresTestLayer<E = never, R = never, TFixtures = never>(options: PostgresTestOptions<E, R, TFixtures>) {
|
|
23
38
|
return Layer.effectContext(
|
|
24
39
|
Effect.gen(function* () {
|
|
@@ -30,10 +45,14 @@ export function makePostgresTestLayer<E = never, R = never, TFixtures = never>(o
|
|
|
30
45
|
yield* Effect.scoped(
|
|
31
46
|
Effect.gen(function* () {
|
|
32
47
|
const services = yield* Layer.build(connection(template.url, maxConnections, options));
|
|
33
|
-
|
|
48
|
+
const initialize = options.initialize;
|
|
49
|
+
if (initialize === undefined) {
|
|
50
|
+
yield* migratePostgres(options.migrations).pipe(Effect.provideContext(services));
|
|
51
|
+
} else {
|
|
52
|
+
yield* runLoader(initialize, template.url).pipe(Effect.provideContext(services));
|
|
53
|
+
}
|
|
34
54
|
if (options.fixtures !== undefined) {
|
|
35
|
-
|
|
36
|
-
yield* fixtures.pipe(Effect.provideContext(services));
|
|
55
|
+
yield* runLoader(options.fixtures, template.url).pipe(Effect.provideContext(services));
|
|
37
56
|
}
|
|
38
57
|
}),
|
|
39
58
|
);
|