@xemahq/biome-database-nest 1.0.1 → 1.1.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 +20 -0
- package/dist/testing/index.d.ts +12 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +36 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -55,6 +55,26 @@ Mount it beside `XemaServiceModule.forBiome(...)`, which publishes the connectio
|
|
|
55
55
|
|
|
56
56
|
Every Postgres session must run in UTC. The package verifies this and refuses to start otherwise; it never sets the zone.
|
|
57
57
|
|
|
58
|
+
## Testing
|
|
59
|
+
|
|
60
|
+
`@xemahq/pg-test-harness` (0.5 and later) provisions a scratch database but does not know how to migrate it. `createTestMigrator` from the `/testing` subpath returns the `migrate` callback it needs: the same migration phase a service runs at boot (`runBiomeMigrations`). It applies the service's Prisma migrations from `<rootDir>/prisma`, then the operator-migration ledger and the SDK-owned migrations you list, and verifies every owned table's shape. Running it again on the same schema changes nothing.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
// tests/global-setup.ts
|
|
64
|
+
import { createTestMigrator } from '@xemahq/biome-database-nest/testing';
|
|
65
|
+
import { provisionTestDatabase } from '@xemahq/pg-test-harness';
|
|
66
|
+
|
|
67
|
+
export default async function globalSetup(): Promise<void> {
|
|
68
|
+
await provisionTestDatabase({
|
|
69
|
+
serviceName: 'example',
|
|
70
|
+
rootDir: process.cwd(),
|
|
71
|
+
migrate: createTestMigrator({ sdkOwnedMigrations: [/* each SDK's migration set */] }),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`createTestMigrator(options?)` takes `sdkOwnedMigrations?: readonly SdkOwnedMigrationSet[]` and returns `(target: { serviceName, rootDir, url, schema }) => Promise<void>`. It reads no environment variables.
|
|
77
|
+
|
|
58
78
|
## Peer requirements
|
|
59
79
|
|
|
60
80
|
NestJS 10 or 11, Prisma 7 (`@prisma/client`, `@prisma/adapter-pg`), `@xemahq/identity-client`, `@xemahq/contracts`, `@xemahq/service-registry-nest`, `@xemahq/platform-common`.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SdkOwnedMigrationSet } from '../lib/sdk-owned-migration-set';
|
|
2
|
+
export interface TestMigrationTarget {
|
|
3
|
+
readonly serviceName: string;
|
|
4
|
+
readonly rootDir: string;
|
|
5
|
+
readonly url: string;
|
|
6
|
+
readonly schema: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CreateTestMigratorOptions {
|
|
9
|
+
readonly sdkOwnedMigrations?: readonly SdkOwnedMigrationSet[];
|
|
10
|
+
}
|
|
11
|
+
export declare function createTestMigrator(options?: CreateTestMigratorOptions): (target: TestMigrationTarget) => Promise<void>;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAM3E,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,yBAAyB;IAExC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAC;CAC/D;AAWD,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,CAAC,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CA6BhD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTestMigrator = createTestMigrator;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const biome_migrations_1 = require("../lib/biome-migrations");
|
|
7
|
+
const operator_migration_1 = require("../lib/operator-migration");
|
|
8
|
+
const SQL_IDENTIFIER = /^[a-z_][a-z0-9_]*$/iu;
|
|
9
|
+
function createTestMigrator(options = {}) {
|
|
10
|
+
return async (target) => {
|
|
11
|
+
const schemaPath = (0, node_path_1.join)(target.rootDir, 'prisma', 'schema.prisma');
|
|
12
|
+
if (!(0, node_fs_1.existsSync)(schemaPath)) {
|
|
13
|
+
throw new Error(`${target.serviceName}: no Prisma schema at ${schemaPath}. Pass the service root as \`rootDir\` to provisionTestDatabase.`);
|
|
14
|
+
}
|
|
15
|
+
if (!SQL_IDENTIFIER.test(target.schema)) {
|
|
16
|
+
throw new Error(`${target.serviceName}: refusing scratch schema ${JSON.stringify(target.schema)}; it must match ${SQL_IDENTIFIER.source} before it is interpolated into CREATE SCHEMA.`);
|
|
17
|
+
}
|
|
18
|
+
const database = await (0, operator_migration_1.openOperatorMigrationClient)({
|
|
19
|
+
connectionString: target.url,
|
|
20
|
+
});
|
|
21
|
+
try {
|
|
22
|
+
await database.query(`CREATE SCHEMA IF NOT EXISTS "${target.schema}"`);
|
|
23
|
+
await (0, biome_migrations_1.runBiomeMigrations)({
|
|
24
|
+
database,
|
|
25
|
+
workspaceDir: target.rootDir,
|
|
26
|
+
connectionUrl: target.url,
|
|
27
|
+
label: target.serviceName,
|
|
28
|
+
sdkOwnedMigrations: options.sdkOwnedMigrations ?? [],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
await database.end();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.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QACvB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xemahq/biome-database-nest",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Explicit database migration ownership, least-privilege runtime verification, and schema-qualified Prisma wiring for Xema biome services.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Neuralchowder Inc. <developer@xema.dev> (https://xema.dev)",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"prisma": "7.8.0",
|
|
40
40
|
"ts-jest": "^29.4.9",
|
|
41
41
|
"typescript": "5.9.3",
|
|
42
|
-
"@xemahq/
|
|
42
|
+
"@xemahq/eslint-config": "0.14.0",
|
|
43
43
|
"@xemahq/xema-decorators": "1.0.1",
|
|
44
|
-
"@xemahq/
|
|
44
|
+
"@xemahq/service-registry-nest": "1.1.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@nestjs/common": "^10 || ^11",
|
|
@@ -64,6 +64,11 @@
|
|
|
64
64
|
"xema-source": "./src/index.ts",
|
|
65
65
|
"default": "./dist/index.js"
|
|
66
66
|
},
|
|
67
|
+
"./testing": {
|
|
68
|
+
"types": "./dist/testing/index.d.ts",
|
|
69
|
+
"xema-source": "./src/testing/index.ts",
|
|
70
|
+
"default": "./dist/testing/index.js"
|
|
71
|
+
},
|
|
67
72
|
"./dist/lib/*": {
|
|
68
73
|
"types": "./dist/lib/*.d.ts",
|
|
69
74
|
"default": "./dist/lib/*.js"
|
|
@@ -78,6 +83,6 @@
|
|
|
78
83
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
79
84
|
},
|
|
80
85
|
"xemaRelease": {
|
|
81
|
-
"sourceDigest": "sha256:
|
|
86
|
+
"sourceDigest": "sha256:6a5dd5acb427f3601ffafd9f7f634024b4504d3968dd6508b0b4794998130f71"
|
|
82
87
|
}
|
|
83
88
|
}
|