@proteinjs/db-driver-spanner 1.14.1 → 1.14.3

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/generated/index.js +1 -1
  3. package/dist/generated/index.js.map +1 -1
  4. package/dist/generated/test/index.js +1 -1
  5. package/dist/generated/test/index.js.map +1 -1
  6. package/dist/src/SpannerDriver.d.ts.map +1 -1
  7. package/dist/src/SpannerDriver.js +6 -25
  8. package/dist/src/SpannerDriver.js.map +1 -1
  9. package/dist/test/MigrationRunner.test.d.ts +2 -0
  10. package/dist/test/MigrationRunner.test.d.ts.map +1 -0
  11. package/dist/test/MigrationRunner.test.js +172 -0
  12. package/dist/test/MigrationRunner.test.js.map +1 -0
  13. package/dist/test/ServiceUpdateVerbs.test.d.ts.map +1 -1
  14. package/dist/test/ServiceUpdateVerbs.test.js +14 -6
  15. package/dist/test/ServiceUpdateVerbs.test.js.map +1 -1
  16. package/dist/test/SessionPoolExhaustion.test.d.ts.map +1 -1
  17. package/dist/test/SessionPoolExhaustion.test.js +15 -3
  18. package/dist/test/SessionPoolExhaustion.test.js.map +1 -1
  19. package/dist/test/SessionRecordTableQuery.test.d.ts.map +1 -1
  20. package/dist/test/SessionRecordTableQuery.test.js +13 -6
  21. package/dist/test/SessionRecordTableQuery.test.js.map +1 -1
  22. package/dist/test/TransactionSafety.test.d.ts.map +1 -1
  23. package/dist/test/TransactionSafety.test.js +15 -3
  24. package/dist/test/TransactionSafety.test.js.map +1 -1
  25. package/dist/test/util/SpannerEmulatorProvisioner.d.ts.map +1 -1
  26. package/dist/test/util/SpannerEmulatorProvisioner.js +17 -6
  27. package/dist/test/util/SpannerEmulatorProvisioner.js.map +1 -1
  28. package/generated/index.ts +9 -6
  29. package/generated/test/index.ts +11 -8
  30. package/package.json +6 -7
  31. package/src/SpannerDriver.ts +9 -23
  32. package/test/MigrationRunner.test.ts +88 -0
  33. package/test/ServiceUpdateVerbs.test.ts +6 -0
  34. package/test/SessionPoolExhaustion.test.ts +18 -3
  35. package/test/SessionRecordTableQuery.test.ts +5 -0
  36. package/test/TransactionSafety.test.ts +18 -3
  37. package/test/util/SpannerEmulatorProvisioner.ts +10 -1
  38. package/LICENSE +0 -21
@@ -1,7 +1,9 @@
1
1
  import { Database, SessionPool } from '@google-cloud/spanner';
2
- import { Db, Record, StringColumn, Table, withRecordColumns } from '@proteinjs/db';
2
+ import { Db, Record, StringColumn, Table, tableByName, withRecordColumns } from '@proteinjs/db';
3
3
  import { TransactionContext } from '@proteinjs/db-transaction-context';
4
4
  import { SpannerDriver } from '@proteinjs/db-driver-spanner';
5
+ import { registerTestUser, clearTestUser } from '@proteinjs/db/test';
6
+ import { SourceRepository } from '@proteinjs/reflection';
5
7
  import { getDropTestTable } from './util/getDropTestTable';
6
8
  import { SpannerEmulatorProvisioner } from './util/SpannerEmulatorProvisioner';
7
9
  import '../generated/test/index';
@@ -20,8 +22,9 @@ class WedgeEmployeeTestTable extends Table<WedgeEmployee> {
20
22
  }
21
23
 
22
24
  const employeeTable: Table<WedgeEmployee> = new WedgeEmployeeTestTable();
