Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/group/store/mysql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Mysql from '../../mysql.js'
import GroupBase from './base.js'
import Permission from '../../permission.js'
import Permission from '../../permission/index.js'
import { mapToDbColumn } from '../../util.js'

const groupDbMap = { id: 'nt_group_id', parent_gid: 'parent_group_id' }
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/group/test.js → lib/group/test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict'
import { describe, it, after, before } from 'node:test'

import Group from './index.js'
import Group from '../index.js'

import testCase from '../test/group.json' with { type: 'json' }

Expand Down
18 changes: 18 additions & 0 deletions lib/nameserver/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const storeType = process.env.NICTOOL_DATA_STORE ?? 'mysql'

let RepoClass
switch (storeType) {
case 'toml':
RepoClass = (await import('./store/toml.js')).default
break
case 'mongodb':
RepoClass = (await import('./store/mongodb.js')).default
break
case 'elasticsearch':
RepoClass = (await import('./store/elasticsearch.js')).default
break
default:
RepoClass = (await import('./store/mysql.js')).default
}

export default new RepoClass()
44 changes: 44 additions & 0 deletions lib/nameserver/store/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Nameserver store base class – pure attributes and business logic.
*
* Has zero knowledge of how nameservers are persisted. All nameserver repository classes
* must extend this class and implement the repo contract methods.
*
* Repo contract:
* get(args) → object[]
* create(args) → number (zoneId)
* put(args) → boolean
* delete(args) → boolean
* destroy(args) → boolean
*/
class NameserverBase {
constructor(args = {}) {
this.debug = args?.debug ?? false
}

// -------------------------------------------------------------------------
// Repo contract – subclasses must implement these
// -------------------------------------------------------------------------

async get(_args) {
throw new Error('get() not implemented by this repo')
}

async create(_args) {
throw new Error('create() not implemented by this repo')
}

async put(_args) {
throw new Error('put() not implemented by this repo')
}

async delete(_args) {
throw new Error('delete() not implemented by this repo')
}

async destroy(_args) {
throw new Error('destroy() not implemented by this repo')
}
}

export default NameserverBase
10 changes: 6 additions & 4 deletions lib/nameserver.js → lib/nameserver/store/mysql.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Mysql from './mysql.js'
import { mapToDbColumn } from './util.js'
import Mysql from '../../mysql.js'
import NameserverBase from './base.js'
import { mapToDbColumn } from '../../util.js'

const nsDbMap = { id: 'nt_nameserver_id', gid: 'nt_group_id' }
const boolFields = ['deleted', 'export_serials']

