@kravc/dos 1.9.2 → 1.9.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.
- package/package.json +1 -1
- package/src/Service.js +14 -2
- package/src/Service.spec.js +11 -3
package/package.json
CHANGED
package/src/Service.js
CHANGED
|
@@ -12,15 +12,27 @@ const OperationNotFoundError = require('./errors/OperationNotFoundError')
|
|
|
12
12
|
const { get, uniq, compact } = require('lodash')
|
|
13
13
|
|
|
14
14
|
const ROOT_PATH = process.cwd()
|
|
15
|
+
const DEFAULT_URL = 'http://localhost:3000/'
|
|
16
|
+
const DEFAULT_SERVICE_PATH = `${ROOT_PATH}/src`
|
|
17
|
+
const DEFAULT_SKIP_OPERATIONS = []
|
|
15
18
|
|
|
16
19
|
class Service {
|
|
17
|
-
constructor(modules,
|
|
20
|
+
constructor(modules, options = {}) {
|
|
21
|
+
let {
|
|
22
|
+
url = DEFAULT_URL,
|
|
23
|
+
path = DEFAULT_SERVICE_PATH,
|
|
24
|
+
skipOperations = DEFAULT_SKIP_OPERATIONS,
|
|
25
|
+
} = options
|
|
26
|
+
|
|
18
27
|
if (!url.endsWith('/')) { url = url + '/' }
|
|
19
28
|
|
|
20
29
|
const schemasMap = createSchemasMap(path)
|
|
21
30
|
|
|
22
31
|
let components = modules.filter(Component => !Component.types)
|
|
23
|
-
|
|
32
|
+
|
|
33
|
+
let operations = modules
|
|
34
|
+
.filter(Component => !!Component.types)
|
|
35
|
+
.filter(({ id }) => !skipOperations.includes(id))
|
|
24
36
|
|
|
25
37
|
const operationComponents = compact(operations.map(({ Component }) => Component))
|
|
26
38
|
components = uniq([ ...components, ...operationComponents ])
|
package/src/Service.spec.js
CHANGED
|
@@ -35,7 +35,11 @@ describe('Service', () => {
|
|
|
35
35
|
|
|
36
36
|
describe('Service.constructor(modules, url, path = \'/src\')', () => {
|
|
37
37
|
it('initializes service', () => {
|
|
38
|
-
const service = new Service(modules,
|
|
38
|
+
const service = new Service(modules, {
|
|
39
|
+
url: 'https://example.com/api',
|
|
40
|
+
path: `${ROOT_PATH}/examples`
|
|
41
|
+
})
|
|
42
|
+
|
|
39
43
|
expect(service).to.exist
|
|
40
44
|
})
|
|
41
45
|
|
|
@@ -71,8 +75,12 @@ describe('Service', () => {
|
|
|
71
75
|
})
|
|
72
76
|
|
|
73
77
|
describe('.handler(request)', () => {
|
|
74
|
-
const service = new Service(modules,
|
|
75
|
-
|
|
78
|
+
const service = new Service(modules, {
|
|
79
|
+
url: 'https://example.com/api/',
|
|
80
|
+
path: `${ROOT_PATH}/examples`
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const exec = test.execute(service)
|
|
76
84
|
|
|
77
85
|
const authorization = test.createAccessToken({}, { group: 'Administrators' })
|
|
78
86
|
|