Skip to content

Commit d8eb058

Browse files
committed
mysql.disconnect: consolidate into */mysql.js classes
1 parent 030153f commit d8eb058

26 files changed

Lines changed: 73 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ jobs:
9191

9292
test-docker:
9393
runs-on: ubuntu-latest
94+
permissions:
95+
contents: read
9496
steps:
9597
- uses: actions/checkout@v6
9698
- name: Generate .env

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
66

77
### Unreleased
88

9+
- add: TOML stores for group, nameserver, permission, session
10+
911
### [3.0.0-alpha.11] - 2026-04-07
1012

1113
- decorate user & group with permissions

lib/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Config {
1818
const str = await fs.readFile(`./conf.d/${name}.toml`, 'utf8')
1919
const cfg = parse(str)
2020
applyEnvOverrides(name, cfg)
21-
if (this.debug) console.debug(cfg)
21+
// if (this.debug) console.debug(cfg)
2222

2323
if (name === 'http') {
2424
const tls = await loadPEM('./conf.d')
@@ -37,7 +37,7 @@ class Config {
3737
const str = fsSync.readFileSync(`./conf.d/${name}.toml`, 'utf8')
3838
const cfg = parse(str)
3939
applyEnvOverrides(name, cfg)
40-
if (this.debug) console.debug(cfg)
40+
// if (this.debug) console.debug(cfg)
4141

4242
if (name === 'http') {
4343
const tls = loadPEMSync('./conf.d')

lib/group/store/base.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class GroupBase {
1616
this.debug = args?.debug ?? false
1717
}
1818

19+
disconnect() {
20+
// noop, for repos that need to clean up resources
21+
}
22+
1923
// -------------------------------------------------------------------------
2024
// Repo contract – subclasses must implement these
2125
// -------------------------------------------------------------------------

lib/group/store/mysql.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ class Group extends GroupBase {
163163
const r = await Mysql.execute(...Mysql.delete(`nt_group`, { nt_group_id: args.id }))
164164
return r.affectedRows === 1
165165
}
166+
167+
disconnect() {
168+
return this.mysql?.disconnect()
169+
}
166170
}
167171

168172
export default Group

lib/group/test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Group from '../index.js'
66
import testCase from '../test/group.json' with { type: 'json' }
77

88
after(async () => {
9-
Group.mysql.disconnect()
9+
Group.disconnect()
1010
})
1111

1212
describe('group', function () {

lib/mysql.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ class Mysql {
1212
}
1313

1414
async connect() {
15-
// if (this.dbh && this.dbh?.connection?.connectionId) return this.dbh;
16-
1715
const cfg = await Config.get('mysql')
18-
if (_debug) console.log(cfg)
19-
16+
// if (_debug) console.log(cfg)
2017
this.dbh = await mysql.createConnection(cfg)
2118
if (_debug) console.log(`MySQL connection id ${this.dbh.connection.connectionId}`)
2219
return this.dbh

lib/nameserver/store/base.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class NameserverBase {
3939
async destroy(_args) {
4040
throw new Error('destroy() not implemented by this repo')
4141
}
42+
43+
disconnect() {
44+
// noop by default
45+
}
4246
}
4347

4448
export default NameserverBase

lib/nameserver/store/mysql.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class Nameserver extends NameserverBase {
9494
const r = await Mysql.execute(...Mysql.delete(`nt_nameserver`, { nt_nameserver_id: args.id }))
9595
return r.affectedRows === 1
9696
}
97+
98+
disconnect() {
99+
return this.mysql?.disconnect()
100+
}
97101
}
98102

99103
export default Nameserver

lib/nameserver/test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ before(async () => {
1212

1313
after(async () => {
1414
await Nameserver.destroy({ id: testCase.id })
15-
Nameserver.mysql.disconnect()
15+
await Nameserver.disconnect()
1616
})
1717

1818
describe('nameserver', function () {

0 commit comments

Comments
 (0)