@kravc/dos 1.9.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kravc/dos",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "Convention-based, easy-to-use library for building API-driven serverless services.",
5
5
  "keywords": [
6
6
  "Service",
package/src/Document.js CHANGED
@@ -150,8 +150,18 @@ class Document extends Component {
150
150
  return { objects, ...rest }
151
151
  }
152
152
 
153
- static _index() {
154
- const items = Object.values(STORE[this.name] || {}).map(cloneDeep)
153
+ static async indexAll(context, query, options) {
154
+ return this.index(context, query, options)
155
+ }
156
+
157
+ static _index(query) {
158
+ const filter = item =>
159
+ Object.keys(query).every(key => item[key] === query[key])
160
+
161
+ const items = Object
162
+ .values(STORE[this.name] || {})
163
+ .filter(filter)
164
+ .map(cloneDeep)
155
165
 
156
166
  return { items, count: items.length }
157
167
  }
@@ -180,6 +180,9 @@ describe('Document', () => {
180
180
 
181
181
  expect(result.objects.length).to.eql(3)
182
182
  expect(result.count).to.eql(3)
183
+
184
+ result = await Profile.indexAll(context, { name: 'Dasha' })
185
+ expect(result.count).to.eql(1)
183
186
  })
184
187
  })
185
188
 
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, url = 'http://localhost:3000/', path = `${ROOT_PATH}/src`) {
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
- let operations = modules.filter(Component => !!Component.types)
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 ])
@@ -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, 'https://example.com/api', `${ROOT_PATH}/examples`)
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, 'https://example.com/api/', `${ROOT_PATH}/examples`)
75
- const exec = test.execute(service)
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