@withjoy/limiter 0.0.7 → 0.0.8
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 +28 -0
- package/.nvmrc +1 -0
- package/README.md +2 -2
- package/limiter.js +9 -2
- package/package.json +1 -1
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,6 +20,9 @@ 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) {
|
|
@@ -35,7 +38,11 @@ class Limiter {
|
|
|
35
38
|
stub it to prevent a real connect from happening under Test Suite Conditions
|
|
36
39
|
*/
|
|
37
40
|
connect(url) {
|
|
38
|
-
|
|
41
|
+
if(!connection) {
|
|
42
|
+
connection = new LimitdClient(url);
|
|
43
|
+
this._limitd = connection;
|
|
44
|
+
}
|
|
45
|
+
return connection;
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
/*
|
|
@@ -80,7 +87,7 @@ class Limiter {
|
|
|
80
87
|
|
|
81
88
|
// promise wrapper for limitd lib take
|
|
82
89
|
_take (type, id, amount) {
|
|
83
|
-
return new Promise((resolve, reject) =>
|
|
90
|
+
return new Promise((resolve, reject) =>
|
|
84
91
|
this._limitd.take(type, id, amount, (err, resp) => {
|
|
85
92
|
if (err) {
|
|
86
93
|
this._console.error(err);
|