@kravc/dos 1.8.8 → 1.8.10
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 +3 -2
- package/specs/Documents.yaml +1 -0
- package/specs/Enums.yaml +1 -0
- package/specs/Operations.yaml +1 -0
- package/specs/Parameters.yaml +1 -0
- package/specs/Scenarios.yaml +1 -0
- package/specs/Schemas.yaml +1 -0
- package/src/Document.js +4 -4
- package/src/Service.spec.js +8 -0
- package/src/helpers/specMiddleware.js +30 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kravc/dos",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.10",
|
|
4
4
|
"description": "Convention-based, easy-to-use library for building API-driven serverless services.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Service",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"pluralize": "^8.0.0",
|
|
34
34
|
"ulid": "^2.3.0",
|
|
35
35
|
"uuid": "^9.0.1",
|
|
36
|
-
"z-schema": "^6.0.1"
|
|
36
|
+
"z-schema": "^6.0.1",
|
|
37
|
+
"read-yaml-file": "^2.1.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@eslint/eslintrc": "^3.2.0",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/specs/Enums.yaml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/src/Document.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { get, omit, capitalize } = require('lodash')
|
|
4
3
|
const { ulid } = require('ulid')
|
|
5
4
|
const Component = require('./Component')
|
|
6
5
|
const getIdPrefix = require('./helpers/getIdPrefix')
|
|
7
6
|
const getComponentTitle = require('./helpers/getComponentTitle')
|
|
8
7
|
const DocumentExistsError = require('./errors/DocumentExistsError')
|
|
9
8
|
const DocumentNotFoundError = require('./errors/DocumentNotFoundError')
|
|
9
|
+
const { get, omit, capitalize, cloneDeep } = require('lodash')
|
|
10
10
|
|
|
11
11
|
const STORE = {}
|
|
12
12
|
|
|
@@ -139,7 +139,7 @@ class Document extends Component {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
static _read({ id = 'NONE' }) {
|
|
142
|
-
return STORE[this.name][id]
|
|
142
|
+
return cloneDeep(STORE[this.name][id])
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
static async index(context, query = {}, options = {}) {
|
|
@@ -151,7 +151,7 @@ class Document extends Component {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
static _index() {
|
|
154
|
-
const items = Object.values(STORE[this.name] || {})
|
|
154
|
+
const items = Object.values(STORE[this.name] || {}).map(cloneDeep)
|
|
155
155
|
|
|
156
156
|
return { items, count: items.length }
|
|
157
157
|
}
|
|
@@ -201,7 +201,7 @@ class Document extends Component {
|
|
|
201
201
|
|
|
202
202
|
STORE[this.name][id] = { ...item, ...mutation }
|
|
203
203
|
|
|
204
|
-
return STORE[this.name][id]
|
|
204
|
+
return cloneDeep(STORE[this.name][id])
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
static async delete(context, query) {
|
package/src/Service.spec.js
CHANGED
|
@@ -289,6 +289,14 @@ describe('Service', () => {
|
|
|
289
289
|
const body = JSON.parse(response.body)
|
|
290
290
|
expect(body.swagger).to.exist
|
|
291
291
|
|
|
292
|
+
response = await lambdaFunction({ path: '/Documents.yaml', httpMethod: 'GET' })
|
|
293
|
+
response = await lambdaFunction({ path: '/Enums.yaml', httpMethod: 'GET' })
|
|
294
|
+
response = await lambdaFunction({ path: '/Operations.yaml', httpMethod: 'GET' })
|
|
295
|
+
response = await lambdaFunction({ path: '/Parameters.yaml', httpMethod: 'GET' })
|
|
296
|
+
response = await lambdaFunction({ path: '/Schenarios.yaml', httpMethod: 'GET' })
|
|
297
|
+
response = await lambdaFunction({ path: '/Schemas.yaml', httpMethod: 'GET' })
|
|
298
|
+
expect(response.statusCode).to.eql(200)
|
|
299
|
+
|
|
292
300
|
process.env.NODE_APP_INSTANCE = undefined
|
|
293
301
|
})
|
|
294
302
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { resolve }
|
|
3
|
+
const { resolve } = require('path')
|
|
4
|
+
const readYamlFile = require('read-yaml-file')
|
|
4
5
|
const { readFileSync } = require('fs')
|
|
5
6
|
|
|
6
7
|
const SWAGGER_UI_TEMPLATE_PATH = resolve(__dirname, '../../assets/index.html')
|
|
@@ -46,6 +47,34 @@ const specMiddleware = (service, context) => {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
const readFileJson = httpPath => {
|
|
51
|
+
const fileName = httpPath.replace('/', '')
|
|
52
|
+
const source = readYamlFile.sync(`${ROOT_PATH}/specs/${fileName}`)
|
|
53
|
+
|
|
54
|
+
return JSON.stringify(source, null, 2)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const isComposer = [
|
|
58
|
+
'/Enums.yaml',
|
|
59
|
+
'/Schemas.yaml',
|
|
60
|
+
'/Documents.yaml',
|
|
61
|
+
'/Scenarios.yaml',
|
|
62
|
+
'/Operations.yaml',
|
|
63
|
+
'/Parameters.yaml'
|
|
64
|
+
].includes(httpPath)
|
|
65
|
+
|
|
66
|
+
const shouldReturnComposerSpecs = isComposer && isDevelopment()
|
|
67
|
+
|
|
68
|
+
if (shouldReturnComposerSpecs) {
|
|
69
|
+
return {
|
|
70
|
+
headers: {
|
|
71
|
+
'Content-Type': 'application/json; charset=utf-8'
|
|
72
|
+
},
|
|
73
|
+
statusCode: 200,
|
|
74
|
+
body: readFileJson(httpPath),
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
49
78
|
return null
|
|
50
79
|
}
|
|
51
80
|
|