configurapi 1.6.8 → 1.7.0

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": "configurapi",
3
- "version": "1.6.8",
3
+ "version": "1.7.0",
4
4
  "description": "A configurable API framework",
5
5
  "main": "src/configurapi.js",
6
6
  "types": "src/configurapi.d.ts",
package/src/config.js CHANGED
@@ -5,6 +5,16 @@ let LogLevel = require('./logLevel');
5
5
  let yaml = require('js-yaml');
6
6
  let fs = require('fs');
7
7
  let NestedError = require('nested-error-stacks');
8
+ const nodePath = require('path');
9
+
10
+ function getPathParentDir(path)
11
+ {
12
+ if (!nodePath.isAbsolute(path))
13
+ {
14
+ path = nodePath.resolve(process.cwd(), path);
15
+ }
16
+ return nodePath.parse(path).dir
17
+ }
8
18
 
9
19
  module.exports = class Config
10
20
  {
@@ -27,10 +37,10 @@ module.exports = class Config
27
37
  throw new NestedError(`Failed to load '${path}'`, error);
28
38
  }
29
39
 
30
- return this.parse(content);
40
+ return this.parse(content, getPathParentDir(path));
31
41
  }
32
42
 
33
- static parse(content)
43
+ static parse(content, parentDirectory)
34
44
  {
35
45
 
36
46
  let document = yaml.safeLoad(content);
@@ -39,7 +49,7 @@ module.exports = class Config
39
49
  {
40
50
  let config = new Config();
41
51
 
42
- config.modules = this.parseImport(document);
52
+ config.modules = this.parseImport(document, parentDirectory);
43
53
  config.events = this.parseApi(document);
44
54
 
45
55
  return config;
@@ -50,7 +60,7 @@ module.exports = class Config
50
60
  }
51
61
  }
52
62
 
53
- static parseImport(document)
63
+ static parseImport(document, parentDirectory)
54
64
  {
55
65
  let result = [];
56
66
 
@@ -64,6 +74,10 @@ module.exports = class Config
64
74
 
65
75
  for(let module of document['import'])
66
76
  {
77
+ if (module.startsWith('.'))
78
+ {
79
+ module = nodePath.resolve(parentDirectory, module);
80
+ }
67
81
  result.push(module);
68
82
  }
69
83
  }
@@ -210,4 +224,4 @@ module.exports = class Config
210
224
 
211
225
  return policy.parameters || []
212
226
  }
213
- };
227
+ };
@@ -1,5 +1,4 @@
1
1
  const Result = require('../result');
2
- const getParams = require('get-parameter-names');
3
2
  const EventEmitter = require('events').EventEmitter;
4
3
  const LogLevel = require('../logLevel')
5
4
 
@@ -31,22 +30,14 @@ module.exports = class Policy extends EventEmitter
31
30
  let handlerParams = this.parameters instanceof Array ? this.parameters.slice(0) : [];
32
31
  handlerParams.unshift(event);
33
32
 
34
- let something = this.handler.apply(context, handlerParams);
35
-
36
- if(something instanceof Promise)
33
+ try
37
34
  {
38
- something.then(()=>
39
- {
40
- resolve(state);
41
- })
42
- .catch((error)=>
43
- {
44
- reject(error);
45
- })
35
+ await this.handler.apply(context, handlerParams);
36
+ resolve(state);
46
37
  }
47
- else
38
+ catch (error)
48
39
  {
49
- resolve(state);
40
+ reject(error);
50
41
  }
51
42
  });
52
43
  }
package/src/service.js CHANGED
@@ -83,11 +83,17 @@ module.exports = class Service extends events.EventEmitter
83
83
  this.emit(LogLevel.Trace, `configurapi - - Registerd ${route.name} route.`);
84
84
  });
85
85
 
86
- this._handleEvent('on_start');
86
+ this.onStartPromise = this._handleEvent('on_start');
87
87
  }
88
88
 
89
89
  async process(event)
90
90
  {
91
+ if (!this.isReady)
92
+ {
93
+ await this.onStartPromise
94
+ this.isReady = true;
95
+ }
96
+
91
97
  let watch = new Stopwatch();
92
98
 
93
99
  try