@proteinjs/db 1.26.0 → 1.28.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 +17 -0
- package/dist/generated/index.js +3 -3
- package/dist/generated/index.js.map +1 -1
- package/dist/generated/test/index.js +7 -7
- package/dist/generated/test/index.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/src/Db.d.ts +18 -5
- package/dist/src/Db.d.ts.map +1 -1
- package/dist/src/Db.js +43 -35
- package/dist/src/Db.js.map +1 -1
- package/dist/src/MigrationRunner.d.ts +9 -0
- package/dist/src/MigrationRunner.d.ts.map +1 -1
- package/dist/src/MigrationRunner.js +24 -10
- package/dist/src/MigrationRunner.js.map +1 -1
- package/dist/src/auth/TableAuth.d.ts +7 -1
- package/dist/src/auth/TableAuth.d.ts.map +1 -1
- package/dist/src/auth/TableAuth.js +7 -1
- package/dist/src/auth/TableAuth.js.map +1 -1
- package/dist/src/tables/MigrationTable.d.ts +7 -0
- package/dist/src/tables/MigrationTable.d.ts.map +1 -1
- package/dist/src/tables/MigrationTable.js +10 -0
- package/dist/src/tables/MigrationTable.js.map +1 -1
- package/dist/src/transaction/TransactionContextFactory.d.ts +8 -1
- package/dist/src/transaction/TransactionContextFactory.d.ts.map +1 -1
- package/dist/test/MigrationAuth.test.d.ts +2 -0
- package/dist/test/MigrationAuth.test.d.ts.map +1 -0
- package/dist/test/MigrationAuth.test.js +77 -0
- package/dist/test/MigrationAuth.test.js.map +1 -0
- package/dist/test/MigrationRunnerContainment.test.d.ts +2 -0
- package/dist/test/MigrationRunnerContainment.test.d.ts.map +1 -0
- package/dist/test/MigrationRunnerContainment.test.js +144 -0
- package/dist/test/MigrationRunnerContainment.test.js.map +1 -0
- package/dist/test/TableServiceAuth.test.js +67 -0
- package/dist/test/TableServiceAuth.test.js.map +1 -1
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +1 -0
- package/dist/test/index.js.map +1 -1
- package/dist/test/util/DbTestEnvironment.d.ts.map +1 -1
- package/dist/test/util/DbTestEnvironment.js +5 -0
- package/dist/test/util/DbTestEnvironment.js.map +1 -1
- package/dist/test/util/testUser.d.ts +5 -0
- package/dist/test/util/testUser.d.ts.map +1 -0
- package/dist/test/util/testUser.js +17 -0
- package/dist/test/util/testUser.js.map +1 -0
- package/generated/index.ts +3 -3
- package/generated/test/index.ts +7 -7
- package/index.ts +2 -0
- package/package.json +4 -4
- package/src/Db.ts +47 -28
- package/src/MigrationRunner.ts +20 -5
- package/src/auth/TableAuth.ts +13 -2
- package/src/tables/MigrationTable.ts +10 -0
- package/src/transaction/TransactionContextFactory.ts +8 -1
- package/test/MigrationAuth.test.ts +87 -0
- package/test/MigrationRunnerContainment.test.ts +104 -0
- package/test/TableServiceAuth.test.ts +90 -1
- package/test/index.ts +2 -0
- package/test/util/DbTestEnvironment.ts +5 -0
- package/test/util/testUser.ts +27 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Table, DbDriver } from '@proteinjs/db';
|
|
2
|
+
import { registerTestUser, clearTestUser } from './testUser';
|
|
2
3
|
import { cascadeDeleteTestTables } from './tables/cascadeDeleteTestTables';
|
|
3
4
|
import { columnTypesTestTables } from './tables/columnTypesTestTables';
|
|
4
5
|
import { crudTestTables } from './tables/crudTestTables';
|
|
@@ -25,6 +26,9 @@ export class DbTestEnvironment {
|
|
|
25
26
|
) {}
|
|
26
27
|
|
|
27
28
|
async beforeAll() {
|
|
29
|
+
// UserAuth is fail-closed; the suites run non-system Db paths, so they carry an explicit
|
|
30
|
+
// identity instead of leaning on an open gate.
|
|
31
|
+
registerTestUser();
|
|
28
32
|
if (this.dbDriver.start) {
|
|
29
33
|
await this.dbDriver.start();
|
|
30
34
|
}
|
|
@@ -35,6 +39,7 @@ export class DbTestEnvironment {
|
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
async afterAll() {
|
|
42
|
+
clearTestUser();
|
|
38
43
|
for (const table of TABLES.reverse()) {
|
|
39
44
|
await this.dropTestTable(table);
|
|
40
45
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { UserAuth } from '@proteinjs/user-auth';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Explicit test identity for suites that exercise non-system `Db` paths.
|
|
5
|
+
*
|
|
6
|
+
* `UserAuth` is FAIL-CLOSED: with no registered `AuthenticatedUserRepo` every table gate denies.
|
|
7
|
+
* Test harnesses that run `Db` outside a server (driver suites, the reusable CRUD suites) must
|
|
8
|
+
* therefore say who they are instead of leaning on an open gate. Register in `beforeAll`, clear
|
|
9
|
+
* in `afterAll`; `DbTestEnvironment` does both for the reusable suites.
|
|
10
|
+
*
|
|
11
|
+
* The static is reached via a runtime cast per the test-harness convention — widening `UserAuth`
|
|
12
|
+
* with a setter only tests need would be the wrong trade.
|
|
13
|
+
*
|
|
14
|
+
* @internal This module is intended to be used only in tests. Do not use it in production code.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
type UserAuthInternals = { userRepo?: { getUser: () => { email: string; roles: string[] } } };
|
|
18
|
+
|
|
19
|
+
/** Register an explicit identity on `UserAuth` (admin by default — the reusable suites test CRUD, not table doors). */
|
|
20
|
+
export const registerTestUser = (roles: string[] = ['admin'], email = 'db-test-user@test.local') => {
|
|
21
|
+
(UserAuth as unknown as UserAuthInternals).userRepo = { getUser: () => ({ email, roles }) };
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Remove the registered test identity, restoring the deny-everything unregistered state. */
|
|
25
|
+
export const clearTestUser = () => {
|
|
26
|
+
(UserAuth as unknown as UserAuthInternals).userRepo = undefined;
|
|
27
|
+
};
|