@devmoods/observability 0.4.0 → 0.5.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.
@@ -1,210 +1,205 @@
1
1
  /* eslint-disable */
2
- var addSorting = (function() {
3
- 'use strict';
4
- var cols,
5
- currentSort = {
6
- index: 0,
7
- desc: false
8
- };
2
+ var addSorting = (function () {
3
+ "use strict";
4
+ var cols,
5
+ currentSort = {
6
+ index: 0,
7
+ desc: false,
8
+ };
9
9
 
10
- // returns the summary table element
11
- function getTable() {
12
- return document.querySelector('.coverage-summary');
13
- }
14
- // returns the thead element of the summary table
15
- function getTableHeader() {
16
- return getTable().querySelector('thead tr');
17
- }
18
- // returns the tbody element of the summary table
19
- function getTableBody() {
20
- return getTable().querySelector('tbody');
21
- }
22
- // returns the th element for nth column
23
- function getNthColumn(n) {
24
- return getTableHeader().querySelectorAll('th')[n];
10
+ // returns the summary table element
11
+ function getTable() {
12
+ return document.querySelector(".coverage-summary");
13
+ }
14
+ // returns the thead element of the summary table
15
+ function getTableHeader() {
16
+ return getTable().querySelector("thead tr");
17
+ }
18
+ // returns the tbody element of the summary table
19
+ function getTableBody() {
20
+ return getTable().querySelector("tbody");
21
+ }
22
+ // returns the th element for nth column
23
+ function getNthColumn(n) {
24
+ return getTableHeader().querySelectorAll("th")[n];
25
+ }
26
+
27
+ function onFilterInput() {
28
+ const searchValue = document.getElementById("fileSearch").value;
29
+ const rows = document.getElementsByTagName("tbody")[0].children;
30
+
31
+ // Try to create a RegExp from the searchValue. If it fails (invalid regex),
32
+ // it will be treated as a plain text search
33
+ let searchRegex;
34
+ try {
35
+ searchRegex = new RegExp(searchValue, "i"); // 'i' for case-insensitive
36
+ } catch (error) {
37
+ searchRegex = null;
25
38
  }
26
39
 
27
- function onFilterInput() {
28
- const searchValue = document.getElementById('fileSearch').value;
29
- const rows = document.getElementsByTagName('tbody')[0].children;
30
-
31
- // Try to create a RegExp from the searchValue. If it fails (invalid regex),
32
- // it will be treated as a plain text search
33
- let searchRegex;
34
- try {
35
- searchRegex = new RegExp(searchValue, 'i'); // 'i' for case-insensitive
36
- } catch (error) {
37
- searchRegex = null;
38
- }
40
+ for (let i = 0; i < rows.length; i++) {
41
+ const row = rows[i];
42
+ let isMatch = false;
39
43
 
40
- for (let i = 0; i < rows.length; i++) {
41
- const row = rows[i];
42
- let isMatch = false;
43
-
44
- if (searchRegex) {
45
- // If a valid regex was created, use it for matching
46
- isMatch = searchRegex.test(row.textContent);
47
- } else {
48
- // Otherwise, fall back to the original plain text search
49
- isMatch = row.textContent
50
- .toLowerCase()
51
- .includes(searchValue.toLowerCase());
52
- }
53
-
54
- row.style.display = isMatch ? '' : 'none';
55
- }
56
- }
44
+ if (searchRegex) {
45
+ // If a valid regex was created, use it for matching
46
+ isMatch = searchRegex.test(row.textContent);
47
+ } else {
48
+ // Otherwise, fall back to the original plain text search
49
+ isMatch = row.textContent.toLowerCase().includes(searchValue.toLowerCase());
50
+ }
57
51
 
58
- // loads the search box
59
- function addSearchBox() {
60
- var template = document.getElementById('filterTemplate');
61
- var templateClone = template.content.cloneNode(true);
62
- templateClone.getElementById('fileSearch').oninput = onFilterInput;
63
- template.parentElement.appendChild(templateClone);
52
+ row.style.display = isMatch ? "" : "none";
64
53
  }
65
-
66
- // loads all columns
67
- function loadColumns() {
68
- var colNodes = getTableHeader().querySelectorAll('th'),
69
- colNode,
70
- cols = [],
71
- col,
72
- i;
73
-
74
- for (i = 0; i < colNodes.length; i += 1) {
75
- colNode = colNodes[i];
76
- col = {
77
- key: colNode.getAttribute('data-col'),
78
- sortable: !colNode.getAttribute('data-nosort'),
79
- type: colNode.getAttribute('data-type') || 'string'
80
- };
81
- cols.push(col);
82
- if (col.sortable) {
83
- col.defaultDescSort = col.type === 'number';
84
- colNode.innerHTML =
85
- colNode.innerHTML + '<span class="sorter"></span>';
86
- }
87
- }
88
- return cols;
54
+ }
55
+
56
+ // loads the search box
57
+ function addSearchBox() {
58
+ var template = document.getElementById("filterTemplate");
59
+ var templateClone = template.content.cloneNode(true);
60
+ templateClone.getElementById("fileSearch").oninput = onFilterInput;
61
+ template.parentElement.appendChild(templateClone);
62
+ }
63
+
64
+ // loads all columns
65
+ function loadColumns() {
66
+ var colNodes = getTableHeader().querySelectorAll("th"),
67
+ colNode,
68
+ cols = [],
69
+ col,
70
+ i;
71
+
72
+ for (i = 0; i < colNodes.length; i += 1) {
73
+ colNode = colNodes[i];
74
+ col = {
75
+ key: colNode.getAttribute("data-col"),
76
+ sortable: !colNode.getAttribute("data-nosort"),
77
+ type: colNode.getAttribute("data-type") || "string",
78
+ };
79
+ cols.push(col);
80
+ if (col.sortable) {
81
+ col.defaultDescSort = col.type === "number";
82
+ colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
83
+ }
89
84
  }
90
- // attaches a data attribute to every tr element with an object
91
- // of data values keyed by column name
92
- function loadRowData(tableRow) {
93
- var tableCols = tableRow.querySelectorAll('td'),
94
- colNode,
95
- col,
96
- data = {},
97
- i,
98
- val;
99
- for (i = 0; i < tableCols.length; i += 1) {
100
- colNode = tableCols[i];
101
- col = cols[i];
102
- val = colNode.getAttribute('data-value');
103
- if (col.type === 'number') {
104
- val = Number(val);
105
- }
106
- data[col.key] = val;
107
- }
108
- return data;
85
+ return cols;
86
+ }
87
+ // attaches a data attribute to every tr element with an object
88
+ // of data values keyed by column name
89
+ function loadRowData(tableRow) {
90
+ var tableCols = tableRow.querySelectorAll("td"),
91
+ colNode,
92
+ col,
93
+ data = {},
94
+ i,
95
+ val;
96
+ for (i = 0; i < tableCols.length; i += 1) {
97
+ colNode = tableCols[i];
98
+ col = cols[i];
99
+ val = colNode.getAttribute("data-value");
100
+ if (col.type === "number") {
101
+ val = Number(val);
102
+ }
103
+ data[col.key] = val;
109
104
  }
110
- // loads all row data
111
- function loadData() {
112
- var rows = getTableBody().querySelectorAll('tr'),
113
- i;
114
-
115
- for (i = 0; i < rows.length; i += 1) {
116
- rows[i].data = loadRowData(rows[i]);
117
- }
105
+ return data;
106
+ }
107
+ // loads all row data
108
+ function loadData() {
109
+ var rows = getTableBody().querySelectorAll("tr"),
110
+ i;
111
+
112
+ for (i = 0; i < rows.length; i += 1) {
113
+ rows[i].data = loadRowData(rows[i]);
118
114
  }
119
- // sorts the table using the data for the ith column
120
- function sortByIndex(index, desc) {
121
- var key = cols[index].key,
122
- sorter = function(a, b) {
123
- a = a.data[key];
124
- b = b.data[key];
125
- return a < b ? -1 : a > b ? 1 : 0;
126
- },
127
- finalSorter = sorter,
128
- tableBody = document.querySelector('.coverage-summary tbody'),
129
- rowNodes = tableBody.querySelectorAll('tr'),
130
- rows = [],
131
- i;
132
-
133
- if (desc) {
134
- finalSorter = function(a, b) {
135
- return -1 * sorter(a, b);
136
- };
137
- }
138
-
139
- for (i = 0; i < rowNodes.length; i += 1) {
140
- rows.push(rowNodes[i]);
141
- tableBody.removeChild(rowNodes[i]);
142
- }
143
-
144
- rows.sort(finalSorter);
145
-
146
- for (i = 0; i < rows.length; i += 1) {
147
- tableBody.appendChild(rows[i]);
148
- }
115
+ }
116
+ // sorts the table using the data for the ith column
117
+ function sortByIndex(index, desc) {
118
+ var key = cols[index].key,
119
+ sorter = function (a, b) {
120
+ a = a.data[key];
121
+ b = b.data[key];
122
+ return a < b ? -1 : a > b ? 1 : 0;
123
+ },
124
+ finalSorter = sorter,
125
+ tableBody = document.querySelector(".coverage-summary tbody"),
126
+ rowNodes = tableBody.querySelectorAll("tr"),
127
+ rows = [],
128
+ i;
129
+
130
+ if (desc) {
131
+ finalSorter = function (a, b) {
132
+ return -1 * sorter(a, b);
133
+ };
149
134
  }
150
- // removes sort indicators for current column being sorted
151
- function removeSortIndicators() {
152
- var col = getNthColumn(currentSort.index),
153
- cls = col.className;
154
135
 
155
- cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
156
- col.className = cls;
136
+ for (i = 0; i < rowNodes.length; i += 1) {
137
+ rows.push(rowNodes[i]);
138
+ tableBody.removeChild(rowNodes[i]);
157
139
  }
158
- // adds sort indicators for current column being sorted
159
- function addSortIndicators() {
160
- getNthColumn(currentSort.index).className += currentSort.desc
161
- ? ' sorted-desc'
162
- : ' sorted';
140
+
141
+ rows.sort(finalSorter);
142
+
143
+ for (i = 0; i < rows.length; i += 1) {
144
+ tableBody.appendChild(rows[i]);
163
145
  }
164
- // adds event listeners for all sorter widgets
165
- function enableUI() {
166
- var i,
167
- el,
168
- ithSorter = function ithSorter(i) {
169
- var col = cols[i];
170
-
171
- return function() {
172
- var desc = col.defaultDescSort;
173
-
174
- if (currentSort.index === i) {
175
- desc = !currentSort.desc;
176
- }
177
- sortByIndex(i, desc);
178
- removeSortIndicators();
179
- currentSort.index = i;
180
- currentSort.desc = desc;
181
- addSortIndicators();
182
- };
183
- };
184
- for (i = 0; i < cols.length; i += 1) {
185
- if (cols[i].sortable) {
186
- // add the click event handler on the th so users
187
- // dont have to click on those tiny arrows
188
- el = getNthColumn(i).querySelector('.sorter').parentElement;
189
- if (el.addEventListener) {
190
- el.addEventListener('click', ithSorter(i));
191
- } else {
192
- el.attachEvent('onclick', ithSorter(i));
193
- }
194
- }
146
+ }
147
+ // removes sort indicators for current column being sorted
148
+ function removeSortIndicators() {
149
+ var col = getNthColumn(currentSort.index),
150
+ cls = col.className;
151
+
152
+ cls = cls.replace(/ sorted$/, "").replace(/ sorted-desc$/, "");
153
+ col.className = cls;
154
+ }
155
+ // adds sort indicators for current column being sorted
156
+ function addSortIndicators() {
157
+ getNthColumn(currentSort.index).className += currentSort.desc ? " sorted-desc" : " sorted";
158
+ }
159
+ // adds event listeners for all sorter widgets
160
+ function enableUI() {
161
+ var i,
162
+ el,
163
+ ithSorter = function ithSorter(i) {
164
+ var col = cols[i];
165
+
166
+ return function () {
167
+ var desc = col.defaultDescSort;
168
+
169
+ if (currentSort.index === i) {
170
+ desc = !currentSort.desc;
171
+ }
172
+ sortByIndex(i, desc);
173
+ removeSortIndicators();
174
+ currentSort.index = i;
175
+ currentSort.desc = desc;
176
+ addSortIndicators();
177
+ };
178
+ };
179
+ for (i = 0; i < cols.length; i += 1) {
180
+ if (cols[i].sortable) {
181
+ // add the click event handler on the th so users
182
+ // dont have to click on those tiny arrows
183
+ el = getNthColumn(i).querySelector(".sorter").parentElement;
184
+ if (el.addEventListener) {
185
+ el.addEventListener("click", ithSorter(i));
186
+ } else {
187
+ el.attachEvent("onclick", ithSorter(i));
195
188
  }
189
+ }
196
190
  }
197
- // adds sorting functionality to the UI
198
- return function() {
199
- if (!getTable()) {
200
- return;
201
- }
202
- cols = loadColumns();
203
- loadData();
204
- addSearchBox();
205
- addSortIndicators();
206
- enableUI();
207
- };
191
+ }
192
+ // adds sorting functionality to the UI
193
+ return function () {
194
+ if (!getTable()) {
195
+ return;
196
+ }
197
+ cols = loadColumns();
198
+ loadData();
199
+ addSearchBox();
200
+ addSortIndicators();
201
+ enableUI();
202
+ };
208
203
  })();
209
204
 
210
- window.addEventListener('load', addSorting);
205
+ window.addEventListener("load", addSorting);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devmoods/observability",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -21,5 +21,5 @@
21
21
  "build": "pnpm run clean && tsc",
22
22
  "prepublishOnly": "pnpm run clean && pnpm run build"
23
23
  },
24
- "gitHead": "97c5d5f84397815a726bf44ae3f401f24c852fc6"
24
+ "gitHead": "60fe0c3459c81c7d71a4423cdc66d046d166de75"
25
25
  }
@@ -1,19 +1,21 @@
1
1
  import { Metrics, metrics, startTimer } from '../index.js';
2
2
 
3
- test('startTimer', async () => {
4
- const timer = startTimer();
5
- let duration = timer.getDuration();
6
- expect(duration).toBeGreaterThan(0);
7
-
8
- await new Promise((resolve) => setTimeout(resolve, 500));
9
-
10
- duration = timer.getDuration();
11
- expect(duration + 0.001).toBeGreaterThan(0.5);
12
-
13
- timer.reset();
14
-
15
- duration = timer.getDuration();
16
- expect(duration).toBeLessThan(0.01);
3
+ test('startTimer', () => {
4
+ vi.useFakeTimers();
5
+ try {
6
+ const timer = startTimer();
7
+ vi.advanceTimersByTime(1);
8
+ expect(timer.getDuration()).toBeGreaterThan(0);
9
+
10
+ vi.advanceTimersByTime(500);
11
+ expect(timer.getDuration()).toBeGreaterThanOrEqual(0.5);
12
+
13
+ timer.reset();
14
+ vi.advanceTimersByTime(1);
15
+ expect(timer.getDuration()).toBeLessThan(0.01);
16
+ } finally {
17
+ vi.useRealTimers();
18
+ }
17
19
  });
18
20
 
19
21
  test('Metrics: hasSubscribers returns false with no adapters', () => {