@zeroxsolutions/db 7.0.0 → 9.0.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/README.md +11 -4
- package/dist/testing/disposable-postgres.d.ts +4 -7
- package/dist/testing/disposable-postgres.d.ts.map +1 -1
- package/dist/testing/disposable-postgres.js +4 -7
- package/dist/testing/postgres-image.d.ts +8 -0
- package/dist/testing/postgres-image.d.ts.map +1 -0
- package/dist/testing/postgres-image.js +7 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ declares `"."`, but no `src/index.ts` exists for the build to emit it from, so
|
|
|
38
38
|
| `@zeroxsolutions/db/postgres` | PostgreSQL entity, repository, view repository, unit of work, outbox, and types |
|
|
39
39
|
| `@zeroxsolutions/db/d1` | Cloudflare D1 (SQLite) entity, repository, unit of work, outbox, and types |
|
|
40
40
|
| `@zeroxsolutions/db/utils` | Filter and order builders, `TableQuery` and the relational-read builder, the field-whitelist guard, the filter-value schema + operator enum, omit masks, pagination constants |
|
|
41
|
-
| `@zeroxsolutions/db/testing` | A throwaway Postgres container carrying your schema, the
|
|
41
|
+
| `@zeroxsolutions/db/testing` | A throwaway Postgres container carrying your schema, on the engine you name, plus the container timeout and a fake uuid v7 |
|
|
42
42
|
|
|
43
43
|
---
|
|
44
44
|
|
|
@@ -458,10 +458,14 @@ import {
|
|
|
458
458
|
} from '@zeroxsolutions/db/testing';
|
|
459
459
|
import * as schema from './lib/db/index.js';
|
|
460
460
|
|
|
461
|
+
// The engine THIS package deploys, written down once here. It is asked for rather than defaulted:
|
|
462
|
+
// only you know which major your deployment runs, and a container started on another one passes.
|
|
463
|
+
const POSTGRES_IMAGE = 'postgres:17-alpine';
|
|
464
|
+
|
|
461
465
|
let database: DisposablePostgres<typeof schema>;
|
|
462
466
|
|
|
463
467
|
beforeAll(async () => {
|
|
464
|
-
database = await startDisposablePostgres(schema);
|
|
468
|
+
database = await startDisposablePostgres(schema, POSTGRES_IMAGE);
|
|
465
469
|
}, CONTAINER_TIMEOUT_MS);
|
|
466
470
|
|
|
467
471
|
afterAll(async () => {
|
|
@@ -472,10 +476,13 @@ afterAll(async () => {
|
|
|
472
476
|
A suite that cannot use the client - a worker e2e reaching its database through a Hyperdrive
|
|
473
477
|
binding - takes `database.connectionString` and hands that to its test pool instead.
|
|
474
478
|
|
|
479
|
+
This package names no engine for you, and exports no constant standing in as that argument. Which
|
|
480
|
+
major you run is your deployment's own fact, so `image` takes no default: a forgotten argument is a
|
|
481
|
+
typecheck failure rather than a suite that quietly passed on a major you do not deploy.
|
|
482
|
+
|
|
475
483
|
| Export | What it is |
|
|
476
484
|
| ------ | ---------- |
|
|
477
|
-
| `startDisposablePostgres(schema, image
|
|
478
|
-
| `POSTGRES_IMAGE` | `postgres:18-alpine`, the default `image` - the one place the engine version is written down, so a container started by hand takes it from here too |
|
|
485
|
+
| `startDisposablePostgres(schema, image)` | Starts the container, creates `schema` in it, and returns a Drizzle client typed against it, the `connectionString` it dialled, and the `stop()` that tears it down |
|
|
479
486
|
| `CONTAINER_TIMEOUT_MS` | 180s, for the hook that starts a container: an image pull on a cold machine outruns vitest's 5s default |
|
|
480
487
|
| `fakeUuidV7` | Random bits in a v7 layout: it passes a v7 check, and is not time-ordered like a minted id |
|
|
481
488
|
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { type PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
2
|
-
/**
|
|
3
|
-
* The Postgres engine every test starting a container runs against - the one place the version is written down.
|
|
4
|
-
* The major tracks the deployed engine, which nothing in this workspace pins: iac carries only a connection string.
|
|
5
|
-
*/
|
|
6
|
-
export declare const POSTGRES_IMAGE = "postgres:18-alpine";
|
|
7
2
|
/** Pulling the image on a cold machine costs far more than vitest's 5s default timeout. */
|
|
8
3
|
export declare const CONTAINER_TIMEOUT_MS = 180000;
|
|
9
4
|
/** A throwaway Postgres carrying one schema, and the handle that tears its container down. */
|
|
@@ -20,7 +15,9 @@ export interface DisposablePostgres<TSchema extends Record<string, unknown>> {
|
|
|
20
15
|
* Starts a Postgres container, creates `schema` inside it, and returns a client typed against it
|
|
21
16
|
* plus the address it dialled.
|
|
22
17
|
* @param schema - the drizzle tables and relations to create; the module namespace of a schema barrel.
|
|
23
|
-
* @param image - the Postgres image to run
|
|
18
|
+
* @param image - the Postgres image to run. It carries no default because only the caller knows which
|
|
19
|
+
* engine its own deployment runs: a default would let a forgotten argument run a whole suite against
|
|
20
|
+
* another major, passing, and reading afterwards like the engine that caller chose.
|
|
24
21
|
*/
|
|
25
|
-
export declare function startDisposablePostgres<TSchema extends Record<string, unknown>>(schema: TSchema, image
|
|
22
|
+
export declare function startDisposablePostgres<TSchema extends Record<string, unknown>>(schema: TSchema, image: string): Promise<DisposablePostgres<TSchema>>;
|
|
26
23
|
//# sourceMappingURL=disposable-postgres.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disposable-postgres.d.ts","sourceRoot":"","sources":["../../src/testing/disposable-postgres.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG3E
|
|
1
|
+
{"version":3,"file":"disposable-postgres.d.ts","sourceRoot":"","sources":["../../src/testing/disposable-postgres.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG3E,2FAA2F;AAC3F,eAAO,MAAM,oBAAoB,SAAU,CAAC;AAE5C,8FAA8F;AAC9F,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACzE,EAAE,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAChC;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnF,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAiBtC"}
|
|
@@ -2,20 +2,17 @@ import { PostgreSqlContainer } from '@testcontainers/postgresql';
|
|
|
2
2
|
import { generateDrizzleJson, generateMigration } from 'drizzle-kit/api';
|
|
3
3
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
4
4
|
import postgres from 'postgres';
|
|
5
|
-
/**
|
|
6
|
-
* The Postgres engine every test starting a container runs against - the one place the version is written down.
|
|
7
|
-
* The major tracks the deployed engine, which nothing in this workspace pins: iac carries only a connection string.
|
|
8
|
-
*/
|
|
9
|
-
export const POSTGRES_IMAGE = 'postgres:18-alpine';
|
|
10
5
|
/** Pulling the image on a cold machine costs far more than vitest's 5s default timeout. */
|
|
11
6
|
export const CONTAINER_TIMEOUT_MS = 180_000;
|
|
12
7
|
/**
|
|
13
8
|
* Starts a Postgres container, creates `schema` inside it, and returns a client typed against it
|
|
14
9
|
* plus the address it dialled.
|
|
15
10
|
* @param schema - the drizzle tables and relations to create; the module namespace of a schema barrel.
|
|
16
|
-
* @param image - the Postgres image to run
|
|
11
|
+
* @param image - the Postgres image to run. It carries no default because only the caller knows which
|
|
12
|
+
* engine its own deployment runs: a default would let a forgotten argument run a whole suite against
|
|
13
|
+
* another major, passing, and reading afterwards like the engine that caller chose.
|
|
17
14
|
*/
|
|
18
|
-
export async function startDisposablePostgres(schema, image
|
|
15
|
+
export async function startDisposablePostgres(schema, image) {
|
|
19
16
|
const container = await new PostgreSqlContainer(image).start();
|
|
20
17
|
const connectionString = container.getConnectionUri();
|
|
21
18
|
const client = postgres(connectionString);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Postgres engine this package's own specs run on, named once for all of them.
|
|
3
|
+
* Deliberately outside `index.ts`, so no consumer can import it: which engine a context runs is that
|
|
4
|
+
* context's own fact, and a constant a consumer could pass would carry this package's answer under
|
|
5
|
+
* that consumer's name, exactly as a default parameter would.
|
|
6
|
+
*/
|
|
7
|
+
export declare const POSTGRES_IMAGE = "postgres:18-alpine";
|
|
8
|
+
//# sourceMappingURL=postgres-image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-image.d.ts","sourceRoot":"","sources":["../../src/testing/postgres-image.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Postgres engine this package's own specs run on, named once for all of them.
|
|
3
|
+
* Deliberately outside `index.ts`, so no consumer can import it: which engine a context runs is that
|
|
4
|
+
* context's own fact, and a constant a consumer could pass would carry this package's answer under
|
|
5
|
+
* that consumer's name, exactly as a default parameter would.
|
|
6
|
+
*/
|
|
7
|
+
export const POSTGRES_IMAGE = 'postgres:18-alpine';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeroxsolutions/db",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Generic Drizzle toolkit - the id column and audit timestamps a table takes, a base repository, the unit-of-work and transactional outbox impls, and the filter/sort/pagination query helpers, for PostgreSQL (postgres-js) and Cloudflare D1; ships no domain schema. Shared across ZeroXSolutions services.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"tslib": "^2.3.0",
|
|
39
39
|
"uuid": "^14.0.1",
|
|
40
|
-
"@zeroxsolutions/
|
|
41
|
-
"@zeroxsolutions/
|
|
40
|
+
"@zeroxsolutions/cosmic": "0.3.4",
|
|
41
|
+
"@zeroxsolutions/query": "0.5.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@testcontainers/postgresql": "^12.1.0",
|