@volcanicminds/backend 0.3.6 → 0.5.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/.mocharc.json +3 -0
- package/README.md +1 -0
- package/TODO.md +0 -2
- package/dist/index.js +47 -36
- package/dist/index.js.map +1 -1
- package/dist/lib/api/auth/controller/auth.js +49 -50
- package/dist/lib/api/auth/controller/auth.js.map +1 -1
- package/dist/lib/api/token/controller/token.js +4 -4
- package/dist/lib/api/token/controller/token.js.map +1 -1
- package/dist/lib/api/tool/controller/tool.js +25 -0
- package/dist/lib/api/tool/controller/tool.js.map +1 -0
- package/dist/lib/api/tool/routes.js +26 -0
- package/dist/lib/api/tool/routes.js.map +1 -0
- package/dist/lib/hooks/onRequest.js +1 -7
- package/dist/lib/hooks/onRequest.js.map +1 -1
- package/dist/lib/loader/translation.js +53 -0
- package/dist/lib/loader/translation.js.map +1 -0
- package/dist/lib/locales/en.json +12 -0
- package/dist/lib/locales/it.json +12 -0
- package/dist/lib/util/errors.js +19 -0
- package/dist/lib/util/errors.js.map +1 -0
- package/dist/nodemon.json +7 -0
- package/dist/package.json +100 -0
- package/dist/tsconfig.json +32 -0
- package/index.ts +47 -38
- package/lib/api/auth/controller/auth.ts +52 -53
- package/lib/api/token/controller/token.ts +4 -4
- package/lib/api/tool/controller/tool.ts +13 -0
- package/lib/api/tool/routes.ts +24 -0
- package/lib/loader/translation.ts +67 -0
- package/lib/locales/en.json +12 -0
- package/lib/locales/it.json +12 -0
- package/lib/util/errors.ts +20 -0
- package/package.json +13 -7
- package/test/common/api.ts +80 -0
- package/test/common/bootstrap.ts +33 -0
- package/test/demo/demo.ts +9 -0
- package/test/demo/index.ts +14 -0
- package/test/e2e/index.ts +14 -0
- package/test/index.spec.ts +20 -0
- package/test/unit/index.ts +14 -0
- package/test/unit/semver.ts +24 -0
- package/test/unit/translation.ts +77 -0
- package/tsconfig.json +2 -1
- package/types/global.d.ts +5 -0
- package/test/example.test.js +0 -5
- package/test/semver.test.js +0 -16
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default function load() {
|
|
2
|
+
describe('demo', async () => {
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const files = fs.readdirSync(__dirname).filter((file) => !['index.ts'].includes(file))
|
|
5
|
+
|
|
6
|
+
await files.forEach(async (file) => {
|
|
7
|
+
try {
|
|
8
|
+
await require(`./${file}`)()
|
|
9
|
+
} catch (err) {
|
|
10
|
+
global.log.error(err)
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default function load() {
|
|
2
|
+
describe('e2e', async () => {
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const files = fs.readdirSync(__dirname).filter((file) => !['index.ts'].includes(file))
|
|
5
|
+
|
|
6
|
+
await files.forEach(async (file) => {
|
|
7
|
+
try {
|
|
8
|
+
await require(`./${file}`)()
|
|
9
|
+
} catch (err) {
|
|
10
|
+
global.log.error(err)
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { startUp, tearDown, buildTasks } from './common/bootstrap'
|
|
2
|
+
|
|
3
|
+
import demo from './demo'
|
|
4
|
+
import unit from './unit'
|
|
5
|
+
import e2e from './e2e'
|
|
6
|
+
|
|
7
|
+
const pkg = require('../package.json')
|
|
8
|
+
|
|
9
|
+
const beforeAll = global.beforeAll || global.before
|
|
10
|
+
const afterAll = global.afterAll || global.after
|
|
11
|
+
|
|
12
|
+
beforeAll(async () => await startUp())
|
|
13
|
+
afterAll(async () => await tearDown())
|
|
14
|
+
|
|
15
|
+
describe(`Test: ${pkg.name}@${pkg.version} on node@${process.version}`, async () => {
|
|
16
|
+
const tasks = buildTasks()
|
|
17
|
+
tasks.e2e && (await e2e())
|
|
18
|
+
tasks.unit && (await unit())
|
|
19
|
+
tasks.demo && (await demo())
|
|
20
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default function load() {
|
|
2
|
+
describe('unit', async () => {
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const files = fs.readdirSync(__dirname).filter((file) => !['index.ts'].includes(file))
|
|
5
|
+
|
|
6
|
+
await files.forEach(async (file) => {
|
|
7
|
+
try {
|
|
8
|
+
await require(`./${file}`)()
|
|
9
|
+
} catch (err) {
|
|
10
|
+
global.log.error(err)
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { expect } from 'expect'
|
|
2
|
+
|
|
3
|
+
module.exports = () => {
|
|
4
|
+
describe('Semver', () => {
|
|
5
|
+
it('should test semver library', () => {
|
|
6
|
+
const semver = require('semver')
|
|
7
|
+
|
|
8
|
+
const verx = 'v1.2.3'
|
|
9
|
+
const valid = semver.valid(verx)
|
|
10
|
+
const clean = semver.clean(verx)
|
|
11
|
+
|
|
12
|
+
const res1 = semver.satisfies(clean, '>1.0.0 <=1.2.4')
|
|
13
|
+
const res2 = semver.satisfies(clean, '>1.0')
|
|
14
|
+
const res3 = semver.satisfies(clean, '>1.0 <8.0')
|
|
15
|
+
|
|
16
|
+
global.log.debug(verx + ' ' + valid + ' ' + clean)
|
|
17
|
+
global.log.debug(res1 + ' ' + res2 + ' ' + res3)
|
|
18
|
+
|
|
19
|
+
expect(res1).toBeTruthy()
|
|
20
|
+
expect(res2).toBeTruthy()
|
|
21
|
+
expect(res3).toBeTruthy()
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { expect } from 'expect'
|
|
2
|
+
import { TranslatedError } from '../../lib/util/errors'
|
|
3
|
+
|
|
4
|
+
module.exports = () => {
|
|
5
|
+
describe('Translation', () => {
|
|
6
|
+
it('should translate various messages', () => {
|
|
7
|
+
try {
|
|
8
|
+
let translated = global.t.__('hello')
|
|
9
|
+
expect(translated).toBe('Hello')
|
|
10
|
+
|
|
11
|
+
translated = global.t.__('hello', 'Superman')
|
|
12
|
+
expect(translated).toBe('Hello')
|
|
13
|
+
|
|
14
|
+
translated = global.t.__('greeting.placeholder.formal', 'Superman')
|
|
15
|
+
expect(translated).toBe('Hello Superman')
|
|
16
|
+
|
|
17
|
+
translated = global.t.__({ phrase: 'greeting.placeholder.informal', locale: 'en' }, 'Superman')
|
|
18
|
+
expect(translated).toBe('Hi Superman')
|
|
19
|
+
|
|
20
|
+
translated = global.t.__({ phrase: 'greeting.placeholder.formal', locale: 'it' }, 'Superman')
|
|
21
|
+
expect(translated).toBe('Ciao Superman')
|
|
22
|
+
|
|
23
|
+
translated = global.t.__(
|
|
24
|
+
{ phrase: 'complex', locale: 'en' },
|
|
25
|
+
{ user: { firstname: 'Clark', lastname: 'Kent' } }
|
|
26
|
+
)
|
|
27
|
+
expect(translated).toBe('Hello Clark Kent')
|
|
28
|
+
|
|
29
|
+
translated = global.t.__(
|
|
30
|
+
{ phrase: 'complex', locale: 'it' },
|
|
31
|
+
{ user: { firstname: 'Clark', lastname: 'Kent' } }
|
|
32
|
+
)
|
|
33
|
+
expect(translated).toBe('Ciao Clark Kent')
|
|
34
|
+
} catch (err) {
|
|
35
|
+
global.log.error(err)
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('should translate various errors', () => {
|
|
40
|
+
let translated
|
|
41
|
+
try {
|
|
42
|
+
translated = new TranslatedError({ translationCode: 'hello' })
|
|
43
|
+
expect(translated).toBeDefined()
|
|
44
|
+
expect(translated.message).toBe('Hello')
|
|
45
|
+
expect(translated.translationCode).toBe('hello')
|
|
46
|
+
expect(translated.translatedMessage).toBe('Hello')
|
|
47
|
+
expect(translated.data).toMatchObject({})
|
|
48
|
+
expect(translated.name).toBe('TranslatedError')
|
|
49
|
+
expect(translated.locale).toBe('en')
|
|
50
|
+
|
|
51
|
+
translated = new TranslatedError({ translationCode: 'hello', locale: 'it' })
|
|
52
|
+
expect(translated).toBeDefined()
|
|
53
|
+
expect(translated.message).toBe('Ciao')
|
|
54
|
+
expect(translated.translationCode).toBe('hello')
|
|
55
|
+
expect(translated.translatedMessage).toBe('Ciao')
|
|
56
|
+
expect(translated.data).toEqual({})
|
|
57
|
+
expect(translated.name).toBe('TranslatedError')
|
|
58
|
+
expect(translated.locale).toBe('it')
|
|
59
|
+
|
|
60
|
+
translated = new TranslatedError({
|
|
61
|
+
translationCode: 'complex',
|
|
62
|
+
locale: 'it',
|
|
63
|
+
data: { user: { firstname: 'Clark', lastname: 'Kent' } }
|
|
64
|
+
})
|
|
65
|
+
expect(translated).toBeDefined()
|
|
66
|
+
expect(translated.message).toBe('Ciao Clark Kent')
|
|
67
|
+
expect(translated.translationCode).toBe('complex')
|
|
68
|
+
expect(translated.translatedMessage).toBe('Ciao Clark Kent')
|
|
69
|
+
expect(translated.data).toEqual({ user: { firstname: 'Clark', lastname: 'Kent' } })
|
|
70
|
+
expect(translated.name).toBe('TranslatedError')
|
|
71
|
+
expect(translated.locale).toBe('it')
|
|
72
|
+
} catch (err) {
|
|
73
|
+
global.log.error(err)
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"allowJs": true,
|
|
24
24
|
"outDir": "dist",
|
|
25
25
|
"lib": ["es7"],
|
|
26
|
+
"resolveJsonModule": true,
|
|
26
27
|
"paths": {
|
|
27
28
|
"@types": ["./types"]
|
|
28
29
|
}
|
|
@@ -34,6 +35,6 @@
|
|
|
34
35
|
// "*": ["*", "components/*"]
|
|
35
36
|
// }
|
|
36
37
|
},
|
|
37
|
-
"include": ["*.ts", "*.d.ts", "
|
|
38
|
+
"include": ["*.ts", "*.d.ts", "*.json", "lib/**/*", "lib/**/*.json", "types/*"],
|
|
38
39
|
"exclude": ["node_modules", "test/**/*"]
|
|
39
40
|
}
|
package/types/global.d.ts
CHANGED
|
@@ -112,6 +112,11 @@ export interface TokenManagement {
|
|
|
112
112
|
removeTokenById(id: string): any | null
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
export interface DataBaseManagement {
|
|
116
|
+
isImplemented(): boolean
|
|
117
|
+
synchronizeSchemas(): any | null
|
|
118
|
+
}
|
|
119
|
+
|
|
115
120
|
declare module 'fastify' {
|
|
116
121
|
export interface FastifyRequest {
|
|
117
122
|
user?: AuthenticatedUser
|
package/test/example.test.js
DELETED
package/test/semver.test.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
describe('semver', () => {
|
|
2
|
-
test('simple', () => {
|
|
3
|
-
const semver = require('semver')
|
|
4
|
-
|
|
5
|
-
const verx = 'v1.2.3+'
|
|
6
|
-
const valid = semver.valid(verx)
|
|
7
|
-
const clean = semver.clean(verx)
|
|
8
|
-
|
|
9
|
-
const res1 = semver.satisfies(clean, '>1.0.0 <=1.2.4')
|
|
10
|
-
const res2 = semver.satisfies(clean, '>1.0')
|
|
11
|
-
const res3 = semver.satisfies(clean, '>1.0 <8.0')
|
|
12
|
-
|
|
13
|
-
console.log(verx + ' ' + valid + ' ' + clean)
|
|
14
|
-
console.log(res1 + ' ' + res2 + ' ' + res3)
|
|
15
|
-
})
|
|
16
|
-
})
|