web_plsql 1.2.0 → 1.3.1
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/README.md +103 -8
- package/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/frontend/assets/main-C8GKnEhz.js +147 -0
- package/dist/frontend/assets/main-C8GKnEhz.js.br +0 -0
- package/dist/frontend/assets/main-C8GKnEhz.js.gz +0 -0
- package/dist/frontend/assets/main-bU4x_yEW.css +1 -0
- package/dist/frontend/assets/main-bU4x_yEW.css.br +0 -0
- package/dist/frontend/assets/main-bU4x_yEW.css.gz +0 -0
- package/{src/admin → dist/frontend}/index.html +12 -25
- package/dist/frontend/index.html.br +0 -0
- package/dist/frontend/index.html.gz +0 -0
- package/dist/index.d.mts +646 -0
- package/dist/index.mjs +3559 -0
- package/dist/index.mjs.map +1 -0
- package/dist/oracledb-mock-Dn8aHtd7.mjs +68 -0
- package/dist/oracledb-mock-Dn8aHtd7.mjs.map +1 -0
- package/examples/config-apex.js +1 -1
- package/examples/config-docker.js +1 -2
- package/package.json +48 -32
- package/examples/config-native.js +0 -68
- package/src/admin/client/charts.ts +0 -598
- package/src/admin/client/main.js +0 -3
- package/src/admin/client/tailwind.css +0 -41
- package/src/admin/js/api.ts +0 -170
- package/src/admin/js/app.ts +0 -614
- package/src/admin/js/eslint.config.js +0 -74
- package/src/admin/js/schemas.ts +0 -215
- package/src/admin/js/templates/config.ts +0 -147
- package/src/admin/js/templates/errorRow.ts +0 -21
- package/src/admin/js/templates/index.ts +0 -4
- package/src/admin/js/templates/poolCard.ts +0 -61
- package/src/admin/js/templates/traceRow.ts +0 -24
- package/src/admin/js/tsconfig.json +0 -24
- package/src/admin/js/types.ts +0 -336
- package/src/admin/js/ui/components.ts +0 -44
- package/src/admin/js/ui/table.ts +0 -173
- package/src/admin/js/ui/theme.ts +0 -93
- package/src/admin/js/ui/views.ts +0 -427
- package/src/admin/js/util/format.ts +0 -46
- package/src/admin/js/util/metrics.ts +0 -24
- package/src/admin/lib/chart.bundle.css +0 -1
- package/src/admin/lib/chart.bundle.js +0 -146
- package/src/admin/style.css +0 -1437
- package/src/bin/load-test.js +0 -202
- package/src/handler/handlerAdmin.js +0 -293
- package/src/handler/handlerLogger.js +0 -21
- package/src/handler/handlerUpload.js +0 -26
- package/src/handler/plsql/cgi.js +0 -131
- package/src/handler/plsql/errorPage.js +0 -113
- package/src/handler/plsql/handlerPlSql.js +0 -90
- package/src/handler/plsql/owaPageStream.js +0 -93
- package/src/handler/plsql/parsePage.js +0 -213
- package/src/handler/plsql/procedure.js +0 -426
- package/src/handler/plsql/procedureError.js +0 -40
- package/src/handler/plsql/procedureNamed.js +0 -282
- package/src/handler/plsql/procedureSanitize.js +0 -286
- package/src/handler/plsql/procedureVariable.js +0 -56
- package/src/handler/plsql/request.js +0 -124
- package/src/handler/plsql/requestError.js +0 -23
- package/src/handler/plsql/sendResponse.js +0 -174
- package/src/handler/plsql/stream.js +0 -28
- package/src/handler/plsql/upload.js +0 -109
- package/src/index.js +0 -19
- package/src/server/adminContext.js +0 -23
- package/src/server/config.js +0 -57
- package/src/server/connections.js +0 -40
- package/src/server/server.js +0 -304
- package/src/types.js +0 -150
- package/src/util/cache.js +0 -123
- package/src/util/errorToString.js +0 -24
- package/src/util/file.js +0 -91
- package/src/util/html.js +0 -53
- package/src/util/jsonLogger.js +0 -47
- package/src/util/oracle.js +0 -80
- package/src/util/shutdown.js +0 -44
- package/src/util/statsManager.js +0 -368
- package/src/util/trace.js +0 -326
- package/src/util/traceManager.js +0 -68
- package/src/util/type.js +0 -6
- package/src/util/util.js +0 -66
- package/src/version.js +0 -5
- package/types/admin/js/schemas.d.ts +0 -384
- package/types/admin/js/types.d.ts +0 -312
- package/types/handler/handlerAdmin.d.ts +0 -79
- package/types/handler/handlerLogger.d.ts +0 -2
- package/types/handler/handlerUpload.d.ts +0 -7
- package/types/handler/plsql/cgi.d.ts +0 -4
- package/types/handler/plsql/errorPage.d.ts +0 -11
- package/types/handler/plsql/handlerPlSql.d.ts +0 -13
- package/types/handler/plsql/owaPageStream.d.ts +0 -28
- package/types/handler/plsql/parsePage.d.ts +0 -3
- package/types/handler/plsql/procedure.d.ts +0 -13
- package/types/handler/plsql/procedureError.d.ts +0 -23
- package/types/handler/plsql/procedureNamed.d.ts +0 -14
- package/types/handler/plsql/procedureSanitize.d.ts +0 -11
- package/types/handler/plsql/procedureVariable.d.ts +0 -10
- package/types/handler/plsql/request.d.ts +0 -9
- package/types/handler/plsql/requestError.d.ts +0 -8
- package/types/handler/plsql/sendResponse.d.ts +0 -6
- package/types/handler/plsql/upload.d.ts +0 -5
- package/types/index.d.ts +0 -10
- package/types/server/adminContext.d.ts +0 -17
- package/types/server/config.d.ts +0 -2
- package/types/server/server.d.ts +0 -57
- package/types/types.d.ts +0 -328
- package/types/util/cache.d.ts +0 -69
- package/types/util/errorToString.d.ts +0 -1
- package/types/util/file.d.ts +0 -6
- package/types/util/html.d.ts +0 -3
- package/types/util/jsonLogger.d.ts +0 -45
- package/types/util/oracle.d.ts +0 -5
- package/types/util/shutdown.d.ts +0 -2
- package/types/util/statsManager.d.ts +0 -395
- package/types/util/trace.d.ts +0 -22
- package/types/util/traceManager.d.ts +0 -35
- package/types/util/type.d.ts +0 -1
- package/types/util/util.d.ts +0 -3
- package/types/version.d.ts +0 -1
- /package/{src/admin/favicon.svg → dist/frontend/assets/favicon-mQAM4tVu.svg} +0 -0
package/src/util/trace.js
DELETED
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Trace utilities
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as rotatingFileStream from 'rotating-file-stream';
|
|
6
|
-
import express from 'express';
|
|
7
|
-
import util from 'node:util';
|
|
8
|
-
import oracledb from 'oracledb';
|
|
9
|
-
import {escapeHtml, convertAsciiToHtml} from './html.js';
|
|
10
|
-
import {errorToString} from './errorToString.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {import('express').Request} Request
|
|
14
|
-
* @typedef {import('../types.js').BindParameterConfig} BindParameterConfig
|
|
15
|
-
* @typedef {import('../types.js').environmentType} environmentType
|
|
16
|
-
* @typedef {{html: string; text: string}} outputType
|
|
17
|
-
* @typedef {{type: 'error' | 'warning' | 'trace'; message: string; timestamp?: Date | null; req?: Request | null; environment?: environmentType | null, sql?: string | null; bind?: BindParameterConfig | null}} messageType
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
const SEPARATOR_H1 = '='.repeat(100);
|
|
21
|
-
const SEPARATOR_H2 = '-'.repeat(30);
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Return a string representation of the value.
|
|
25
|
-
*
|
|
26
|
-
* @param {unknown} value - Any value.
|
|
27
|
-
* @param {number | null} depth - Specifies the number of times to recurse while formatting object.
|
|
28
|
-
* @returns {string} - The string representation.
|
|
29
|
-
*/
|
|
30
|
-
export const inspect = (value, depth = null) => {
|
|
31
|
-
try {
|
|
32
|
-
return util.inspect(value, {showHidden: false, depth, colors: false});
|
|
33
|
-
} catch (err) {
|
|
34
|
-
/* empty */
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
return JSON.stringify(value);
|
|
39
|
-
} catch (err) {
|
|
40
|
-
/* empty */
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return 'Unable to convert value to string';
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Return a tabular representation of the values.
|
|
48
|
-
*
|
|
49
|
-
* @param {string[]} head - The header values.
|
|
50
|
-
* @param {string[][]} body - The row values.
|
|
51
|
-
* @returns {outputType} - The output.
|
|
52
|
-
*/
|
|
53
|
-
export const toTable = (head, body) => {
|
|
54
|
-
if (head.length === 0) {
|
|
55
|
-
throw new Error('head cannot be empty');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Calculate column widths
|
|
59
|
-
const widths = head.map((h, i) => {
|
|
60
|
-
const bodyMax = Math.max(0, ...body.map((row) => (row[i] ?? '').length));
|
|
61
|
-
return Math.max(h.length, bodyMax);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Build text representation
|
|
65
|
-
/**
|
|
66
|
-
* @param {string} cell - The string
|
|
67
|
-
* @param {number} width - The width
|
|
68
|
-
* @returns {string} - The result
|
|
69
|
-
*/
|
|
70
|
-
const padCell = (cell, width) => cell.padEnd(width, ' ');
|
|
71
|
-
const textHeader = head.map((h, i) => padCell(h, widths[i] ?? 0)).join(' | ');
|
|
72
|
-
const textSeparator = widths.map((w) => '-'.repeat(w ?? 0)).join('-+-');
|
|
73
|
-
const textRows = body.map((row) => head.map((_, i) => padCell(row[i] ?? '', widths[i] ?? 0)).join(' | '));
|
|
74
|
-
const text = [textHeader, textSeparator, ...textRows].join('\n');
|
|
75
|
-
|
|
76
|
-
const htmlHead = head.map((h) => `<th>${escapeHtml(h)}</th>`).join('');
|
|
77
|
-
const htmlBody = body.map((row) => `<tr>${head.map((_, i) => `<td>${escapeHtml(row[i] ?? '')}</td>`).join('')}</tr>`).join('');
|
|
78
|
-
const html = `<table><thead><tr>${htmlHead}</tr></thead><tbody>${htmlBody}</tbody></table>`;
|
|
79
|
-
|
|
80
|
-
return {text, html};
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Log text to the console and to a file.
|
|
85
|
-
*
|
|
86
|
-
* @param {string} text - Text to log.
|
|
87
|
-
* @returns {void}
|
|
88
|
-
*/
|
|
89
|
-
export const logToFile = (text) => {
|
|
90
|
-
const fs = rotatingFileStream.createStream('trace.log', {
|
|
91
|
-
size: '10M', // rotate every 10 MegaBytes written
|
|
92
|
-
interval: '1d', // rotate daily
|
|
93
|
-
maxFiles: 10, // maximum number of rotated files to keep
|
|
94
|
-
compress: 'gzip', // compress rotated files
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
fs.write(text);
|
|
98
|
-
fs.end();
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Return a string representation of the request.
|
|
103
|
-
*
|
|
104
|
-
* @param {express.Request} req - express.Request.
|
|
105
|
-
* @param {boolean} simple - Set to false to see all public properties of the request.
|
|
106
|
-
* @returns {string} - The string representation.
|
|
107
|
-
*/
|
|
108
|
-
const inspectRequest = (req, simple = true) => {
|
|
109
|
-
/** @type {Record<string, unknown>} */
|
|
110
|
-
const requestData = {};
|
|
111
|
-
|
|
112
|
-
Object.keys(req)
|
|
113
|
-
.filter((prop) =>
|
|
114
|
-
simple ? ['originalUrl', 'params', 'query', 'url', 'method', 'body', 'files', 'secret', 'cookies'].includes(prop) : !prop.startsWith('_'),
|
|
115
|
-
)
|
|
116
|
-
.forEach((prop) => {
|
|
117
|
-
requestData[prop] = req[/** @type {keyof import('express').Request} */ (prop)];
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
return inspect(requestData);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Return a string representation of the bind parameter.
|
|
125
|
-
* @param {number | undefined} dir - The direction.
|
|
126
|
-
* @returns {string} The string.
|
|
127
|
-
*/
|
|
128
|
-
const dirToString = (dir) => {
|
|
129
|
-
switch (dir) {
|
|
130
|
-
case oracledb.BIND_IN:
|
|
131
|
-
return 'IN';
|
|
132
|
-
case oracledb.BIND_OUT:
|
|
133
|
-
return 'OUT';
|
|
134
|
-
case oracledb.BIND_INOUT:
|
|
135
|
-
return 'INOUT';
|
|
136
|
-
default:
|
|
137
|
-
return '';
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Return a string representation of the bind type.
|
|
143
|
-
* @param {oracledb.DbType | string | number | undefined} type - The type.
|
|
144
|
-
* @returns {string} The string.
|
|
145
|
-
*/
|
|
146
|
-
const bindTypeToString = (type) => {
|
|
147
|
-
if (typeof type === 'object' && 'name' in type) {
|
|
148
|
-
return type.name;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (typeof type === 'string') {
|
|
152
|
-
return type;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (typeof type === 'number') {
|
|
156
|
-
return type.toString();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return '';
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Return a string representation of the bind parameter.
|
|
164
|
-
* @param {outputType} output - The output.
|
|
165
|
-
* @param {BindParameterConfig} bind - The bind parameters.
|
|
166
|
-
* @returns {undefined}
|
|
167
|
-
*/
|
|
168
|
-
const inspectBindParameter = (output, bind) => {
|
|
169
|
-
const rows = Object.entries(bind);
|
|
170
|
-
|
|
171
|
-
if (rows.length === 0) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const body = rows.map(([id, row]) => {
|
|
176
|
-
const dir = dirToString(row.dir);
|
|
177
|
-
const maxArraySize = row.maxArraySize ? row.maxArraySize.toString() : '';
|
|
178
|
-
const maxSize = row.maxSize ? row.maxSize.toString() : '';
|
|
179
|
-
const bindType = bindTypeToString(row.type);
|
|
180
|
-
const value = inspect(row.val);
|
|
181
|
-
const valueType = typeof row.val;
|
|
182
|
-
|
|
183
|
-
return [id, dir, maxArraySize, maxSize, bindType, value, valueType];
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
const {html, text} = toTable(['id', 'dir', 'maxArraySize', 'maxSize', 'bind type', 'value', 'value type'], body);
|
|
187
|
-
|
|
188
|
-
output.html += html;
|
|
189
|
-
output.text += text;
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Add environment
|
|
194
|
-
* @param {outputType} output - The output.
|
|
195
|
-
* @param {environmentType} environment - The environment.
|
|
196
|
-
*/
|
|
197
|
-
const inspectEnvironment = (output, environment) => {
|
|
198
|
-
const rows = Object.entries(environment);
|
|
199
|
-
|
|
200
|
-
if (rows.length === 0) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const {html, text} = toTable(['key', 'value'], rows);
|
|
205
|
-
|
|
206
|
-
output.html += html;
|
|
207
|
-
output.text += text;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Get a block.
|
|
212
|
-
* @param {string} title - The name.
|
|
213
|
-
* @param {string} body - The name.
|
|
214
|
-
* @returns {string} - The text.
|
|
215
|
-
*/
|
|
216
|
-
export const getBlock = (title, body) => `\n${SEPARATOR_H2}${title.toUpperCase()}${SEPARATOR_H2}\n${body}`;
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Get line html
|
|
220
|
-
* @param {string} text - The text.
|
|
221
|
-
* @returns {string} - The line.
|
|
222
|
-
*/
|
|
223
|
-
const getLineHtml = (text) => `<p>${convertAsciiToHtml(text)}</p>`;
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Get line text
|
|
227
|
-
* @param {string} text - The text.
|
|
228
|
-
* @returns {string} - The line.
|
|
229
|
-
*/
|
|
230
|
-
const getLineText = (text) => `${text}\n`;
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Add line
|
|
234
|
-
* @param {outputType} output - The output.
|
|
235
|
-
* @param {string} text - The text to convert.
|
|
236
|
-
*/
|
|
237
|
-
const addLine = (output, text) => {
|
|
238
|
-
output.html += getLineHtml(text);
|
|
239
|
-
output.text += getLineText(text);
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Add header
|
|
244
|
-
* @param {outputType} output - The output.
|
|
245
|
-
* @param {string} text - The text to convert.
|
|
246
|
-
*/
|
|
247
|
-
const addHeader = (output, text) => {
|
|
248
|
-
output.html += `<h2>${text}</h2>`;
|
|
249
|
-
output.text += `\n${text}\n${'-'.repeat(text.length)}\n`;
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Add procedure
|
|
254
|
-
* @param {outputType} output - The output.
|
|
255
|
-
* @param {string} sql - The SQL to execute.
|
|
256
|
-
* @param {BindParameterConfig} bind - The bind parameters.
|
|
257
|
-
*/
|
|
258
|
-
const addProcedure = (output, sql, bind) => {
|
|
259
|
-
output.html += `${sql}<br><br>`;
|
|
260
|
-
output.text += `${sql}\n\n`;
|
|
261
|
-
|
|
262
|
-
try {
|
|
263
|
-
inspectBindParameter(output, bind);
|
|
264
|
-
} catch (err) {
|
|
265
|
-
addLine(output, `Unable to inspect bind parameter: ${errorToString(err)}`);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
output.html += `<br>`;
|
|
269
|
-
output.text += `\n`;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Get a formatted message.
|
|
274
|
-
* @param {messageType} para - The req object represents the HTTP request.
|
|
275
|
-
* @returns {outputType} - The output.
|
|
276
|
-
*/
|
|
277
|
-
export const getFormattedMessage = (para) => {
|
|
278
|
-
const timestamp = para.timestamp ?? new Date();
|
|
279
|
-
|
|
280
|
-
// header
|
|
281
|
-
const url = typeof para.req?.originalUrl === 'string' && para.req.originalUrl.length > 0 ? ` on ${para.req.originalUrl}` : '';
|
|
282
|
-
const type = (para.type ?? 'trace').toUpperCase();
|
|
283
|
-
const header = `${type} at ${timestamp.toUTCString()}${url}`;
|
|
284
|
-
const output = {
|
|
285
|
-
html: `<h1>${header}</h1>`,
|
|
286
|
-
text: `\n\n${SEPARATOR_H1}\n== ${header}\n${SEPARATOR_H1}\n`,
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
// error
|
|
290
|
-
addHeader(output, 'ERROR');
|
|
291
|
-
addLine(output, para.message);
|
|
292
|
-
|
|
293
|
-
// request
|
|
294
|
-
if (para.req) {
|
|
295
|
-
addHeader(output, 'REQUEST');
|
|
296
|
-
addLine(output, inspectRequest(para.req));
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// parameters
|
|
300
|
-
if (para.sql && para.bind) {
|
|
301
|
-
addHeader(output, 'PROCEDURE');
|
|
302
|
-
addProcedure(output, para.sql, para.bind);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// environment
|
|
306
|
-
if (para.environment) {
|
|
307
|
-
addHeader(output, 'ENVIRONMENT');
|
|
308
|
-
inspectEnvironment(output, para.environment);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return output;
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Log a warning message.
|
|
316
|
-
* @param {messageType} para - The req object represents the HTTP request.
|
|
317
|
-
*/
|
|
318
|
-
export const warningMessage = (para) => {
|
|
319
|
-
const {text} = getFormattedMessage(para);
|
|
320
|
-
|
|
321
|
-
// trace to file
|
|
322
|
-
logToFile(text);
|
|
323
|
-
|
|
324
|
-
// console
|
|
325
|
-
console.warn(text);
|
|
326
|
-
};
|
package/src/util/traceManager.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {import('../admin/js/types.js').TraceEntry} TraceEntry
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
class TraceManager {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.enabled = false;
|
|
11
|
-
this.filename = 'trace.json.log';
|
|
12
|
-
this.maxEntries = 1000;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Toggle tracing
|
|
17
|
-
* @param {boolean} enabled - New state
|
|
18
|
-
*/
|
|
19
|
-
setEnabled(enabled) {
|
|
20
|
-
this.enabled = enabled;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Is tracing enabled?
|
|
25
|
-
* @returns {boolean} - The state
|
|
26
|
-
*/
|
|
27
|
-
isEnabled() {
|
|
28
|
-
return this.enabled;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Add a trace entry
|
|
33
|
-
* @param {object} entry - The trace entry
|
|
34
|
-
*/
|
|
35
|
-
addTrace(entry) {
|
|
36
|
-
if (!this.enabled) return;
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const line = JSON.stringify(entry) + '\n';
|
|
40
|
-
fs.appendFileSync(this.filename, line);
|
|
41
|
-
} catch (err) {
|
|
42
|
-
console.error('TraceManager: error writing trace', err);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Clear all traces
|
|
48
|
-
*/
|
|
49
|
-
clear() {
|
|
50
|
-
try {
|
|
51
|
-
if (fs.existsSync(this.filename)) {
|
|
52
|
-
fs.truncateSync(this.filename, 0);
|
|
53
|
-
}
|
|
54
|
-
} catch (err) {
|
|
55
|
-
console.error('TraceManager: error clearing traces', err);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Get the full path to the trace file
|
|
61
|
-
* @returns {string} - The path
|
|
62
|
-
*/
|
|
63
|
-
getFilePath() {
|
|
64
|
-
return path.resolve(this.filename);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const traceManager = new TraceManager();
|
package/src/util/type.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Is the given value a string or an array of strings
|
|
3
|
-
* @param {unknown} value - The value to check.
|
|
4
|
-
* @returns {value is string | string[]} - True if the value is a string or an array of strings
|
|
5
|
-
*/
|
|
6
|
-
export const isStringOrArrayOfString = (value) => typeof value === 'string' || (Array.isArray(value) && value.every((element) => typeof element === 'string'));
|
package/src/util/util.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get duration as human readable string.
|
|
3
|
-
* @param {number} duration - Milliseconds.
|
|
4
|
-
* @returns {string} String.
|
|
5
|
-
*/
|
|
6
|
-
export const humanDuration = (duration) => {
|
|
7
|
-
if (!Number.isFinite(duration)) return 'invalid';
|
|
8
|
-
|
|
9
|
-
const ms = Math.floor(duration % 1000);
|
|
10
|
-
const s = Math.floor((duration / 1000) % 60);
|
|
11
|
-
const m = Math.floor((duration / (1000 * 60)) % 60);
|
|
12
|
-
const h = Math.floor((duration / (1000 * 60 * 60)) % 24);
|
|
13
|
-
const d = Math.floor(duration / (1000 * 60 * 60 * 24));
|
|
14
|
-
|
|
15
|
-
const parts = [];
|
|
16
|
-
if (d) parts.push(`${d}d`);
|
|
17
|
-
if (h) parts.push(`${h}h`);
|
|
18
|
-
if (m) parts.push(`${m}m`);
|
|
19
|
-
if (s) parts.push(`${s}s`);
|
|
20
|
-
if (ms || !parts.length) parts.push(`${ms}ms`);
|
|
21
|
-
|
|
22
|
-
return parts.join(' ');
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Convert a string to a number
|
|
27
|
-
*
|
|
28
|
-
* @param {unknown} value - The string to convert
|
|
29
|
-
* @returns {number | null} The number or null if the string could not be converted
|
|
30
|
-
*/
|
|
31
|
-
export const stringToNumber = (value) => {
|
|
32
|
-
// is the value already of type number?
|
|
33
|
-
if (typeof value === 'number') {
|
|
34
|
-
return !Number.isNaN(value) && Number.isFinite(value) ? value : null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Test for invalid characters
|
|
38
|
-
if (typeof value !== 'string' || !/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:E[+-]?\d+)?$/i.test(value)) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Convert value to a number
|
|
43
|
-
const num = Number(value);
|
|
44
|
-
return Number.isNaN(num) ? null : num;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Convert a string to a integer
|
|
49
|
-
*
|
|
50
|
-
* @param {unknown} value - The value to convert
|
|
51
|
-
* @returns {number | null} The integer or null if the string could not be converted
|
|
52
|
-
*/
|
|
53
|
-
export const stringToInteger = (value) => {
|
|
54
|
-
// is the value already a "real" integer, we just return the value
|
|
55
|
-
if (typeof value === 'number' && Number.isInteger(value)) {
|
|
56
|
-
return value;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// try to convert value to a number
|
|
60
|
-
const num = stringToNumber(value);
|
|
61
|
-
if (num === null || !Number.isInteger(num)) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return num;
|
|
66
|
-
};
|