class Nameserver {
class Nameserver extends NameserverBase {
constructor() {
super()
this.mysql = Mysql
}

Expand Down Expand Up @@ -94,7 +96,7 @@ class Nameserver {
}
}

export default new Nameserver()
export default Nameserver

function dbToObject(rows) {
for (const row of rows) {
Expand Down
4 changes: 2 additions & 2 deletions lib/nameserver.test.js → lib/nameserver/test/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import assert from 'node:assert/strict'
import { describe, it, after, before } from 'node:test'

import Nameserver from './nameserver.js'
import Nameserver from '../index.js'

import testCase from './test/nameserver.json' with { type: 'json' }
import testCase from './nameserver.json' with { type: 'json' }

before(async () => {
await Nameserver.destroy({ id: testCase.id })
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/permission.js → lib/permission/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Mysql from './mysql.js'
import { mapToDbColumn } from './util.js'
import Mysql from '../mysql.js'
import { mapToDbColumn } from '../util.js'

const permDbMap = {
id: 'nt_perm_id',
Expand Down
12 changes: 6 additions & 6 deletions lib/permission.test.js → lib/permission/test/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import assert from 'node:assert/strict'
import { describe, it, after, before } from 'node:test'

import Group from './group/index.js'
import User from './user/index.js'
import Permission from './permission.js'
import Group from '../../group/index.js'
import User from '../../user/index.js'
import Permission from '../index.js'

import groupTestCase from './test/group.json' with { type: 'json' }
import userTestCase from './test/user.json' with { type: 'json' }
import permTestCase from './test/permission.json' with { type: 'json' }
import groupTestCase from '../../group/test/group.json' with { type: 'json' }
import userTestCase from '../../user/test/user.json' with { type: 'json' }
import permTestCase from './permission.json' with { type: 'json' }

before(async () => {
await Group.create(groupTestCase)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, after, before } from 'node:test'

import User from './user/index.js'
import Session from './session.js'
import userCase from './test/user.json' with { type: 'json' }
import userCase from './user/test/user.json' with { type: 'json' }

const sessionUser = {
...userCase,
Expand Down
2 changes: 1 addition & 1 deletion lib/user/store/mysql.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Mysql from '../../mysql.js'
import Config from '../../config.js'
import UserBase from './base.js'
import Permission from '../../permission.js'
import Permission from '../../permission/index.js'
import { mapToDbColumn } from '../../util.js'

const userDbMap = { id: 'nt_user_id', gid: 'nt_group_id' }
Expand Down
8 changes: 4 additions & 4 deletions lib/user/test.js → lib/user/test/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import assert from 'node:assert/strict'
import { describe, it, after, before } from 'node:test'

import User from './index.js'
import Group from '../group/index.js'
import User from '../index.js'
import Group from '../../group/index.js'

import userCase from '../test/user.json' with { type: 'json' }
import groupCase from '../test/group.json' with { type: 'json' }
import userCase from './user.json' with { type: 'json' }
import groupCase from '../../group/test/group.json' with { type: 'json' }

before(async () => {
await Group.create(groupCase)
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion lib/zone.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/zone/test.js → lib/zone/test/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import assert from 'node:assert/strict'
import { describe, it, after, before } from 'node:test'

import Zone from './index.js'
import Zone from '../index.js'

import testCase from '../test/zone.json' with { type: 'json' }
import testCase from './zone.json' with { type: 'json' }

before(async () => {
await Zone.destroy({ id: testCase.id })
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion lib/zone_record.js

This file was deleted.

42 changes: 42 additions & 0 deletions lib/zone_record/store/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Zone Record domain class – pure contract, no persistence knowledge.
*
* All zone repository classes must extend this class and implement:
* get(args) → object[]
* count(args) → number
* create(args) → number (zoneId)
* put(args) → boolean
* delete(args) → boolean
* destroy(args) → boolean
*/
class ZoneRecordBase {
constructor(args = {}) {
this.debug = args?.debug ?? false
}

async get(_args) {
throw new Error('get() not implemented by this repo')
}

async count(_args) {
throw new Error('count() not implemented by this repo')
}

async create(_args) {
throw new Error('create() not implemented by this repo')
}

async put(_args) {
throw new Error('put() not implemented by this repo')
}

async delete(_args) {
throw new Error('delete() not implemented by this repo')
}

async destroy(_args) {
throw new Error('destroy() not implemented by this repo')
}
}

export default ZoneRecordBase
6 changes: 4 additions & 2 deletions lib/zone_record/store/mysql.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as RR from '@nictool/dns-resource-record'
import ZoneRecordBase from './base.js'

import Mysql from '../../mysql.js'
import { mapToDbColumn } from '../../util.js'
Expand All @@ -8,8 +9,9 @@ const boolFields = ['deleted']
const keepZeroWeightFor = new Set(['SRV', 'URI'])
const keepZeroPriorityFor = new Set(['HTTPS', 'SVCB', 'URI'])

class ZoneRecordRepoMySQL {
class ZoneRecordMySQL extends ZoneRecordBase {
constructor() {
super()
this.mysql = Mysql
}

Expand Down Expand Up @@ -92,7 +94,7 @@ class ZoneRecordRepoMySQL {
}
}

export default ZoneRecordRepoMySQL
export default ZoneRecordMySQL

function dbToObject(rows) {
rows = JSON.parse(JSON.stringify(rows))
Expand Down
7 changes: 3 additions & 4 deletions lib/zone_record.test.js → lib/zone_record/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'node:path'
import assert from 'node:assert/strict'
import { describe, it, after, before } from 'node:test'

import ZoneRecord from './zone_record.js'
import ZoneRecord from '../index.js'

after(async () => {
// await ZoneRecord.destroy({ id: testCase.id })
Expand Down Expand Up @@ -34,14 +34,13 @@ describe('zone_record', function () {
}
})

for (const rrType of fs.readdirSync('./lib/test/rrs')) {
// console.log(rrType)
for (const rrType of fs.readdirSync('lib/zone_record/test/rrs')) {
// if (rrType !== 'tlsa.json') continue
describe(`${path.basename(rrType, '.json').toUpperCase()}`, function () {
let testCase

before(async () => {
testCase = JSON.parse(fs.readFileSync(`./lib/test/rrs/${rrType}`))
testCase = JSON.parse(fs.readFileSync(`lib/zone_record/test/rrs/${rrType}`))
await ZoneRecord.destroy({ id: testCase.id })
await ZoneRecord.create(testCase)
})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion routes/nameserver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import validate from '@nictool/validate'

import Nameserver from '../lib/nameserver.js'
import Nameserver from '../lib/nameserver/index.js'
import { meta } from '../lib/util.js'

function NameserverRoutes(server) {
Expand Down
2 changes: 1 addition & 1 deletion routes/nameserver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, it, before, after } from 'node:test'
import { init } from './index.js'
import Group from '../lib/group/index.js'
import User from '../lib/user/index.js'
import Nameserver from '../lib/nameserver.js'
import Nameserver from '../lib/nameserver/index.js'

import groupCase from './test/group.json' with { type: 'json' }
import userCase from './test/user.json' with { type: 'json' }
Expand Down
2 changes: 1 addition & 1 deletion routes/permission.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import validate from '@nictool/validate'

import Permission from '../lib/permission.js'
import Permission from '../lib/permission/index.js'
import { meta } from '../lib/util.js'

function PermissionRoutes(server) {
Expand Down
2 changes: 1 addition & 1 deletion routes/permission.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, it, before, after } from 'node:test'
import { init } from './index.js'
import Group from '../lib/group/index.js'
import User from '../lib/user/index.js'
import Permission from '../lib/permission.js'
import Permission from '../lib/permission/index.js'

import groupCase from './test/group.json' with { type: 'json' }
import userCase from './test/user.json' with { type: 'json' }
Expand Down
2 changes: 1 addition & 1 deletion routes/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import permCase from './test/permission.json' with { type: 'json' }

import User from '../lib/user/index.js'
import Group from '../lib/group/index.js'
import Permission from '../lib/permission.js'
import Permission from '../lib/permission/index.js'

let server

Expand Down
2 changes: 1 addition & 1 deletion routes/zone.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import validate from '@nictool/validate'

import Zone from '../lib/zone.js'
import Zone from '../lib/zone/index.js'
import Mysql from '../lib/mysql.js'
import { meta } from '../lib/util.js'

Expand Down
2 changes: 1 addition & 1 deletion routes/zone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, it, before, after } from 'node:test'
import { init } from './index.js'
import Group from '../lib/group/index.js'
import User from '../lib/user/index.js'
import Zone from '../lib/zone.js'
import Zone from '../lib/zone/index.js'

import groupCase from './test/group.json' with { type: 'json' }
import userCase from './test/user.json' with { type: 'json' }
Expand Down
4 changes: 2 additions & 2 deletions routes/zone_record.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import validate from '@nictool/validate'

import ZoneRecord from '../lib/zone_record.js'
import Zone from '../lib/zone.js'
import ZoneRecord from '../lib/zone_record/index.js'
import Zone from '../lib/zone/index.js'
import { meta } from '../lib/util.js'

async function zoneRecordResponseFailAction(request, h, err) {
Expand Down
4 changes: 2 additions & 2 deletions routes/zone_record.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { describe, it, before, after } from 'node:test'
import { init } from './index.js'
import Group from '../lib/group/index.js'
import User from '../lib/user/index.js'
import Zone from '../lib/zone.js'
import ZoneRecord from '../lib/zone_record.js'
import Zone from '../lib/zone/index.js'
import ZoneRecord from '../lib/zone_record/index.js'

import groupCase from './test/group.json' with { type: 'json' }
import userCase from './test/user.json' with { type: 'json' }
Expand Down
14 changes: 7 additions & 7 deletions test-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import path from 'node:path'
import Group from './lib/group/index.js'
import User from './lib/user/index.js'
import Session from './lib/session.js'
import Permission from './lib/permission.js'
import Nameserver from './lib/nameserver.js'
import Zone from './lib/zone.js'
import Permission from './lib/permission/index.js'
import Nameserver from './lib/nameserver/index.js'
import Zone from './lib/zone/index.js'
// import ZoneRecord from './lib/zone_record.js'

import groupCase from './lib/test/group.json' with { type: 'json' }
import userCase from './lib/test/user.json' with { type: 'json' }
import zoneCase from './lib/test/zone.json' with { type: 'json' }
// import zrCase from './lib/test/zone_record.json' with { type: 'json' }
import groupCase from './lib/group/test/group.json' with { type: 'json' }
import userCase from './lib/user/test/user.json' with { type: 'json' }
import zoneCase from './lib/zone/test/zone.json' with { type: 'json' }
// import zrCase from './lib/zone_record/test/zone_record.json' with { type: 'json' }
import groupCaseR from './routes/test/group.json' with { type: 'json' }
import userCaseR from './routes/test/user.json' with { type: 'json' }
import nsCaseR from './routes/test/nameserver.json' with { type: 'json' }
Expand Down
Loading
Loading