anote-server-libs 0.4.2 → 0.4.4

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.2",
3
+ "version": "0.4.4",
4
4
  "description": "Helpers for express-TS servers",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -6,7 +6,7 @@ const ajv = new ajv_1.default();
6
6
  ajv.addKeyword({
7
7
  keyword: 'maxDigits',
8
8
  type: 'number',
9
- schemaType: 'integer',
9
+ schemaType: 'number',
10
10
  code(cxt) {
11
11
  const { data, schema } = cxt;
12
12
  const op = (0, ajv_1._) `!==`;
@@ -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 = 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
  }
@@ -5,7 +5,7 @@ const ajv = new Ajv();
5
5
  ajv.addKeyword({
6
6
  keyword: 'maxDigits',
7
7
  type: 'number',
8
- schemaType: 'integer',
8
+ schemaType: 'number',
9
9
  code(cxt: any) {
10
10
  const {data, schema} = cxt;
11
11
  const op = _`!==`;
@@ -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
  }