@withjoy/limiter 0.0.6 → 0.0.9

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/.editorconfig ADDED
@@ -0,0 +1,28 @@
1
+ # Look for an EditorConfig plugin for your tool of choice,
2
+ # or you might not be able to commit code ;)
3
+
4
+ # http://editorconfig.org
5
+
6
+ # top-most EditorConfig file, as we could have one per folder
7
+ root = true
8
+
9
+ # All files
10
+ # - use UTF-8
11
+ # - use Unix-style newlines with a newline ending every file
12
+ # - indent by spaces
13
+ # - get whitespace-trimmed
14
+ [*]
15
+ charset = utf-8
16
+ end_of_line = lf
17
+ insert_final_newline = true
18
+ indent_style = space
19
+ trim_trailing_whitespace = true
20
+
21
+ # JavaScript, JSON
22
+ [*.{js,json}]
23
+ indent_style = tab
24
+ indent_size = 2
25
+
26
+ # Markdown
27
+ [*.md]
28
+ indent_size = 2
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 10
package/README.md CHANGED
@@ -11,6 +11,8 @@ Provides utilities and rollback functionality for our clients.
11
11
 
12
12
  ##### How can I run that limitd instance quickly ?
13
13
 
14
+ check [the Wiki](https://withjoy.atlassian.net/wiki/spaces/KNOW/pages/1905557728/Running+withjoy+limitd+locally)
15
+
14
16
  run this in the root of this repo:
15
17
  ```bash
16
18
  docker run -p 9231:9231 \
@@ -18,5 +20,3 @@ run this in the root of this repo:
18
20
  type=bind,source="$(pwd)"/tests/limitd.config,target=/etc/limitd.config \
19
21
  -it joylife/limitd:release-6-d5e4805
20
22
  ```
21
-
22
-
package/limiter.js CHANGED
@@ -20,12 +20,29 @@ class Operation {
20
20
  }
21
21
  }
22
22
 
23
+ // global singleton
24
+ let connection = null;
25
+
23
26
  class Limiter {
24
27
 
25
28
  constructor(config) {
26
- this._limitd = new LimitdClient(config.limitdUrl);
27
29
  this._console = config.console;
28
30
  this._operationList = [];
31
+ this._limitd = undefined;
32
+ this.connect(config.limitdUrl);
33
+ }
34
+
35
+ /*
36
+ The LimitD Client will auto-connect,
37
+ and we invoke this method from the Constructor.
38
+ stub it to prevent a real connect from happening under Test Suite Conditions
39
+ */
40
+ connect(url) {
41
+ if(!connection) {
42
+ connection = new LimitdClient(url);
43
+ }
44
+ this._limitd = connection;
45
+ return connection;
29
46
  }
30
47
 
31
48
  /*
@@ -70,7 +87,7 @@ class Limiter {
70
87
 
71
88
  // promise wrapper for limitd lib take
72
89
  _take (type, id, amount) {
73
- return new Promise((resolve, reject) =>
90
+ return new Promise((resolve, reject) =>
74
91
  this._limitd.take(type, id, amount, (err, resp) => {
75
92
  if (err) {
76
93
  this._console.error(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withjoy/limiter",
3
- "version": "0.0.6",
3
+ "version": "0.0.9",
4
4
  "description": "Api Rate limiter",
5
5
  "main": "limiter.js",
6
6
  "scripts": {
package/.npmignore DELETED
@@ -1,63 +0,0 @@
1
- # Logs
2
- logs
3
- *.log
4
- npm-debug.log*
5
- yarn-debug.log*
6
- yarn-error.log*
7
-
8
- # Runtime data
9
- pids
10
- *.pid
11
- *.seed
12
- *.pid.lock
13
-
14
- # Directory for instrumented libs generated by jscoverage/JSCover
15
- lib-cov
16
-
17
- # Coverage directory used by tools like istanbul
18
- coverage
19
-
20
- # nyc test coverage
21
- .nyc_output
22
-
23
- # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24
- .grunt
25
-
26
- # Bower dependency directory (https://bower.io/)
27
- bower_components
28
-
29
- # node-waf configuration
30
- .lock-wscript
31
-
32
- # Compiled binary addons (http://nodejs.org/api/addons.html)
33
- build/Release
34
-
35
- # Dependency directories
36
- node_modules/
37
- jspm_packages/
38
-
39
- # Typescript v1 declaration files
40
- typings/
41
-
42
- # Optional npm cache directory
43
- .npm
44
-
45
- # Optional eslint cache
46
- .eslintcache
47
-
48
- # Optional REPL history
49
- .node_repl_history
50
-
51
- # Output of 'npm pack'
52
- *.tgz
53
-
54
- # Yarn Integrity file
55
- .yarn-integrity
56
-
57
- # dotenv environment variables file
58
- .env
59
-
60
-
61
- #db
62
- db
63
- tests/db