@appium/support 7.0.4 → 7.0.6
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/build/lib/console.d.ts +42 -88
- package/build/lib/console.d.ts.map +1 -1
- package/build/lib/console.js +25 -85
- package/build/lib/console.js.map +1 -1
- package/build/lib/doctor.d.ts +6 -18
- package/build/lib/doctor.d.ts.map +1 -1
- package/build/lib/doctor.js +0 -15
- package/build/lib/doctor.js.map +1 -1
- package/build/lib/env.d.ts +14 -20
- package/build/lib/env.d.ts.map +1 -1
- package/build/lib/env.js +24 -61
- package/build/lib/env.js.map +1 -1
- package/build/lib/fs.d.ts +109 -148
- package/build/lib/fs.d.ts.map +1 -1
- package/build/lib/fs.js +130 -230
- package/build/lib/fs.js.map +1 -1
- package/build/lib/image-util.d.ts +7 -6
- package/build/lib/image-util.d.ts.map +1 -1
- package/build/lib/image-util.js +9 -6
- package/build/lib/image-util.js.map +1 -1
- package/build/lib/index.d.ts +19 -17
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/logger.d.ts +1 -1
- package/build/lib/logger.d.ts.map +1 -1
- package/build/lib/logger.js +1 -1
- package/build/lib/logger.js.map +1 -1
- package/build/lib/logging.d.ts +7 -15
- package/build/lib/logging.d.ts.map +1 -1
- package/build/lib/logging.js +36 -62
- package/build/lib/logging.js.map +1 -1
- package/build/lib/mjpeg.d.ts +19 -56
- package/build/lib/mjpeg.d.ts.map +1 -1
- package/build/lib/mjpeg.js +55 -78
- package/build/lib/mjpeg.js.map +1 -1
- package/build/lib/mkdirp.d.ts +4 -1
- package/build/lib/mkdirp.d.ts.map +1 -1
- package/build/lib/mkdirp.js +1 -2
- package/build/lib/mkdirp.js.map +1 -1
- package/build/lib/net.d.ts +52 -90
- package/build/lib/net.d.ts.map +1 -1
- package/build/lib/net.js +104 -193
- package/build/lib/net.js.map +1 -1
- package/build/lib/node.d.ts +16 -17
- package/build/lib/node.d.ts.map +1 -1
- package/build/lib/node.js +115 -120
- package/build/lib/node.js.map +1 -1
- package/build/lib/npm.d.ts +65 -86
- package/build/lib/npm.d.ts.map +1 -1
- package/build/lib/npm.js +64 -122
- package/build/lib/npm.js.map +1 -1
- package/build/lib/plist.d.ts +36 -29
- package/build/lib/plist.d.ts.map +1 -1
- package/build/lib/plist.js +62 -59
- package/build/lib/plist.js.map +1 -1
- package/build/lib/process.d.ts +19 -2
- package/build/lib/process.d.ts.map +1 -1
- package/build/lib/process.js +24 -7
- package/build/lib/process.js.map +1 -1
- package/build/lib/system.d.ts +41 -6
- package/build/lib/system.d.ts.map +1 -1
- package/build/lib/system.js +49 -14
- package/build/lib/system.js.map +1 -1
- package/build/lib/tempdir.d.ts +26 -49
- package/build/lib/tempdir.d.ts.map +1 -1
- package/build/lib/tempdir.js +46 -78
- package/build/lib/tempdir.js.map +1 -1
- package/build/lib/timing.d.ts +28 -22
- package/build/lib/timing.d.ts.map +1 -1
- package/build/lib/timing.js +16 -17
- package/build/lib/timing.js.map +1 -1
- package/build/lib/util.d.ts +164 -181
- package/build/lib/util.d.ts.map +1 -1
- package/build/lib/util.js +198 -253
- package/build/lib/util.js.map +1 -1
- package/build/lib/zip.d.ts +81 -139
- package/build/lib/zip.d.ts.map +1 -1
- package/build/lib/zip.js +235 -283
- package/build/lib/zip.js.map +1 -1
- package/lib/console.ts +139 -0
- package/lib/{doctor.js → doctor.ts} +6 -20
- package/lib/{env.js → env.ts} +34 -62
- package/lib/fs.ts +453 -0
- package/lib/image-util.ts +40 -0
- package/lib/index.ts +1 -0
- package/lib/{logger.js → logger.ts} +1 -1
- package/lib/logging.ts +157 -0
- package/lib/mjpeg.ts +186 -0
- package/lib/{mkdirp.js → mkdirp.ts} +2 -2
- package/lib/net.ts +305 -0
- package/lib/{node.js → node.ts} +136 -135
- package/lib/npm.ts +291 -0
- package/lib/plist.ts +187 -0
- package/lib/process.ts +62 -0
- package/lib/system.ts +95 -0
- package/lib/tempdir.ts +115 -0
- package/lib/{timing.js → timing.ts} +28 -33
- package/lib/util.ts +561 -0
- package/lib/{zip.js → zip.ts} +344 -299
- package/package.json +24 -26
- package/tsconfig.json +3 -5
- package/index.js +0 -1
- package/lib/console.js +0 -173
- package/lib/fs.js +0 -496
- package/lib/image-util.js +0 -32
- package/lib/logging.js +0 -145
- package/lib/mjpeg.js +0 -207
- package/lib/net.js +0 -336
- package/lib/npm.js +0 -310
- package/lib/plist.js +0 -182
- package/lib/process.js +0 -46
- package/lib/system.js +0 -48
- package/lib/tempdir.js +0 -131
- package/lib/util.js +0 -585
package/build/lib/tempdir.js
CHANGED
|
@@ -3,103 +3,86 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.openDir = void 0;
|
|
7
|
-
exports.open = open;
|
|
6
|
+
exports.staticDir = exports.openDir = void 0;
|
|
8
7
|
exports.path = path;
|
|
9
|
-
exports.
|
|
8
|
+
exports.open = open;
|
|
10
9
|
/* This library is originated from temp.js at http://github.com/bruce/node-temp */
|
|
11
10
|
const fs_1 = require("./fs");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
11
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
12
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
14
|
+
const node_fs_1 = require("node:fs");
|
|
15
15
|
const logger_1 = __importDefault(require("./logger"));
|
|
16
|
-
const RDWR_EXCL =
|
|
16
|
+
const RDWR_EXCL = node_fs_1.constants.O_CREAT | node_fs_1.constants.O_TRUNC | node_fs_1.constants.O_RDWR | node_fs_1.constants.O_EXCL;
|
|
17
17
|
/**
|
|
18
|
-
* Generate a temporary directory
|
|
19
|
-
* e.g.
|
|
20
|
-
* - No `process.env.APPIUM_TMP_DIR`: `/var/folders/34/2222sh8n27d6rcp7jqlkw8km0000gn/T/xxxxxxxx.yyyy`
|
|
21
|
-
* - With `process.env.APPIUM_TMP_DIR = '/path/to/root'`: `/path/to/root/xxxxxxxx.yyyy`
|
|
18
|
+
* Generate a temporary directory with arbitrary prefix/suffix for the directory name.
|
|
22
19
|
*
|
|
23
|
-
* @
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const now = new Date();
|
|
27
|
-
const filePath = path_1.default.join(process.env.APPIUM_TMP_DIR || os_1.default.tmpdir(), [
|
|
28
|
-
now.getFullYear(),
|
|
29
|
-
now.getMonth(),
|
|
30
|
-
now.getDate(),
|
|
31
|
-
'-',
|
|
32
|
-
process.pid,
|
|
33
|
-
'-',
|
|
34
|
-
(Math.random() * 0x100000000 + 1).toString(36),
|
|
35
|
-
].join(''));
|
|
36
|
-
// creates a temp directory using the date and a random string
|
|
37
|
-
await fs_1.fs.mkdir(filePath, { recursive: true });
|
|
38
|
-
return filePath;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @typedef Affixes
|
|
42
|
-
* @property {string} [prefix] - prefix of the temp directory name
|
|
43
|
-
* @property {string} [suffix] - suffix of the temp directory name
|
|
44
|
-
*/
|
|
45
|
-
/**
|
|
46
|
-
* Generate a temporary directory in os.tempdir() or process.env.APPIUM_TMP_DIR
|
|
47
|
-
* with arbitrary prefix/suffix for the directory name.
|
|
48
|
-
*
|
|
49
|
-
* @param {string|Affixes} rawAffixes
|
|
50
|
-
* @param {string} [defaultPrefix]
|
|
51
|
-
* @returns {Promise<string>} A path to the temporary directory with rawAffixes and defaultPrefix
|
|
20
|
+
* @param rawAffixes - Prefix string, or object with prefix/suffix, or omitted.
|
|
21
|
+
* @param defaultPrefix - Default prefix when rawAffixes is omitted.
|
|
22
|
+
* @returns A path to the temporary directory.
|
|
52
23
|
*/
|
|
53
24
|
async function path(rawAffixes, defaultPrefix) {
|
|
54
25
|
const affixes = parseAffixes(rawAffixes, defaultPrefix);
|
|
55
|
-
const name = `${affixes.prefix
|
|
26
|
+
const name = `${affixes.prefix ?? ''}${affixes.suffix ?? ''}`;
|
|
56
27
|
const tempDirectory = await tempDir();
|
|
57
|
-
return
|
|
28
|
+
return node_path_1.default.join(tempDirectory, name);
|
|
58
29
|
}
|
|
59
30
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @property {string} path - The path to file
|
|
62
|
-
* @property {number} fd - The file descriptor opened
|
|
63
|
-
*/
|
|
64
|
-
/**
|
|
65
|
-
* Generate a temporary directory in os.tempdir() or process.env.APPIUM_TMP_DIR
|
|
66
|
-
* with arbitrary prefix/suffix for the directory name and return it as open.
|
|
31
|
+
* Generate a temp file path with prefix/suffix, open the file, and return path and fd.
|
|
67
32
|
*
|
|
68
|
-
* @param
|
|
69
|
-
* @returns
|
|
33
|
+
* @param affixes - Prefix/suffix for the file name.
|
|
34
|
+
* @returns The opened file path and descriptor.
|
|
70
35
|
*/
|
|
71
36
|
async function open(affixes) {
|
|
72
37
|
const filePath = await path(affixes, 'f-');
|
|
73
38
|
try {
|
|
74
|
-
|
|
75
|
-
// opens the file in mode 384
|
|
39
|
+
const fd = await fs_1.fs.open(filePath, RDWR_EXCL, 0o600);
|
|
76
40
|
return { path: filePath, fd };
|
|
77
41
|
}
|
|
78
42
|
catch (err) {
|
|
79
43
|
throw logger_1.default.errorWithException(err);
|
|
80
44
|
}
|
|
81
45
|
}
|
|
46
|
+
/** Returns a new path to a temporary directory (alias for the tempDir implementation). */
|
|
47
|
+
exports.openDir = tempDir;
|
|
82
48
|
/**
|
|
49
|
+
* Returns a path to a temporary directory which is reused for the life of the process.
|
|
83
50
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* @param {string|Affixes} rawAffixes
|
|
87
|
-
* @param {string} [defaultPrefix]
|
|
88
|
-
* @returns {Affixes}
|
|
51
|
+
* @returns The same temp directory path on every call.
|
|
89
52
|
*/
|
|
53
|
+
exports.staticDir = lodash_1.default.memoize(async function staticDir() {
|
|
54
|
+
return tempDir();
|
|
55
|
+
});
|
|
56
|
+
// #region Private
|
|
57
|
+
/**
|
|
58
|
+
* Generate a temporary directory in os.tmpdir() or process.env.APPIUM_TMP_DIR.
|
|
59
|
+
*/
|
|
60
|
+
async function tempDir() {
|
|
61
|
+
const now = new Date();
|
|
62
|
+
const filePath = node_path_1.default.join(process.env.APPIUM_TMP_DIR || node_os_1.default.tmpdir(), [
|
|
63
|
+
now.getFullYear(),
|
|
64
|
+
now.getMonth(),
|
|
65
|
+
now.getDate(),
|
|
66
|
+
'-',
|
|
67
|
+
process.pid,
|
|
68
|
+
'-',
|
|
69
|
+
(Math.random() * 0x100000000 + 1).toString(36),
|
|
70
|
+
].join(''));
|
|
71
|
+
await fs_1.fs.mkdir(filePath, { recursive: true });
|
|
72
|
+
return filePath;
|
|
73
|
+
}
|
|
90
74
|
function parseAffixes(rawAffixes, defaultPrefix) {
|
|
91
|
-
/** @type {Affixes} */
|
|
92
75
|
let affixes = {};
|
|
93
|
-
if (rawAffixes) {
|
|
76
|
+
if (rawAffixes !== undefined && rawAffixes !== null) {
|
|
94
77
|
switch (typeof rawAffixes) {
|
|
95
78
|
case 'string':
|
|
96
|
-
affixes
|
|
79
|
+
affixes = { prefix: rawAffixes };
|
|
97
80
|
break;
|
|
98
81
|
case 'object':
|
|
99
82
|
affixes = rawAffixes;
|
|
100
83
|
break;
|
|
101
84
|
default:
|
|
102
|
-
throw new Error(`Unknown affix declaration: ${
|
|
85
|
+
throw new Error(`Unknown affix declaration: ${String(rawAffixes)}`);
|
|
103
86
|
}
|
|
104
87
|
}
|
|
105
88
|
else {
|
|
@@ -107,20 +90,5 @@ function parseAffixes(rawAffixes, defaultPrefix) {
|
|
|
107
90
|
}
|
|
108
91
|
return affixes;
|
|
109
92
|
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Returns a new path to a temporary directory
|
|
113
|
-
*
|
|
114
|
-
* @returns {string} A new tempDir() if tempRootDirectory is not provided
|
|
115
|
-
*/
|
|
116
|
-
const openDir = tempDir;
|
|
117
|
-
exports.openDir = openDir;
|
|
118
|
-
/**
|
|
119
|
-
* Returns a path to a temporary directory which is defined as static in the same process
|
|
120
|
-
*
|
|
121
|
-
* @returns {Promise<string>} A temp directory path which is defined as static in the same process
|
|
122
|
-
*/
|
|
123
|
-
async function staticDir() {
|
|
124
|
-
return _static;
|
|
125
|
-
}
|
|
93
|
+
// #endregion
|
|
126
94
|
//# sourceMappingURL=tempdir.js.map
|
package/build/lib/tempdir.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tempdir.js","sourceRoot":"","sources":["../../lib/tempdir.
|
|
1
|
+
{"version":3,"file":"tempdir.js","sourceRoot":"","sources":["../../lib/tempdir.ts"],"names":[],"mappings":";;;;;;AA6BA,oBAQC;AAQD,oBAQC;AArDD,kFAAkF;AAClF,6BAAwB;AACxB,sDAAyB;AACzB,0DAAiC;AACjC,oDAAuB;AACvB,qCAAkC;AAClC,sDAA2B;AAE3B,MAAM,SAAS,GAAG,mBAAS,CAAC,OAAO,GAAG,mBAAS,CAAC,OAAO,GAAG,mBAAS,CAAC,MAAM,GAAG,mBAAS,CAAC,MAAM,CAAC;AAc9F;;;;;;GAMG;AACI,KAAK,UAAU,IAAI,CACxB,UAA6B,EAC7B,aAAsB;IAEtB,MAAM,OAAO,GAAG,YAAY,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;IAC9D,MAAM,aAAa,GAAG,MAAM,OAAO,EAAE,CAAC;IACtC,OAAO,mBAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,IAAI,CAAC,OAAgB;IACzC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC3C,IAAI,CA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AAI,EAAE,CAAC;QACpD,QAAQ,OAAO,UAAU,EAAE,CAAC;YAC1B,KAAK,QAAQ;gBACX,OAAO,GAAG,EAAC,MAAM,EAAE,UAAU,EAAC,CAAC;gBAC/B,MAAM;YACR,KAAK,QAAQ;gBACX,OAAO,GAAG,UAAU,CAAC;gBACrB,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,GAAG,aAAa,CAAC;IACjC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,aAAa"}
|
package/build/lib/timing.d.ts
CHANGED
|
@@ -1,28 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
_startTime: bigint | [number, number] | null;
|
|
4
|
-
get startTime(): bigint | [number, number] | null;
|
|
5
|
-
/**
|
|
6
|
-
* Start the timer
|
|
7
|
-
*
|
|
8
|
-
* @return {Timer} The current instance, for chaining
|
|
9
|
-
*/
|
|
10
|
-
start(): Timer;
|
|
11
|
-
/**
|
|
12
|
-
* Get the duration since the timer was started
|
|
13
|
-
*
|
|
14
|
-
* @return {Duration} the duration
|
|
15
|
-
*/
|
|
16
|
-
getDuration(): Duration;
|
|
17
|
-
toString(): string;
|
|
18
|
-
}
|
|
1
|
+
/** High-resolution start time: tuple from process.hrtime() or bigint from process.hrtime.bigint() */
|
|
2
|
+
type HrTime = [number, number] | bigint;
|
|
19
3
|
/**
|
|
20
4
|
* Class representing a duration, encapsulating the number and units.
|
|
21
5
|
*/
|
|
22
|
-
export class Duration {
|
|
23
|
-
|
|
24
|
-
_nanos:
|
|
25
|
-
get nanos():
|
|
6
|
+
export declare class Duration {
|
|
7
|
+
private _nanos;
|
|
8
|
+
constructor(_nanos: number);
|
|
9
|
+
get nanos(): number;
|
|
26
10
|
/**
|
|
27
11
|
* Get the duration as nanoseconds
|
|
28
12
|
*
|
|
@@ -43,4 +27,26 @@ export class Duration {
|
|
|
43
27
|
get asSeconds(): number;
|
|
44
28
|
toString(): string;
|
|
45
29
|
}
|
|
30
|
+
export declare class Timer {
|
|
31
|
+
private _startTime;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a timer
|
|
34
|
+
*/
|
|
35
|
+
constructor(_startTime?: HrTime | null);
|
|
36
|
+
get startTime(): HrTime | null;
|
|
37
|
+
/**
|
|
38
|
+
* Start the timer
|
|
39
|
+
*
|
|
40
|
+
* @return {Timer} The current instance, for chaining
|
|
41
|
+
*/
|
|
42
|
+
start(): this;
|
|
43
|
+
/**
|
|
44
|
+
* Get the duration since the timer was started
|
|
45
|
+
*
|
|
46
|
+
* @return {Duration} the duration
|
|
47
|
+
*/
|
|
48
|
+
getDuration(): Duration;
|
|
49
|
+
toString(): string;
|
|
50
|
+
}
|
|
51
|
+
export { Timer as default };
|
|
46
52
|
//# sourceMappingURL=timing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../../lib/timing.
|
|
1
|
+
{"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../../lib/timing.ts"],"names":[],"mappings":"AAKA,qGAAqG;AACrG,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;AAExC;;GAEG;AACH,qBAAa,QAAQ;IACP,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;OAIG;IACH,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;;;OAIG;IACH,IAAI,cAAc,IAAI,MAAM,CAE3B;IAED;;;;OAIG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,QAAQ,IAAI,MAAM;CAInB;AAED,qBAAa,KAAK;IAIJ,OAAO,CAAC,UAAU;IAH9B;;OAEG;gBACiB,UAAU,GAAE,MAAM,GAAG,IAAW;IAEpD,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAE7B;IAED;;;;OAIG;IACH,KAAK,IAAI,IAAI;IAQb;;;;OAIG;IACH,WAAW,IAAI,QAAQ;IAsBvB,QAAQ,IAAI,MAAM;CAOnB;AAED,OAAO,EAAC,KAAK,IAAI,OAAO,EAAC,CAAC"}
|
package/build/lib/timing.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.default = exports.Timer = exports.Duration = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const NS_PER_S = 1e9;
|
|
9
9
|
const NS_PER_MS = 1e6;
|
|
@@ -11,8 +11,9 @@ const NS_PER_MS = 1e6;
|
|
|
11
11
|
* Class representing a duration, encapsulating the number and units.
|
|
12
12
|
*/
|
|
13
13
|
class Duration {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
_nanos;
|
|
15
|
+
constructor(_nanos) {
|
|
16
|
+
this._nanos = _nanos;
|
|
16
17
|
}
|
|
17
18
|
get nanos() {
|
|
18
19
|
return this._nanos;
|
|
@@ -48,11 +49,12 @@ class Duration {
|
|
|
48
49
|
}
|
|
49
50
|
exports.Duration = Duration;
|
|
50
51
|
class Timer {
|
|
52
|
+
_startTime;
|
|
51
53
|
/**
|
|
52
54
|
* Creates a timer
|
|
53
55
|
*/
|
|
54
|
-
constructor() {
|
|
55
|
-
this._startTime =
|
|
56
|
+
constructor(_startTime = null) {
|
|
57
|
+
this._startTime = _startTime;
|
|
56
58
|
}
|
|
57
59
|
get startTime() {
|
|
58
60
|
return this._startTime;
|
|
@@ -63,13 +65,10 @@ class Timer {
|
|
|
63
65
|
* @return {Timer} The current instance, for chaining
|
|
64
66
|
*/
|
|
65
67
|
start() {
|
|
66
|
-
if (!lodash_1.default.isNull(this.
|
|
68
|
+
if (!lodash_1.default.isNull(this._startTime)) {
|
|
67
69
|
throw new Error('Timer has already been started.');
|
|
68
70
|
}
|
|
69
|
-
|
|
70
|
-
this._startTime = lodash_1.default.isFunction(process.hrtime.bigint)
|
|
71
|
-
? process.hrtime.bigint()
|
|
72
|
-
: process.hrtime();
|
|
71
|
+
this._startTime = process.hrtime.bigint();
|
|
73
72
|
return this;
|
|
74
73
|
}
|
|
75
74
|
/**
|
|
@@ -78,23 +77,23 @@ class Timer {
|
|
|
78
77
|
* @return {Duration} the duration
|
|
79
78
|
*/
|
|
80
79
|
getDuration() {
|
|
81
|
-
if (lodash_1.default.isNull(this.
|
|
82
|
-
throw new Error(
|
|
80
|
+
if (lodash_1.default.isNull(this._startTime)) {
|
|
81
|
+
throw new Error('Unable to get duration. Timer was not started');
|
|
83
82
|
}
|
|
84
83
|
let nanoDuration;
|
|
85
|
-
if (lodash_1.default.isArray(this.
|
|
84
|
+
if (lodash_1.default.isArray(this._startTime)) {
|
|
86
85
|
// startTime was created using process.hrtime()
|
|
87
|
-
const [seconds, nanos] = process.hrtime(this.
|
|
86
|
+
const [seconds, nanos] = process.hrtime(this._startTime);
|
|
88
87
|
nanoDuration = seconds * NS_PER_S + nanos;
|
|
89
88
|
}
|
|
90
|
-
else if (typeof this.
|
|
89
|
+
else if (typeof this._startTime === 'bigint') {
|
|
91
90
|
// startTime was created using process.hrtime.bigint()
|
|
92
91
|
const endTime = process.hrtime.bigint();
|
|
93
92
|
// get the difference, and convert to number
|
|
94
|
-
nanoDuration = Number(endTime - this.
|
|
93
|
+
nanoDuration = Number(endTime - this._startTime);
|
|
95
94
|
}
|
|
96
95
|
else {
|
|
97
|
-
throw new Error(`Unable to get duration. Start time '${this.
|
|
96
|
+
throw new Error(`Unable to get duration. Start time '${this._startTime}' cannot be parsed`);
|
|
98
97
|
}
|
|
99
98
|
return new Duration(nanoDuration);
|
|
100
99
|
}
|
package/build/lib/timing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timing.js","sourceRoot":"","sources":["../../lib/timing.
|
|
1
|
+
{"version":3,"file":"timing.js","sourceRoot":"","sources":["../../lib/timing.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AAEvB,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,SAAS,GAAG,GAAG,CAAC;AAKtB;;GAEG;AACH,MAAa,QAAQ;IACC;IAApB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAEtC,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;IAC/B,CAAC;IAED,QAAQ;QACN,mCAAmC;QACnC,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;CACF;AAtCD,4BAsCC;AAED,MAAa,KAAK;IAII;IAHpB;;OAEG;IACH,YAAoB,aAA4B,IAAI;QAAhC,eAAU,GAAV,UAAU,CAAsB;IAAG,CAAC;IAExD,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,IAAI,CAAC,gBAAC,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAC1C,OA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