anote-server-libs 0.4.3 → 0.4.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": "anote-server-libs",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "Helpers for express-TS servers",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WithBody = void 0;
3
+ exports.WithBody = exports.ajv = void 0;
4
4
  const ajv_1 = require("ajv");
5
- const ajv = new ajv_1.default();
6
- ajv.addKeyword({
5
+ exports.ajv = new ajv_1.default();
6
+ exports.ajv.addKeyword({
7
7
  keyword: 'maxDigits',
8
8
  type: 'number',
9
9
  schemaType: 'number',
@@ -28,21 +28,11 @@ function WithBody(schema) {
28
28
  });
29
29
  schema.required = required;
30
30
  }
31
- let validate = ajv.compile(schema);
31
+ const validate = exports.ajv.compile(schema);
32
32
  return function (_, __, descriptor) {
33
33
  if (typeof descriptor.value === 'function') {
34
34
  const previousMethod = descriptor.value;
35
35
  descriptor.value = function (req, res) {
36
- const keys = Object.getOwnPropertyNames(schema.properties);
37
- let dynKey = false;
38
- keys.forEach(key => {
39
- if (typeof schema.properties[key] === 'string') {
40
- schema.properties[key] = this.config.app.endpointsSchemas[schema.properties[key]];
41
- dynKey = true;
42
- }
43
- });
44
- if (dynKey)
45
- validate = ajv.compile(schema);
46
36
  if (req.method.toUpperCase() !== 'POST' && req.method.toUpperCase() !== 'PUT') {
47
37
  return previousMethod.call(this, req, res);
48
38
  }
@@ -1,7 +1,7 @@
1
1
  import {Request, Response} from 'express';
2
2
  import Ajv, {_} from 'ajv';
3
3
 
4
- const ajv = new Ajv();
4
+ export const ajv = new Ajv();
5
5
  ajv.addKeyword({
6
6
  keyword: 'maxDigits',
7
7
  type: 'number',
@@ -28,20 +28,11 @@ export function WithBody(schema: any) {
28
28
  });
29
29
  schema.required = required;
30
30
  }
31
- let validate = ajv.compile(schema);
31
+ const validate = ajv.compile(schema);
32
32
  return function(_: any, __: string, descriptor: PropertyDescriptor) {
33
33
  if(typeof descriptor.value === 'function') {
34
34
  const previousMethod = descriptor.value;
35
35
  descriptor.value = function(this: any, req: Request, res: Response) {
36
- const keys = Object.getOwnPropertyNames(schema.properties);
37
- let dynKey = false;
38
- keys.forEach(key => {
39
- if(typeof schema.properties[key] === 'string') {
40
- schema.properties[key] = this.config.app.endpointsSchemas[schema.properties[key]];
41
- dynKey = true;
42
- }
43
- });
44
- if(dynKey) validate = ajv.compile(schema);
45
36
  if(req.method.toUpperCase() !== 'POST' && req.method.toUpperCase() !== 'PUT') {
46
37
  return previousMethod.call(this, req, res);
47
38
  }