@thzero/library_server 0.16.12 → 0.16.13

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.
Files changed (53) hide show
  1. package/README.md +93 -93
  2. package/boot/index.js +431 -431
  3. package/boot/plugins/admin/index.js +6 -6
  4. package/boot/plugins/admin/news.js +33 -33
  5. package/boot/plugins/admin/users.js +33 -33
  6. package/boot/plugins/api.js +57 -57
  7. package/boot/plugins/apiFront.js +31 -31
  8. package/boot/plugins/index.js +70 -70
  9. package/boot/plugins/news.js +44 -44
  10. package/boot/plugins/users.js +46 -46
  11. package/boot/plugins/usersExtended.js +32 -32
  12. package/constants.js +45 -45
  13. package/data/baseNews.js +42 -42
  14. package/data/baseSettingsUser.js +9 -9
  15. package/data/baseUser.js +28 -28
  16. package/data/index.js +24 -24
  17. package/data/named.js +20 -20
  18. package/errors/tokenExpired.js +7 -7
  19. package/license.md +8 -8
  20. package/openSource.js +66 -66
  21. package/package.json +38 -38
  22. package/repository/index.js +174 -174
  23. package/repository/usageMetrics/devnull.js +11 -11
  24. package/routes/index.js +76 -76
  25. package/service/admin/baseNews.js +45 -45
  26. package/service/admin/index.js +130 -130
  27. package/service/admin/news.js +6 -6
  28. package/service/admin/users.js +107 -107
  29. package/service/baseSecurity.js +44 -44
  30. package/service/baseUser.js +122 -122
  31. package/service/communication.js +6 -6
  32. package/service/config.js +32 -32
  33. package/service/crypto.js +16 -16
  34. package/service/discovery/index.js +6 -6
  35. package/service/discovery/resources/index.js +101 -101
  36. package/service/external.js +19 -19
  37. package/service/externalRest.js +19 -19
  38. package/service/index.js +20 -20
  39. package/service/monitoring.js +12 -12
  40. package/service/news/base.js +49 -49
  41. package/service/news/index.js +6 -6
  42. package/service/news/validation/index.js +6 -6
  43. package/service/plans.js +27 -27
  44. package/service/restCommunication.js +21 -21
  45. package/service/usageMetrics.js +57 -57
  46. package/service/utility.js +177 -177
  47. package/service/version.js +32 -32
  48. package/utility/injector.js +59 -59
  49. package/utility/internalIp/index.js +48 -48
  50. package/utility/list/doubleLinked.js +88 -88
  51. package/utility/list/priorityQueue.js +109 -109
  52. package/utility/list/queue.js +72 -72
  53. package/utility/os.js +20 -20
