@kravc/dos 1.10.3 → 1.10.5

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.10.3",
3
+ "version": "1.10.5",
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
@@ -161,10 +161,6 @@ class Document extends Component {
161
161
  return { objects, ...rest }
162
162
  }
163
163
 
164
- static async indexAll(context, query, options) {
165
- return this.index(context, query, options)
166
- }
167
-
168
164
  static _index(query) {
169
165
  const filter = item =>
170
166
  Object.keys(query).every(key => item[key] === query[key])
@@ -177,6 +173,18 @@ class Document extends Component {
177
173
  return { items, count: items.length }
178
174
  }
179
175
 
176
+ static async indexAll(context, query = {}, options = {}) {
177
+ let { items, ...rest } = await this._indexAll(query, options)
178
+
179
+ const objects = items.map(item => new this(context, item))
180
+
181
+ return { objects, ...rest }
182
+ }
183
+
184
+ static _indexAll(query) {
185
+ return this._index(query)
186
+ }
187
+
180
188
  static async update(context, query, mutation, originalDocument = null) {
181
189
  mutation = omit(mutation, [ this.idKey, 'createdAt', 'createdBy' ])
182
190
 
@@ -183,6 +183,9 @@ describe('Document', () => {
183
183
 
184
184
  result = await Profile.indexAll(context, { name: 'Dasha' })
185
185
  expect(result.count).to.eql(1)
186
+
187
+ result = await Profile.indexAll(context)
188
+ expect(result.count).to.eql(3)
186
189
  })
187
190
  })
188
191
 
@@ -240,6 +243,10 @@ describe('Document', () => {
240
243
  const callbacks = {}
241
244
 
242
245
  class CustomProfile extends Profile {
246
+ static getPartition() {
247
+ return 'CustomProfile'
248
+ }
249
+
243
250
  static beforeCreate(context, mutation) {
244
251
  callbacks.beforeCreate = mutation
245
252
  }
@@ -88,6 +88,8 @@ class JwtAuthorization {
88
88
  return { isAuthorized: false, error }
89
89
  }
90
90
 
91
+ token = token.replace(/^bearer\s+/i, '')
92
+
91
93
  const object = decode(token, { complete: true })
92
94
 
93
95
  if (!object) {
@@ -17,7 +17,7 @@ const createAccessToken = (options, attributes) => {
17
17
 
18
18
  const token = JWT.sign(payload, privateKey, { algorithm, ...jwtOptions })
19
19
 
20
- return token
20
+ return `Bearer ${token}`
21
21
  }
22
22
 
23
23
  module.exports = createAccessToken