@kravc/dos 1.6.0 → 1.6.2

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.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Convention-based, easy-to-use library for building API-driven serverless services.",
5
5
  "keywords": [
6
6
  "Service",
@@ -25,7 +25,7 @@
25
25
  "author": "Alexander Kravets <a@kra.vc>",
26
26
  "license": "ISC",
27
27
  "dependencies": {
28
- "@kravc/schema": "^2.4.0",
28
+ "@kravc/schema": "^2.5.1",
29
29
  "cookie": "^0.5.0",
30
30
  "js-yaml": "^4.1.0",
31
31
  "jsonwebtoken": "^9.0.2",
package/src/Document.js CHANGED
@@ -64,6 +64,12 @@ class Document extends Component {
64
64
  }
65
65
 
66
66
  static async create(context, query, mutation) {
67
+ const { document: existingDocument } = context
68
+
69
+ if (existingDocument) {
70
+ return existingDocument
71
+ }
72
+
67
73
  if (!mutation) {
68
74
  mutation = query
69
75
  query = {}
@@ -64,6 +64,13 @@ describe('Document', () => {
64
64
  expect(profile.attributes.createdBy).to.not.exist
65
65
  })
66
66
 
67
+ it('returns exiting document from the context', async () => {
68
+ const profile = await Profile.create(context, { name: 'Volodymyr' })
69
+ const existingProfile = await Profile.create({ ...context, document: profile }, { name: 'Volodymyr' })
70
+
71
+ expect(profile.id).to.eql(existingProfile.id)
72
+ })
73
+
67
74
  it('throws "DocumentExistsError" if document already exists', async () => {
68
75
  const { id } = await Profile.create(context, {}, { name: 'Artem' })
69
76
  const error = await expectError(() => Profile.create(context, {}, { id, name: 'Liam' }))
package/src/Service.js CHANGED
@@ -107,7 +107,8 @@ class Service {
107
107
  if (!Operation) { throw new OperationNotFoundError({ operationId, httpMethod, httpPath }) }
108
108
 
109
109
  context.identity = await authorize(Operation, context)
110
- const parameters = this._getParameters(Operation.inputSchema, context)
110
+ const isUpdate = Operation.type === Operation.types.UPDATE
111
+ const parameters = this._getParameters(Operation.inputSchema, context, isUpdate)
111
112
 
112
113
  const operation = new Operation(context)
113
114
  response = await operation.exec(parameters)
@@ -143,7 +144,7 @@ class Service {
143
144
  return { statusCode, headers, multiValueHeaders, body }
144
145
  }
145
146
 
146
- _getParameters(inputSchema, context) {
147
+ _getParameters(inputSchema, context, shouldNullifyEmptyValues) {
147
148
  if (!inputSchema) { return {} }
148
149
 
149
150
  const { query, mutation } = context
@@ -152,7 +153,7 @@ class Service {
152
153
  let result
153
154
 
154
155
  try {
155
- result = this._validator.validate(input, inputSchema.id)
156
+ result = this._validator.validate(input, inputSchema.id, shouldNullifyEmptyValues)
156
157
 
157
158
  } catch (validationError) {
158
159
  throw new InvalidInputError(validationError, context)
@@ -30,3 +30,4 @@ error:
30
30
 
31
31
  path:
32
32
  description: Path of invalid attribute
33
+ type: array