@@ -1,88 +1,88 @@
1
- class DoubleLinkedList {
2
- constructor() {
3
- this._map = new Map();
4
- this._head = null;
5
- this._pointer = null;
6
- this._tail = null;
7
- }
8
-
9
- add(processId, proxy) {
10
- const node = { processId: processId, proxy: proxy };
11
- this._map.set(processId, node);
12
-
13
- // no element in list
14
- if (!this._head) {
15
- this._head = node;
16
- this._pointer = node;
17
- this._tail = node;
18
- return;
19
- }
20
-
21
- // adding to the tail
22
- this._tail.next = node;
23
- node.previous = this._tail;
24
- this._tail = node;
25
- }
26
-
27
- decrementPointer() {
28
- this._pointer = this._pointer.previous ? this._pointer.previous : this._tail;
29
- return this._pointer;
30
- }
31
-
32
- get(processId) {
33
- return this._map.get(processId);
34
- }
35
-
36
- has(processId) {
37
- return this._map.has(processId);
38
- }
39
-
40
- incrementPointer() {
41
- this._pointer = this._pointer.next ? this._pointer.next : this._head;
42
-
43
- return this._pointer;
44
- }
45
-
46
- remove(processId) {
47
- const node = this.get(processId);
48
- if (!node)
49
- return;
50
-
51
- if (node.previous)
52
- node.previous.next = node.next;
53
- if (node.next)
54
- node.next.previous = node.previous;
55
-
56
- if (this._head === node)
57
- this._head = node.next;
58
- if (this._tail === node)
59
- this._tail = node.previous;
60
-
61
- if (this._pointer === node) {
62
- this._pointer = node.next;
63
- if (!this._pointer)
64
- this._pointer = this._head;
65
- }
66
-
67
- this._map.delete(processId);
68
- }
69
-
70
- setPointer(processId) {
71
- const node = this._map.get(processId);
72
- if (!node)
73
- return;
74
-
75
- this._pointer = node;
76
- return this._pointer;
77
- }
78
-
79
- get length() {
80
- return this._map.size;
81
- }
82
-
83
- get pointer() {
84
- return this._pointer;
85
- }
86
- }
87
-
88
- export default DoubleLinkedList;
1
+ class DoubleLinkedList {
2
+ constructor() {
3
+ this._map = new Map();
4
+ this._head = null;
5
+ this._pointer = null;
6
+ this._tail = null;
7
+ }
8
+
9
+ add(processId, proxy) {
10
+ const node = { processId: processId, proxy: proxy };
11
+ this._map.set(processId, node);
12
+
13
+ // no element in list
14
+ if (!this._head) {
15
+ this._head = node;
16
+ this._pointer = node;
17
+ this._tail = node;
18
+ return;
19
+ }
20
+
21
+ // adding to the tail
22
+ this._tail.next = node;
23
+ node.previous = this._tail;
24
+ this._tail = node;
25
+ }
26
+
27
+ decrementPointer() {
28
+ this._pointer = this._pointer.previous ? this._pointer.previous : this._tail;
29
+ return this._pointer;
30
+ }
31
+
32
+ get(processId) {
33
+ return this._map.get(processId);
34
+ }
35
+
36
+ has(processId) {
37
+ return this._map.has(processId);
38
+ }
39
+
40
+ incrementPointer() {
41
+ this._pointer = this._pointer.next ? this._pointer.next : this._head;
42
+
43
+ return this._pointer;
44
+ }
45
+
46
+ remove(processId) {
47
+ const node = this.get(processId);
48
+ if (!node)
49
+ return;
50
+
51
+ if (node.previous)
52
+ node.previous.next = node.next;
53
+ if (node.next)
54
+ node.next.previous = node.previous;
55
+
56
+ if (this._head === node)
57
+ this._head = node.next;
58
+ if (this._tail === node)
59
+ this._tail = node.previous;
60
+
61
+ if (this._pointer === node) {
62
+ this._pointer = node.next;
63
+ if (!this._pointer)
64
+ this._pointer = this._head;
65
+ }
66
+
67
+ this._map.delete(processId);
68
+ }
69
+
70
+ setPointer(processId) {
71
+ const node = this._map.get(processId);
72
+ if (!node)
73
+ return;
74
+
75
+ this._pointer = node;
76
+ return this._pointer;
77
+ }
78
+
79
+ get length() {
80
+ return this._map.size;
81
+ }
82
+
83
+ get pointer() {
84
+ return this._pointer;
85
+ }
86
+ }
87
+
88
+ export default DoubleLinkedList;
@@ -1,109 +1,109 @@
1
- class PriorityQueue {
2
- constructor() {
3
- this._values = [];
4
- }
5
-
6
- dequeue() {
7
- // swap first and last element
8
- this._swap(0, this._values.length - 1);
9
- // pop max value off of values
10
- let poppedNode = this._values.pop();
11
- // re-adjust heap if length is greater than 1
12
- if (this._values.length > 1)
13
- this._bubbleDown();
14
-
15
- return poppedNode;
16
- }
17
-
18
- // method that pushes new value onto the end and calls the bubble helper
19
- enqueue(value) {
20
- this._values.push(value)
21
- // calculate parent, if parent is greater swap
22
- // while loop or recurse
23
- this._bubbleUp();
24
- return this._values
25
- }
26
-
27
- length() {
28
- return this._values.length;
29
- }
30
-
31
- _bubbleDown() {
32
- let parentIndex = 0;
33
- const length = this._values.length;
34
- const elementPriority = this._values[0].priority;
35
- // loop breaks if no swaps are needed
36
- // eslint-disable-next-line
37
- while (true) {
38
- // get indexes of child elements by following formula
39
- let leftChildIndex = (2 * parentIndex) + 1;
40
- let rightChildIndex = (2 * parentIndex) + 2;
41
- let leftChildPriority, rightChildPriority;
42
- let indexToSwap = null;
43
-
44
- // if left child exists, and is greater than the element, plan to swap with the left child index
45
- if (leftChildIndex < length) {
46
- leftChildPriority = this._values[leftChildIndex].priority;
47
- if (leftChildPriority < elementPriority)
48
- indexToSwap = leftChildIndex;
49
-
50
- }
51
-
52
- // if right child exists
53
- if (rightChildIndex < length) {
54
- rightChildPriority = this._values[rightChildIndex].priority;
55
-
56
- if (
57
- // if right child is greater than element and there are no plans to swap
58
- (rightChildPriority < elementPriority && indexToSwap === null) ||
59
- // OR if right child is greater than left child and there ARE plans to swap
60
- (rightChildPriority < leftChildPriority && indexToSwap !== null))
61
- {
62
- // plan to swap with the right child
63
- indexToSwap = rightChildIndex;
64
- }
65
- }
66
-
67
- // if there are no plans to swap, break out of the loop
68
- if (indexToSwap === null)
69
- break;
70
-
71
- // swap with planned element
72
- this._swap(parentIndex, indexToSwap);
73
- // starting index is now index that we swapped with
74
- parentIndex = indexToSwap;
75
- }
76
- }
77
-
78
- // helper methods that bubbles up values from end
79
- _bubbleUp() {
80
- // get index of inserted element
81
- let index = this._values.length - 1;
82
- // loop while index is not 0 or element no loger needs to bubble
83
- while (index > 0) {
84
- // get parent index via formula
85
- let parentIndex = Math.floor((index - 1)/2);
86
- // if values is greater than parent, swap the two
87
- if (this._values[parentIndex].priority > this._values[index].priority) {
88
- // swap with helper method
89
- this._swap(index, parentIndex);
90
- // change current index to parent index
91
- index = parentIndex;
92
- continue;
93
- }
94
-
95
- break;
96
- }
97
-
98
- return 0;
99
- }
100
-
101
- _swap(index1, index2) {
102
- let temp = this._values[index1];
103
- this._values[index1] = this._values[index2];
104
- this._values[index2] = temp;
105
- return this._values;
106
- }
107
- }
108
-
109
- export default PriorityQueue;
1
+ class PriorityQueue {
2
+ constructor() {
3
+ this._values = [];
4
+ }
5
+
6
+ dequeue() {
7
+ // swap first and last element
8
+ this._swap(0, this._values.length - 1);
9
+ // pop max value off of values
10
+ let poppedNode = this._values.pop();
11
+ // re-adjust heap if length is greater than 1
12
+ if (this._values.length > 1)
13
+ this._bubbleDown();
14
+
15
+ return poppedNode;
16
+ }
17
+
18
+ // method that pushes new value onto the end and calls the bubble helper
19
+ enqueue(value) {
20
+ this._values.push(value)
21
+ // calculate parent, if parent is greater swap
22
+ // while loop or recurse
23
+ this._bubbleUp();
24
+ return this._values
25
+ }
26
+
27
+ length() {
28
+ return this._values.length;
29
+ }
30
+
31
+ _bubbleDown() {
32
+ let parentIndex = 0;
33
+ const length = this._values.length;
34
+ const elementPriority = this._values[0].priority;
35
+ // loop breaks if no swaps are needed
36
+ // eslint-disable-next-line
37
+ while (true) {
38
+ // get indexes of child elements by following formula
39
+ let leftChildIndex = (2 * parentIndex) + 1;
40
+ let rightChildIndex = (2 * parentIndex) + 2;
41
+ let leftChildPriority, rightChildPriority;
42
+ let indexToSwap = null;
43
+
44
+ // if left child exists, and is greater than the element, plan to swap with the left child index
45
+ if (leftChildIndex < length) {
46
+ leftChildPriority = this._values[leftChildIndex].priority;
47
+ if (leftChildPriority < elementPriority)
48
+ indexToSwap = leftChildIndex;
49
+
50
+ }
51
+
52
+ // if right child exists
53
+ if (rightChildIndex < length) {
54
+ rightChildPriority = this._values[rightChildIndex].priority;
55
+
56
+ if (
57
+ // if right child is greater than element and there are no plans to swap
58
+ (rightChildPriority < elementPriority && indexToSwap === null) ||
59
+ // OR if right child is greater than left child and there ARE plans to swap
60
+ (rightChildPriority < leftChildPriority && indexToSwap !== null))
61
+ {
62
+ // plan to swap with the right child
63
+ indexToSwap = rightChildIndex;
64
+ }
65
+ }
66
+
67
+ // if there are no plans to swap, break out of the loop
68
+ if (indexToSwap === null)
69
+ break;
70
+
71
+ // swap with planned element
72
+ this._swap(parentIndex, indexToSwap);
73
+ // starting index is now index that we swapped with
74
+ parentIndex = indexToSwap;
75
+ }
76
+ }
77
+
78
+ // helper methods that bubbles up values from end
79
+ _bubbleUp() {
80
+ // get index of inserted element
81
+ let index = this._values.length - 1;
82
+ // loop while index is not 0 or element no loger needs to bubble
83
+ while (index > 0) {
84
+ // get parent index via formula
85
+ let parentIndex = Math.floor((index - 1)/2);
86
+ // if values is greater than parent, swap the two
87
+ if (this._values[parentIndex].priority > this._values[index].priority) {
88
+ // swap with helper method
89
+ this._swap(index, parentIndex);
90
+ // change current index to parent index
91
+ index = parentIndex;
92
+ continue;
93
+ }
94
+
95
+ break;
96
+ }
97
+
98
+ return 0;
99
+ }
100
+
101
+ _swap(index1, index2) {
102
+ let temp = this._values[index1];
103
+ this._values[index1] = this._values[index2];
104
+ this._values[index2] = temp;
105
+ return this._values;
106
+ }
107
+ }
108
+
109
+ export default PriorityQueue;
@@ -1,72 +1,72 @@
1
- /*
2
-
3
- Queue.js
4
-
5
- A function to represent a queue
6
-
7
- Created by Kate Morley - http://code.iamkate.com/ - and released under the terms
8
- of the CC0 1.0 Universal legal code:
9
-
10
- http://creativecommons.org/publicdomain/zero/1.0/legalcode
11
-
12
- */
13
-
14
- /* Creates a new queue. A queue is a first-in-first-out (FIFO) data structure -
15
- * items are added to the end of the queue and removed from the front.
16
- */
17
- function Queue(){
18
-
19
- // initialise the queue and offset
20
- var queue = [];
21
- var offset = 0;
22
-
23
- // Returns the length of the queue.
24
- this.length = function(){
25
- return (queue.length - offset);
26
- }
27
-
28
- // Returns true if the queue is empty, and false otherwise.
29
- this.isEmpty = function(){
30
- return (queue.length == 0);
31
- }
32
-
33
- /* Enqueues the specified item. The parameter is:
34
- *
35
- * item - the item to enqueue
36
- */
37
- this.enqueue = function(item){
38
- queue.push(item);
39
- }
40
-
41
- /* Dequeues an item and returns it. If the queue is empty, the value
42
- * 'undefined' is returned.
43
- */
44
- this.dequeue = function(){
45
-
46
- // if the queue is empty, return immediately
47
- if (queue.length == 0) return undefined;
48
-
49
- // store the item at the front of the queue
50
- var item = queue[offset];
51
-
52
- // increment the offset and remove the free space if necessary
53
- if (++ offset * 2 >= queue.length){
54
- queue = queue.slice(offset);
55
- offset = 0;
56
- }
57
-
58
- // return the dequeued item
59
- return item;
60
-
61
- }
62
-
63
- /* Returns the item at the front of the queue (without dequeuing it). If the
64
- * queue is empty then undefined is returned.
65
- */
66
- this.peek = function(){
67
- return (queue.length > 0 ? queue[offset] : undefined);
68
- }
69
-
70
- }
71
-
72
- export default Queue;
1
+ /*
2
+
3
+ Queue.js
4
+
5
+ A function to represent a queue
6
+
7
+ Created by Kate Morley - http://code.iamkate.com/ - and released under the terms
8
+ of the CC0 1.0 Universal legal code:
9
+
10
+ http://creativecommons.org/publicdomain/zero/1.0/legalcode
11
+
12
+ */
13
+
14
+ /* Creates a new queue. A queue is a first-in-first-out (FIFO) data structure -
15
+ * items are added to the end of the queue and removed from the front.
16
+ */
17
+ function Queue(){
18
+
19
+ // initialise the queue and offset
20
+ var queue = [];
21
+ var offset = 0;
22
+
23
+ // Returns the length of the queue.
24
+ this.length = function(){
25
+ return (queue.length - offset);
26
+ }
27
+
28
+ // Returns true if the queue is empty, and false otherwise.
29
+ this.isEmpty = function(){
30
+ return (queue.length == 0);
31
+ }
32
+
33
+ /* Enqueues the specified item. The parameter is:
34
+ *
35
+ * item - the item to enqueue
36
+ */
37
+ this.enqueue = function(item){
38
+ queue.push(item);
39
+ }
40
+
41
+ /* Dequeues an item and returns it. If the queue is empty, the value
42
+ * 'undefined' is returned.
43
+ */
44
+ this.dequeue = function(){
45
+
46
+ // if the queue is empty, return immediately
47
+ if (queue.length == 0) return undefined;
48
+
49
+ // store the item at the front of the queue
50
+ var item = queue[offset];
51
+
52
+ // increment the offset and remove the free space if necessary
53
+ if (++ offset * 2 >= queue.length){
54
+ queue = queue.slice(offset);
55
+ offset = 0;
56
+ }
57
+
58
+ // return the dequeued item
59
+ return item;
60
+
61
+ }
62
+
63
+ /* Returns the item at the front of the queue (without dequeuing it). If the
64
+ * queue is empty then undefined is returned.
65
+ */
66
+ this.peek = function(){
67
+ return (queue.length > 0 ? queue[offset] : undefined);
68
+ }
69
+
70
+ }
71
+
72
+ export default Queue;
package/utility/os.js CHANGED
@@ -1,20 +1,20 @@
1
- import os from 'os';
2
-
3
- class OsUtility {
4
- static get isLinux() {
5
- const type = os.type();
6
- return (/^linux/i.test(type) || /^freebsd/i.test(type) || /^darwin/i.test(type));
7
- }
8
-
9
- static get isMac() {
10
- const type = os.type();
11
- return (/^darwin/i.test(type));
12
- }
13
-
14
- static get isWin() {
15
- const type = os.type();
16
- return (/^win/i.test(type));
17
- }
18
- }
19
-
20
- export default OsUtility;
1
+ import os from 'os';
2
+
3
+ class OsUtility {
4
+ static get isLinux() {
5
+ const type = os.type();
6
+ return (/^linux/i.test(type) || /^freebsd/i.test(type) || /^darwin/i.test(type));
7
+ }
8
+
9
+ static get isMac() {
10
+ const type = os.type();
11
+ return (/^darwin/i.test(type));
12
+ }
13
+
14
+ static get isWin() {
15
+ const type = os.type();
16
+ return (/^win/i.test(type));
17
+ }
18
+ }
19
+
20
+ export default OsUtility;