23
- // Local table — not in any reflection source graph, so thread getTable explicitly.
24
- const getTable = () => employeeTable;
25
+ // Local table — not in any reflection source graph, so thread getTable explicitly; other
26
+ // lookups (e.g. the delete path's reverse-cascade scan over graph tables) resolve normally.
27
+ const getTable = (tableName: string) => (tableName === employeeTable.name ? employeeTable : tableByName(tableName));
25
28
  const spannerConfig = {
26
29
  projectId: 'proteinjs-test',
27
30
  instanceName: 'proteinjs-test',
@@ -58,6 +61,14 @@ describe('Session pool at max=1 (wedge designed out; real exhaustion documented)
58
61
  const txnDb = new Db(spannerDriver, getTable, new TransactionContext());
59
62
 
60
63
  beforeAll(async () => {
64
+ // Fail-closed auth needs an explicit identity (the suite predates the flip — n3xa4 side).
65
+ registerTestUser();
66
+ // HERMETIC single-table world: the delete path's reverse-cascade scan walks getTables();
67
+ // scoping the registry to the local table keeps this suite from querying other suites'
68
+ // graph tables (which don't exist in an isolated run). Object cache wins over the graph.
69
+ (SourceRepository.get() as unknown as { objectCache: { [key: string]: unknown[] } }).objectCache[
70
+ '@proteinjs/db/Table'
71
+ ] = [employeeTable];
61
72
  await SpannerEmulatorProvisioner.ensureProvisioned(spannerConfig);
62
73
  await spannerDriver.createDbIfNotExists();
63
74
  // Setup issues overlapping schema-metadata queries; with fail: true the second acquisition
@@ -73,6 +84,10 @@ describe('Session pool at max=1 (wedge designed out; real exhaustion documented)
73
84
  getSessionPool().options.fail = false; // teardown queries queue like setup's
74
85
  await dropTable(employeeTable);
75
86
  await SpannerEmulatorProvisioner.release();
87
+ delete (SourceRepository.get() as unknown as { objectCache: { [key: string]: unknown[] } }).objectCache[
88
+ '@proteinjs/db/Table'
89
+ ];
90
+ clearTestUser();
76
91
  }, 60000);
77
92
 
78
93
  test('SpannerConfig.sessionPoolOptions reach the session pool', () => {
@@ -1,6 +1,7 @@
1
1
  import moment from 'moment';
2
2
  import { SpannerDriver } from '@proteinjs/db-driver-spanner';
3
3
  import { Db, DateColumn, QueryBuilderFactory, Record, StringColumn, Table, withRecordColumns } from '@proteinjs/db';
4
+ import { registerTestUser, clearTestUser } from '@proteinjs/db/test';
4
5
  import { TransactionContext } from '@proteinjs/db-transaction-context';
5
6
  import { getDropTestTable } from './util/getDropTestTable';
6
7
  import { SpannerEmulatorProvisioner } from './util/SpannerEmulatorProvisioner';
@@ -77,6 +78,9 @@ describe('Session-shaped record table query (the admin Sessions table path)', ()
77
78
  const db = new Db(spannerDriver, getTable, new TransactionContext());
78
79
 
79
80
  beforeAll(async () => {
81
+ // The admin Sessions table reads as an admin; UserAuth is fail-closed, so the suite carries
82
+ // that identity explicitly (the session table defaults to the admin door — no auth block).
83
+ registerTestUser();
80
84
  await SpannerEmulatorProvisioner.ensureProvisioned({
81
85
  projectId: 'proteinjs-test',
82
86
  instanceName: 'proteinjs-test',
@@ -87,6 +91,7 @@ describe('Session-shaped record table query (the admin Sessions table path)', ()
87
91
  }, 60000);
88
92
 
89
93
  afterAll(async () => {
94
+ clearTestUser();
90
95
  await dropTable(table);
91
96
  await SpannerEmulatorProvisioner.release();
92
97
  }, 30000);
@@ -1,6 +1,8 @@
1
- import { Db, QueryBuilderFactory, Record, StringColumn, Table, withRecordColumns } from '@proteinjs/db';
1
+ import { Db, QueryBuilderFactory, Record, StringColumn, Table, tableByName, withRecordColumns } from '@proteinjs/db';
2
2
  import { TransactionContext } from '@proteinjs/db-transaction-context';
3
3
  import { SpannerDriver } from '@proteinjs/db-driver-spanner';
4
+ import { registerTestUser, clearTestUser } from '@proteinjs/db/test';
5
+ import { SourceRepository } from '@proteinjs/reflection';
4
6
  import { getDropTestTable } from './util/getDropTestTable';
5
7
  import { SpannerEmulatorProvisioner } from './util/SpannerEmulatorProvisioner';
6
8
  import '../generated/test/index';
@@ -19,8 +21,9 @@ class SafetyEmployeeTestTable extends Table<SafetyEmployee> {
19
21
  }
20
22
 
21
23
  const employeeTable: Table<SafetyEmployee> = new SafetyEmployeeTestTable();
22
- // Local table — not in any reflection source graph, so thread getTable explicitly.
23
- const getTable = () => employeeTable;
24
+ // Local table — not in any reflection source graph, so thread getTable explicitly; other
25
+ // lookups (e.g. the delete path's reverse-cascade scan over graph tables) resolve normally.
26
+ const getTable = (tableName: string) => (tableName === employeeTable.name ? employeeTable : tableByName(tableName));
24
27
  const spannerConfig = {
25
28
  projectId: 'proteinjs-test',
26
29
  instanceName: 'proteinjs-test',
@@ -45,6 +48,14 @@ describe('Transaction safety (stateless contract)', () => {
45
48
  const txnDb = new Db(spannerDriver, getTable, new TransactionContext());
46
49
 
47
50
  beforeAll(async () => {
51
+ // Fail-closed auth needs an explicit identity (the suite predates the flip — n3xa4 side).
52
+ registerTestUser();
53
+ // HERMETIC single-table world: the delete path's reverse-cascade scan walks getTables();
54
+ // scoping the registry to the local table keeps this suite from querying other suites'
55
+ // graph tables (which don't exist in an isolated run). Object cache wins over the graph.
56
+ (SourceRepository.get() as unknown as { objectCache: { [key: string]: unknown[] } }).objectCache[
57
+ '@proteinjs/db/Table'
58
+ ] = [employeeTable];
48
59
  await SpannerEmulatorProvisioner.ensureProvisioned(spannerConfig);
49
60
  await spannerDriver.createDbIfNotExists();
50
61
  await spannerDriver.getTableManager().loadTable(employeeTable);
@@ -53,6 +64,10 @@ describe('Transaction safety (stateless contract)', () => {
53
64
  afterAll(async () => {
54
65
  await dropTable(employeeTable);
55
66
  await SpannerEmulatorProvisioner.release();
67
+ delete (SourceRepository.get() as unknown as { objectCache: { [key: string]: unknown[] } }).objectCache[
68
+ '@proteinjs/db/Table'
69
+ ];
70
+ clearTestUser();
56
71
  }, 60000);
57
72
 
58
73
  test('a PRE-CONSTRUCTED Db rides the ambient transaction: its reads see the txn write, and the txn commits', async () => {
@@ -44,8 +44,17 @@ export class SpannerEmulatorProvisioner {
44
44
  SpannerEmulatorProvisioner.swallowAlreadyExists(error);
45
45
  }
46
46
  try {
47
- const [, operation] = await instance.createDatabase(config.databaseName);
47
+ const [database, operation] = await instance.createDatabase(config.databaseName);
48
48
  await operation.promise();
49
+ // createDatabase constructs a Database handle whose session pool OPENS in its constructor
50
+ // (database.js: pool_.open()). Ignored, it becomes an orphan: its fill/keepalive machinery
51
+ // outlives release(), and once the admin client closes, every subsequent pool op emits an
52
+ // unlistened 'error' on this handle — crashing whichever jest suite happens to be active
53
+ // (only fresh-emulator runs hit this; ALREADY_EXISTS constructs no handle). Own it through
54
+ // its death: the listener covers session creates that settle after close, and the close
55
+ // runs while the admin client can still delete the pool's sessions cleanly.
56
+ database.on('error', () => undefined);
57
+ await database.close().catch(() => undefined);
49
58
  } catch (error) {
50
59
  SpannerEmulatorProvisioner.swallowAlreadyExists(error);
51
60
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Brent Bahry
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.