@@ -2,16 +2,13 @@ const path = require('path');
2
2
const fs = require ( 'fs' ) ;
3
3
const Ajv = require ( 'ajv' ) ;
4
4
const pluralize = require ( 'pluralize' ) ;
5
- const transliterate = require ( '../../../libs /transliterate' ) ;
5
+ const transliterate = require ( '@javascriptru /transliterate' ) ;
6
6
const uuid = require ( 'uuid/v4' ) ;
7
7
8
- const dbPath = path . join ( __dirname , '../data/db.json' ) ;
9
- const schemaPath = path . join ( __dirname , '../db.schemas.js' ) ;
8
+ module . exports = class Db {
10
9
11
- class Db {
12
-
13
- constructor ( filePath , schemasPath ) {
14
- this . filePath = filePath ;
10
+ constructor ( { dataPath, schemasPath} ) {
11
+ this . filePath = dataPath ;
15
12
let schemas = require ( schemasPath ) ;
16
13
this . ajv = new Ajv ( {
17
14
schemas,
@@ -20,14 +17,6 @@ class Db {
20
17
} ) ;
21
18
}
22
19
23
- static instance ( ) {
24
- if ( ! this . _instance ) {
25
- this . _instance = new Db ( dbPath , schemaPath ) ;
26
- this . _instance . load ( ) ;
27
- }
28
- return this . _instance ;
29
- }
30
-
31
20
getAll ( ) {
32
21
return this . data ;
33
22
}
@@ -81,11 +70,12 @@ class Db {
81
70
82
71
// product/db/...
83
72
getValidate ( name ) {
84
- return this . ajv . getSchema ( `https://javascript.info/schemas/ ${ name } .json` ) ;
73
+ return this . ajv . getSchema ( name ) ;
85
74
}
86
75
87
- validateSelf ( ) {
88
- let validate = this . ajv . getSchema ( `https://javascript.info/schemas/db.json` ) ;
76
+ validateAll ( ) {
77
+ // fixme
78
+ let validate = this . ajv . getSchema ( 'db' ) ;
89
79
if ( ! validate ( { db : this . data } ) ) {
90
80
console . error ( validate . errors ) ;
91
81
throw new Error ( "Validation error" ) ;
@@ -126,6 +116,3 @@ class Db {
126
116
}
127
117
128
118
}
129
-
130
-
131
- module . exports = Db . instance ( ) ;
0 commit comments