@darthcav/ts-utils 1.0.0 → 1.0.2
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 +20 -10
- package/dist/core/guards.d.ts.map +1 -1
- package/dist/core/guards.js +4 -10
- package/dist/core/guards.js.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/millisecondsToString.d.ts.map +1 -1
- package/dist/core/millisecondsToString.js +6 -10
- package/dist/core/millisecondsToString.js.map +1 -1
- package/dist/node/delays.d.ts +11 -0
- package/dist/node/delays.d.ts.map +1 -0
- package/dist/node/delays.js +14 -0
- package/dist/node/delays.js.map +1 -0
- package/dist/node/main.d.ts +5 -3
- package/dist/node/main.d.ts.map +1 -1
- package/dist/node/main.js +34 -40
- package/dist/node/main.js.map +1 -1
- package/dist/node/monitorMemory.d.ts +11 -0
- package/dist/node/monitorMemory.d.ts.map +1 -1
- package/dist/node/monitorMemory.js +18 -9
- package/dist/node/monitorMemory.js.map +1 -1
- package/dist/node/osRelease.d.ts +6 -3
- package/dist/node/osRelease.d.ts.map +1 -1
- package/dist/node/osRelease.js +60 -155
- package/dist/node/osRelease.js.map +1 -1
- package/dist/node/releaseParsers.d.ts +11 -0
- package/dist/node/releaseParsers.d.ts.map +1 -0
- package/dist/node/releaseParsers.js +92 -0
- package/dist/node/releaseParsers.js.map +1 -0
- package/package.json +9 -7
- package/src/core/guards.ts +7 -11
- package/src/core/index.ts +2 -1
- package/src/core/millisecondsToString.ts +6 -12
- package/src/node/delays.ts +15 -0
- package/src/node/main.ts +46 -54
- package/src/node/monitorMemory.ts +20 -11
- package/src/node/osRelease.ts +72 -171
- package/src/node/releaseParsers.ts +109 -0
package/README.md
CHANGED
|
@@ -54,7 +54,8 @@ import type { Assert, Equal } from "@darthcav/ts-utils/type-testing"
|
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
The `core` entry point imports no Node.js built-ins and no packages, so its helpers run in any
|
|
57
|
-
runtime that supports ES2025 (`millisecondsToString` needs `Intl.DurationFormat`
|
|
57
|
+
runtime that supports ES2025 (`millisecondsToString` also needs `Intl.DurationFormat` and
|
|
58
|
+
`Temporal`).
|
|
58
59
|
|
|
59
60
|
## Usage
|
|
60
61
|
|
|
@@ -226,14 +227,15 @@ unsupported platforms or when the release file cannot be read. The normalized fi
|
|
|
226
227
|
number.
|
|
227
228
|
|
|
228
229
|
```ts
|
|
229
|
-
import { osRelease } from "@darthcav/ts-utils"
|
|
230
|
+
import { asString, osRelease } from "@darthcav/ts-utils"
|
|
230
231
|
|
|
231
232
|
const info = osRelease()
|
|
232
233
|
if (info) {
|
|
233
|
-
console.log(info.name)
|
|
234
|
-
console.log(info.version)
|
|
235
|
-
console.log(info.arch)
|
|
236
|
-
|
|
234
|
+
console.log(info.name) // e.g. "Ubuntu", "macOS", or "Windows 11"
|
|
235
|
+
console.log(info.version) // e.g. "24.04", "15.1", or "10.0.22000"
|
|
236
|
+
console.log(info.arch) // e.g. "x64"
|
|
237
|
+
// Raw keys are `unknown`; narrow them before use.
|
|
238
|
+
const prettyName = asString(info["PRETTY_NAME"]) // e.g. "Ubuntu 24.04 LTS" (Linux only)
|
|
237
239
|
}
|
|
238
240
|
```
|
|
239
241
|
|
|
@@ -294,8 +296,8 @@ Optional settings are passed as a `MainOptions` object:
|
|
|
294
296
|
|
|
295
297
|
An out-of-range `monitorMemoryHours` (negative, `NaN`, or outside `monitorMemory`'s range),
|
|
296
298
|
`shutdownTimeoutMs`, or `flushTimeoutMs` throws a `RangeError`, and a `launcher`, `shutdown`, or
|
|
297
|
-
`flushLogs` that is not a function throws a `TypeError`, before
|
|
298
|
-
launcher throws or its promise rejects, the failure is logged and the shutdown sequence runs.
|
|
299
|
+
`flushLogs` that is not a function throws a `TypeError`, before anything is logged or registered. If
|
|
300
|
+
the launcher throws or its promise rejects, the failure is logged and the shutdown sequence runs.
|
|
299
301
|
|
|
300
302
|
The default `flushLogs` disposes the sinks configured through the `@logtape/logtape` copy this
|
|
301
303
|
package uses. If the application configures another copy (e.g. a different LogTape version, whose
|
|
@@ -395,9 +397,15 @@ npm run typecheck
|
|
|
395
397
|
# Build (compile to JavaScript)
|
|
396
398
|
npm run build
|
|
397
399
|
|
|
400
|
+
# Build, then check that every package export resolves
|
|
401
|
+
npm run check:exports
|
|
402
|
+
|
|
398
403
|
# Run tests
|
|
399
404
|
npm test
|
|
400
405
|
|
|
406
|
+
# Run tests with coverage (fails below 100%)
|
|
407
|
+
npm run test:coverage
|
|
408
|
+
|
|
401
409
|
# Lint and format
|
|
402
410
|
npm run lint
|
|
403
411
|
npm run lint:fix
|
|
@@ -419,9 +427,11 @@ src/
|
|
|
419
427
|
main.ts # Process bootstrap and shutdown (main)
|
|
420
428
|
monitorMemory.ts # Periodic memory reporting
|
|
421
429
|
osRelease.ts # OS release information
|
|
430
|
+
releaseParsers.ts # os-release and plist parsers (internal)
|
|
431
|
+
delays.ts # Timer delay limit and range check (internal)
|
|
422
432
|
loggers/ # @darthcav/ts-utils/loggers (LogTape helpers)
|
|
423
433
|
type-testing/ # @darthcav/ts-utils/type-testing (type-level assertions)
|
|
424
|
-
__tests__/ # Test files
|
|
434
|
+
__tests__/ # Test files, shared helpers, and child-process fixtures
|
|
425
435
|
dist/ # Compiled output (generated)
|
|
426
436
|
public/ # Documentation output (generated)
|
|
427
437
|
```
|
|
@@ -432,7 +442,7 @@ public/ # Documentation output (generated)
|
|
|
432
442
|
|
|
433
443
|
[node-version]: https://img.shields.io/badge/node-%3E%3D26-orange.svg?style=flat-square
|
|
434
444
|
[node-url]: https://nodejs.org
|
|
435
|
-
[version-image]: https://img.shields.io/badge/version-1.0.
|
|
445
|
+
[version-image]: https://img.shields.io/badge/version-1.0.2-blue.svg?style=flat-square
|
|
436
446
|
[ci-badge]: https://github.com/darthcav/ts-utils/actions/workflows/tests.yml/badge.svg
|
|
437
447
|
[coverage-badge]:
|
|
438
448
|
https://codecov.io/github/darthcav/ts-utils/branch/dev/graph/badge.svg?token=RNEPER4KEI
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/core/guards.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAgBtE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAE1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAE7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAEjE;AAED;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAA;AAEzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACvB,KAAK,EA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KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GACpB,KAAK,IAAI,CAAC,EAAE,CAOd;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACvB,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GACpB,CAAC,EAAE,GAAG,SAAS,CAEjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAIzE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,EAAE,CAEpE"}
|
package/dist/core/guards.js
CHANGED
|
@@ -142,16 +142,10 @@ export function asFiniteNumber(value) {
|
|
|
142
142
|
* ```
|
|
143
143
|
*/
|
|
144
144
|
export function isArrayOf(value, guard) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
for (let i = 0; i < value.length; i++) {
|
|
150
|
-
if (!guard(value[i])) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return true;
|
|
145
|
+
// An array iterator, unlike `Array#every`, visits the holes of sparse
|
|
146
|
+
// arrays, as `undefined`.
|
|
147
|
+
return (Array.isArray(value) &&
|
|
148
|
+
value.values().every((element) => guard(element)));
|
|
155
149
|
}
|
|
156
150
|
/**
|
|
157
151
|
* Returns the input when it is an array whose elements all pass `guard`, as
|
package/dist/core/guards.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/core/guards.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,K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KAAmB;IAChE,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACvB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAgB,EAAgB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClE,CAAC,CAAC,EAAE,CAAA;AACZ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAC/C,OAAO,aAAa,CAAC,KAAK,EAAE,eAAe,CAAC,CAAA;AAChD,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Portable helpers: type guards and narrowing helpers, duration formatting,
|
|
3
3
|
* and `noop`. They import no Node.js built-ins or packages, so they run in any
|
|
4
|
-
* ES2025 runtime (`millisecondsToString` needs `Intl.DurationFormat`
|
|
4
|
+
* ES2025 runtime (`millisecondsToString` also needs `Intl.DurationFormat` and
|
|
5
|
+
* `Temporal`).
|
|
5
6
|
*
|
|
6
7
|
* @example
|
|
7
8
|
* ```ts
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACH,SAAS,EACT,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ,EACR,aAAa,EACb,SAAS,EACT,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ,EACR,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,oBAAoB,GACvB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA"}
|
package/dist/core/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Portable helpers: type guards and narrowing helpers, duration formatting,
|
|
3
3
|
* and `noop`. They import no Node.js built-ins or packages, so they run in any
|
|
4
|
-
* ES2025 runtime (`millisecondsToString` needs `Intl.DurationFormat`
|
|
4
|
+
* ES2025 runtime (`millisecondsToString` also needs `Intl.DurationFormat` and
|
|
5
|
+
* `Temporal`).
|
|
5
6
|
*
|
|
6
7
|
* @example
|
|
7
8
|
* ```ts
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACH,SAAS,EACT,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ,EACR,aAAa,EACb,SAAS,EACT,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ,EAGR,oBAAoB,GACvB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"millisecondsToString.d.ts","sourceRoot":"","sources":["../../src/core/millisecondsToString.ts"],"names":[],"mappings":"AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,SAAO,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"millisecondsToString.d.ts","sourceRoot":"","sources":["../../src/core/millisecondsToString.ts"],"names":[],"mappings":"AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,SAAO,GAAG,MAAM,CAatE"}
|
|
@@ -57,15 +57,11 @@ export function millisecondsToString(ms, locale = "en") {
|
|
|
57
57
|
if (!Number.isFinite(ms)) {
|
|
58
58
|
throw new RangeError(`millisecondsToString: "ms" must be a finite number, received ${ms}`);
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
seconds: Math.floor((magnitude % 60_000) / 1000),
|
|
67
|
-
milliseconds: magnitude % 1000,
|
|
68
|
-
});
|
|
69
|
-
return totalMilliseconds < 0 && formatted ? `-${formatted}` : formatted;
|
|
60
|
+
// Balances the milliseconds into days (of 24 hours) down to milliseconds.
|
|
61
|
+
// `Intl.DurationFormat` puts the sign of a negative duration in front.
|
|
62
|
+
const duration = Temporal.Duration.from({
|
|
63
|
+
milliseconds: Math.round(ms),
|
|
64
|
+
}).round({ largestUnit: "days" });
|
|
65
|
+
return getDurationFormatter(locale).format(duration);
|
|
70
66
|
}
|
|
71
67
|
//# sourceMappingURL=millisecondsToString.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"millisecondsToString.js","sourceRoot":"","sources":["../../src/core/millisecondsToString.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAEhC,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA+B,CAAA;AAEjE,SAAS,oBAAoB,CAAC,MAAc;IACxC,IAAI,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC9C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC1B,IAAI,CAAC;YACD,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE;gBACxC,KAAK,EAAE,QAAQ;aAClB,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,UAAU,CAChB,yCAAyC,MA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ClD,EAAE,KAAK,EAAE,CACZ,CAAA;QACL,CAAC;QACD,IAAI,kBAAkB,CAAC,IAAI,IAAI,qBAAqB,EAAE,CAAC;YACnD,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAA;YACrD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACvB,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YACrC,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC7C,CAAC;IAED,OAAO,SAAS,CAAA;AACpB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAU,EAAE,MAAM,GAAG,IAAI;IAC1D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,UAAU,CAChB,gEAAgE,EAAE,EAAE,CACvE,CAAA;IACL,CAAC;IAED,0EAA0E;IAC1E,uEAAuE;IACvE,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;QACpC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;KAC/B,CAAC,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAA;IACjC,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;AACxD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Longest delay `setTimeout` and `setInterval` support (2³¹ − 1 ms, about
|
|
3
|
+
* 596.5 hours). Node.js silently replaces larger delays with 1 ms.
|
|
4
|
+
*/
|
|
5
|
+
export declare const MAX_DELAY_MS = 2147483647;
|
|
6
|
+
/**
|
|
7
|
+
* Whether `ms` is a finite timer delay between `minMs` and
|
|
8
|
+
* {@link MAX_DELAY_MS}. Internal: not re-exported by the `node` entry point.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isValidDelay(ms: unknown, minMs?: number): ms is number;
|
|
11
|
+
//# sourceMappingURL=delays.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delays.d.ts","sourceRoot":"","sources":["../../src/node/delays.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,YAAY,aAAgB,CAAA;AAEzC;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,EAAE,IAAI,MAAM,CAEjE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isFiniteNumber } from "../core/guards.js";
|
|
2
|
+
/**
|
|
3
|
+
* Longest delay `setTimeout` and `setInterval` support (2³¹ − 1 ms, about
|
|
4
|
+
* 596.5 hours). Node.js silently replaces larger delays with 1 ms.
|
|
5
|
+
*/
|
|
6
|
+
export const MAX_DELAY_MS = 2_147_483_647;
|
|
7
|
+
/**
|
|
8
|
+
* Whether `ms` is a finite timer delay between `minMs` and
|
|
9
|
+
* {@link MAX_DELAY_MS}. Internal: not re-exported by the `node` entry point.
|
|
10
|
+
*/
|
|
11
|
+
export function isValidDelay(ms, minMs = 0) {
|
|
12
|
+
return isFiniteNumber(ms) && ms >= minMs && ms <= MAX_DELAY_MS;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=delays.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delays.js","sourceRoot":"","sources":["../../src/node/delays.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAA;AAEzC;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,EAAW,EAAE,KAAK,GAAG,CAAC;IAC/C,OAAO,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,IAAI,YAAY,CAAA;AAClE,CAAC"}
|
package/dist/node/main.d.ts
CHANGED
|
@@ -48,8 +48,9 @@ export type MainOptions = {
|
|
|
48
48
|
shutdownTimeoutMs?: number;
|
|
49
49
|
/**
|
|
50
50
|
* When greater than `0`, logs the memory usage every `monitorMemoryHours`
|
|
51
|
-
* hours via {@link monitorMemory}. Must be `0` or
|
|
52
|
-
*
|
|
51
|
+
* hours via {@link monitorMemory}. Must be `0` or an interval that
|
|
52
|
+
* {@link monitorMemory} accepts (one minute to 2³¹ − 1 ms). Defaults to
|
|
53
|
+
* `0` (disabled).
|
|
53
54
|
*/
|
|
54
55
|
monitorMemoryHours?: number;
|
|
55
56
|
/**
|
|
@@ -118,7 +119,8 @@ export type MainOptions = {
|
|
|
118
119
|
* `shutdown`, or `flushLogs` is not a function.
|
|
119
120
|
* @throws {Error} If another `main` call is still active.
|
|
120
121
|
* @throws {RangeError} If `monitorMemoryHours`, `shutdownTimeoutMs`, or
|
|
121
|
-
* `flushTimeoutMs` is out of range. Nothing is registered in that
|
|
122
|
+
* `flushTimeoutMs` is out of range. Nothing is logged or registered in that
|
|
123
|
+
* case.
|
|
122
124
|
*
|
|
123
125
|
* @example Without options:
|
|
124
126
|
* ```ts
|
package/dist/node/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/node/main.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/node/main.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAmFvD;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEzD;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GACrB;IACI,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAA;CACxC,GACD;IACI,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,MAAM,EACT,mBAAmB,GACnB,oBAAoB,GACpB,UAAU,CAAA;IAChB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAC1B,CAAA;AAEP;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC3B,OAAO,EAAE,eAAe,KACvB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEzB,8CAA8C;AAC9C,MAAM,MAAM,WAAW,GAAG;IACtB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;;;OAIG;IACH,0BAA0B,CAAC,EAAE,OAAO,CAAA;IACpC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgFG;AACH,wBAAgB,IAAI,CAChB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,WAAW,GACtB,MAAM,IAAI,CAkKZ"}
|
package/dist/node/main.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { constants } from "node:os";
|
|
2
2
|
import process, { env, execArgv, pid, title } from "node:process";
|
|
3
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
3
4
|
import { dispose } from "@logtape/logtape";
|
|
4
|
-
import {
|
|
5
|
+
import { isValidDelay, MAX_DELAY_MS } from "./delays.js";
|
|
6
|
+
import { HOURS_RANGE, isValidHours, monitorMemory } from "./monitorMemory.js";
|
|
5
7
|
/** Default for {@link MainOptions.flushTimeoutMs}. */
|
|
6
8
|
const DEFAULT_FLUSH_TIMEOUT_MS = 3_000;
|
|
7
9
|
/** Default for {@link MainOptions.shutdownTimeoutMs}. */
|
|
8
10
|
const DEFAULT_SHUTDOWN_TIMEOUT_MS = 10_000;
|
|
9
|
-
/**
|
|
10
|
-
* Longest delay `setTimeout` supports (2³¹ − 1 ms). Node.js silently replaces
|
|
11
|
-
* larger delays with 1 ms.
|
|
12
|
-
*/
|
|
13
|
-
const MAX_TIMEOUT_MS = 2_147_483_647;
|
|
14
11
|
/** Whether a {@link main} call has not been torn down yet. */
|
|
15
12
|
let active = false;
|
|
16
13
|
/**
|
|
@@ -19,38 +16,44 @@ let active = false;
|
|
|
19
16
|
* The timer stays referenced, so the process keeps running while it waits.
|
|
20
17
|
*/
|
|
21
18
|
async function runBounded(task, timeoutMs) {
|
|
22
|
-
|
|
19
|
+
const timeout = new AbortController();
|
|
23
20
|
try {
|
|
24
21
|
return await Promise.race([
|
|
25
22
|
Promise.try(task).then(() => ({ status: "fulfilled" }), (reason) => ({
|
|
26
23
|
status: "rejected",
|
|
27
24
|
reason,
|
|
28
25
|
})),
|
|
29
|
-
|
|
30
|
-
timer = setTimeout(() => resolve({ status: "timeout" }), timeoutMs);
|
|
31
|
-
}),
|
|
26
|
+
delay(timeoutMs, { status: "timeout" }, { signal: timeout.signal }),
|
|
32
27
|
]);
|
|
33
28
|
}
|
|
34
29
|
finally {
|
|
35
|
-
|
|
30
|
+
// Cancels the timer. The pending delay then rejects, but the race has
|
|
31
|
+
// already handled that.
|
|
32
|
+
timeout.abort();
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Renders an error (with its stack when available) or any other value.
|
|
37
|
+
* `Error.isError`, unlike `instanceof`, also recognizes errors from another
|
|
38
|
+
* realm (e.g. a `node:vm` context).
|
|
39
|
+
*/
|
|
39
40
|
function describe(value) {
|
|
40
|
-
return value
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
return Error.isError(value) ? (value.stack ?? String(value)) : String(value);
|
|
42
|
+
}
|
|
43
|
+
/** Names the type of `value`, telling `null` apart from objects. */
|
|
44
|
+
function typeName(value) {
|
|
45
|
+
return value === null ? "null" : typeof value;
|
|
43
46
|
}
|
|
44
47
|
/** Throws a `RangeError` unless `value` is a valid timer delay. */
|
|
45
48
|
function assertTimeout(option, value) {
|
|
46
|
-
if (!
|
|
47
|
-
throw new RangeError(`main: "${option}" must be a finite number between 0 and ${
|
|
49
|
+
if (!isValidDelay(value)) {
|
|
50
|
+
throw new RangeError(`main: "${option}" must be a finite number between 0 and ${MAX_DELAY_MS}, received ${value}`);
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
/** Throws a `TypeError` unless `value` is a function or `undefined`. */
|
|
51
54
|
function assertOptionalFunction(option, value) {
|
|
52
55
|
if (value !== undefined && typeof value !== "function") {
|
|
53
|
-
throw new TypeError(`main: "${option}" must be a function, received ${value
|
|
56
|
+
throw new TypeError(`main: "${option}" must be a function, received ${typeName(value)}`);
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
59
|
/**
|
|
@@ -99,7 +102,8 @@ function assertOptionalFunction(option, value) {
|
|
|
99
102
|
* `shutdown`, or `flushLogs` is not a function.
|
|
100
103
|
* @throws {Error} If another `main` call is still active.
|
|
101
104
|
* @throws {RangeError} If `monitorMemoryHours`, `shutdownTimeoutMs`, or
|
|
102
|
-
* `flushTimeoutMs` is out of range. Nothing is registered in that
|
|
105
|
+
* `flushTimeoutMs` is out of range. Nothing is logged or registered in that
|
|
106
|
+
* case.
|
|
103
107
|
*
|
|
104
108
|
* @example Without options:
|
|
105
109
|
* ```ts
|
|
@@ -138,14 +142,14 @@ export function main(name, logger, options) {
|
|
|
138
142
|
// function) from untyped callers, instead of silently ignoring them.
|
|
139
143
|
if (options !== undefined &&
|
|
140
144
|
(typeof options !== "object" || options === null)) {
|
|
141
|
-
throw new TypeError(`main: "options" must be a MainOptions object, received ${options
|
|
145
|
+
throw new TypeError(`main: "options" must be a MainOptions object, received ${typeName(options)}`);
|
|
142
146
|
}
|
|
143
147
|
const { launcher, shutdown, shutdownTimeoutMs = DEFAULT_SHUTDOWN_TIMEOUT_MS, monitorMemoryHours = 0, defaultInterruptionHandler = true, flushLogs = dispose, flushTimeoutMs = DEFAULT_FLUSH_TIMEOUT_MS, } = options ?? {};
|
|
144
148
|
assertOptionalFunction("launcher", launcher);
|
|
145
149
|
assertOptionalFunction("shutdown", shutdown);
|
|
146
150
|
assertOptionalFunction("flushLogs", flushLogs);
|
|
147
|
-
if (
|
|
148
|
-
throw new RangeError(`main: "monitorMemoryHours" must be 0 (disabled) or a
|
|
151
|
+
if (monitorMemoryHours !== 0 && !isValidHours(monitorMemoryHours)) {
|
|
152
|
+
throw new RangeError(`main: "monitorMemoryHours" must be 0 (disabled) or a finite number ${HOURS_RANGE}, received ${monitorMemoryHours}`);
|
|
149
153
|
}
|
|
150
154
|
assertTimeout("shutdownTimeoutMs", shutdownTimeoutMs);
|
|
151
155
|
assertTimeout("flushTimeoutMs", flushTimeoutMs);
|
|
@@ -157,8 +161,6 @@ export function main(name, logger, options) {
|
|
|
157
161
|
__logger.info `Process name: ${name}`;
|
|
158
162
|
__logger.info `Node.js environment: ${env["NODE_ENV"] ?? ""}`;
|
|
159
163
|
__logger.debug `Node.js process options: ${execArgv.concat(env["NODE_OPTIONS"] ?? []).join(" | ")}`;
|
|
160
|
-
// Started before any handler is registered, since it validates the hours
|
|
161
|
-
// further and may throw.
|
|
162
164
|
const stopMonitoring = monitorMemoryHours > 0
|
|
163
165
|
? monitorMemory(__logger, monitorMemoryHours)
|
|
164
166
|
: undefined;
|
|
@@ -175,12 +177,11 @@ export function main(name, logger, options) {
|
|
|
175
177
|
let cleanupFailed = false;
|
|
176
178
|
if (shutdown !== undefined) {
|
|
177
179
|
const outcome = await runBounded(() => shutdown(context), shutdownTimeoutMs);
|
|
180
|
+
cleanupFailed = outcome.status !== "fulfilled";
|
|
178
181
|
if (outcome.status === "rejected") {
|
|
179
|
-
cleanupFailed = true;
|
|
180
182
|
__logger.error `Shutdown function failed: ${describe(outcome.reason)}`;
|
|
181
183
|
}
|
|
182
184
|
else if (outcome.status === "timeout") {
|
|
183
|
-
cleanupFailed = true;
|
|
184
185
|
__logger.error `Shutdown function timed out after ${shutdownTimeoutMs} ms`;
|
|
185
186
|
}
|
|
186
187
|
}
|
|
@@ -214,19 +215,18 @@ export function main(name, logger, options) {
|
|
|
214
215
|
removeListeners.push(() => process.off(signal, onSignal));
|
|
215
216
|
}
|
|
216
217
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
};
|
|
218
|
+
/** Runs the shutdown sequence for a fatal failure, then exits with `1`. */
|
|
219
|
+
const fail = (source, error) => shutDown({ reason: "error", source, error }, () => process.exit(1));
|
|
220
220
|
const onUncaughtException = (error, origin) => {
|
|
221
221
|
__logger.error `Uncaught exception: ${describe(error)}`;
|
|
222
222
|
__logger.error `Exception origin: ${origin}`;
|
|
223
|
-
return
|
|
223
|
+
return fail("uncaughtException", error);
|
|
224
224
|
};
|
|
225
225
|
process.on("uncaughtException", onUncaughtException);
|
|
226
226
|
removeListeners.push(() => process.off("uncaughtException", onUncaughtException));
|
|
227
227
|
const onUnhandledRejection = (reason) => {
|
|
228
228
|
__logger.error `Unhandled promise rejection. Reason:\n${describe(reason)}`;
|
|
229
|
-
return
|
|
229
|
+
return fail("unhandledRejection", reason);
|
|
230
230
|
};
|
|
231
231
|
process.on("unhandledRejection", onUnhandledRejection);
|
|
232
232
|
removeListeners.push(() => process.off("unhandledRejection", onUnhandledRejection));
|
|
@@ -245,16 +245,10 @@ export function main(name, logger, options) {
|
|
|
245
245
|
};
|
|
246
246
|
const onLauncherFailure = (error) => {
|
|
247
247
|
__logger.error `Launcher failed: ${describe(error)}`;
|
|
248
|
-
return
|
|
248
|
+
return fail("launcher", error);
|
|
249
249
|
};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (result !== undefined) {
|
|
253
|
-
Promise.resolve(result).catch(onLauncherFailure);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
catch (error) {
|
|
257
|
-
void onLauncherFailure(error);
|
|
250
|
+
if (launcher !== undefined) {
|
|
251
|
+
Promise.try(launcher).catch(onLauncherFailure);
|
|
258
252
|
}
|
|
259
253
|
return teardown;
|
|
260
254
|
}
|
package/dist/node/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/node/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACjE,OAAO,EAAE,OAAO,EAAe,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/node/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACjE,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAe,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,YAAY,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IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAA;IAC7C,CAAC,CAAA;IACD,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAA;IACtD,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE,CACtB,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAC1D,CAAA;IAED,MAAM,GAAG,IAAI,CAAA;IACb,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,MAAM,QAAQ,GAAG,GAAS,EAAE;QACxB,IAAI,QAAQ,EAAE,CAAC;YACX,OAAM;QACV,CAAC;QACD,QAAQ,GAAG,IAAI,CAAA;QACf,cAAc,EAAE,EAAE,CAAA;QAClB,KAAK,MAAM,MAAM,IAAI,eAAe,EAAE,CAAC;YACnC,MAAM,EAAE,CAAA;QACZ,CAAC;QACD,MAAM,GAAG,KAAK,CAAA;IAClB,CAAC,CAAA;IAED,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAiB,EAAE;QACxD,QAAQ,CAAC,KAAK,CAAA,oBAAoB,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAA;QACnD,OAAO,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;IAClC,CAAC,CAAA;IACD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;IAClD,CAAC;IAED,OAAO,QAAQ,CAAA;AACnB,CAAC"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import type { Logger } from "@logtape/logtape";
|
|
2
|
+
/**
|
|
3
|
+
* The valid range of a reporting interval in hours, for error messages.
|
|
4
|
+
* Internal, like {@link isValidHours}.
|
|
5
|
+
*/
|
|
6
|
+
export declare const HOURS_RANGE: string;
|
|
7
|
+
/**
|
|
8
|
+
* Whether `hours` is a valid reporting interval ({@link HOURS_RANGE}).
|
|
9
|
+
* Internal: {@link main} uses it too, but the `node` entry point does not
|
|
10
|
+
* re-export it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isValidHours(hours: unknown): hours is number;
|
|
2
13
|
/**
|
|
3
14
|
* Starts a periodic interval that logs process uptime and memory usage, and
|
|
4
15
|
* returns a function that stops it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitorMemory.d.ts","sourceRoot":"","sources":["../../src/node/monitorMemory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"monitorMemory.d.ts","sourceRoot":"","sources":["../../src/node/monitorMemory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAW9C;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,MAAoG,CAAA;AAE9H;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,MAAM,IAAI,CA2B5E"}
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { memoryUsage, uptime } from "node:process";
|
|
2
|
+
import { isFiniteNumber } from "../core/guards.js";
|
|
2
3
|
import { millisecondsToString } from "../core/millisecondsToString.js";
|
|
4
|
+
import { isValidDelay, MAX_DELAY_MS } from "./delays.js";
|
|
3
5
|
/** Shortest allowed reporting interval: one minute. */
|
|
4
6
|
const MIN_DELAY_MS = 60 * 1_000;
|
|
7
|
+
/** One hour in milliseconds. */
|
|
8
|
+
const HOUR_MS = 60 * 60 * 1_000;
|
|
5
9
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
10
|
+
* The valid range of a reporting interval in hours, for error messages.
|
|
11
|
+
* Internal, like {@link isValidHours}.
|
|
8
12
|
*/
|
|
9
|
-
const
|
|
13
|
+
export const HOURS_RANGE = `between ${MIN_DELAY_MS / HOUR_MS} and ${MAX_DELAY_MS / HOUR_MS} (1 minute to 2^31 - 1 ms)`;
|
|
14
|
+
/**
|
|
15
|
+
* Whether `hours` is a valid reporting interval ({@link HOURS_RANGE}).
|
|
16
|
+
* Internal: {@link main} uses it too, but the `node` entry point does not
|
|
17
|
+
* re-export it.
|
|
18
|
+
*/
|
|
19
|
+
export function isValidHours(hours) {
|
|
20
|
+
return isFiniteNumber(hours) && isValidDelay(hours * HOUR_MS, MIN_DELAY_MS);
|
|
21
|
+
}
|
|
10
22
|
/**
|
|
11
23
|
* Starts a periodic interval that logs process uptime and memory usage, and
|
|
12
24
|
* returns a function that stops it.
|
|
@@ -48,11 +60,8 @@ const MAX_DELAY_MS = 2_147_483_647;
|
|
|
48
60
|
* ```
|
|
49
61
|
*/
|
|
50
62
|
export function monitorMemory(logger, hours = 24) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
delay < MIN_DELAY_MS ||
|
|
54
|
-
delay > MAX_DELAY_MS) {
|
|
55
|
-
throw new RangeError(`monitorMemory: "hours" must be a finite number between ${MIN_DELAY_MS / 3_600_000} and ${MAX_DELAY_MS / 3_600_000} (1 minute to 2^31 - 1 ms), received ${hours}`);
|
|
63
|
+
if (!isValidHours(hours)) {
|
|
64
|
+
throw new RangeError(`monitorMemory: "hours" must be a finite number ${HOURS_RANGE}, received ${hours}`);
|
|
56
65
|
}
|
|
57
66
|
const __logger = logger.getChild(["monitorMemory"]);
|
|
58
67
|
const timer = setInterval(() => {
|
|
@@ -67,7 +76,7 @@ export function monitorMemory(logger, hours = 24) {
|
|
|
67
76
|
uptimeMs,
|
|
68
77
|
});
|
|
69
78
|
__logger.info("Process memory - Resident set size: {rss} | Heap total: {heapTotal} | Heap used: {heapUsed} | External: {external}", { rss, heapTotal, heapUsed, external });
|
|
70
|
-
},
|
|
79
|
+
}, hours * HOUR_MS);
|
|
71
80
|
timer.unref();
|
|
72
81
|
return () => clearInterval(timer);
|
|
73
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitorMemory.js","sourceRoot":"","sources":["../../src/node/monitorMemory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"monitorMemory.js","sourceRoot":"","sources":["../../src/node/monitorMemory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAExD,uDAAuD;AACvD,MAAM,YAAY,GAAG,EAAE,GAAG,KAAK,CAAA;AAE/B,gCAAgC;AAChC,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAA;AAE/B;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW,WAAW,YAAY,GAAG,OAAO,QAAQ,YAAY,GAAG,OAAO,4BAA4B,CAAA;AAE9H;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACvC,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,KAAK,GAAG,OAAO,EAAE,YAAY,CAAC,CAAA;AAC/E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,QAAgB,EAAE;IAC5D,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,UAAU,CAChB,kDAAkD,WAAW,cAAc,KAAK,EAAE,CACrF,CAAA;IACL,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAC,CAAC,CAAA;IAEnD,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAA;QAC7C,MAAM,eAAe,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAA;QACtD,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,WAAW,EAAE,CAAA;QAC5D,kEAAkE;QAClE,qEAAqE;QACrE,iEAAiE;QACjE,QAAQ,CAAC,IAAI,CAAC,mBAAmB,eAAe,EAAE,EAAE;YAChD,MAAM,EAAE,eAAe;YACvB,QAAQ;SACX,CAAC,CAAA;QACF,QAAQ,CAAC,IAAI,CACT,oHAAoH,EACpH,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,CACzC,CAAA;IACL,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,CAAA;IACnB,KAAK,CAAC,KAAK,EAAE,CAAA;IAEb,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;AACrC,CAAC"}
|
package/dist/node/osRelease.d.ts
CHANGED
|
@@ -44,11 +44,14 @@ export type OsRelease = {
|
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
46
46
|
* ```ts
|
|
47
|
-
* import { osRelease } from "@darthcav/ts-utils"
|
|
47
|
+
* import { asString, osRelease } from "@darthcav/ts-utils"
|
|
48
48
|
*
|
|
49
49
|
* const info = osRelease()
|
|
50
|
-
* if (info)
|
|
51
|
-
*
|
|
50
|
+
* if (info) {
|
|
51
|
+
* console.log(info.name) // e.g. "Ubuntu", "macOS", or "Windows 11"
|
|
52
|
+
* // Raw keys are `unknown`; narrow them before use.
|
|
53
|
+
* const prettyName = asString(info["PRETTY_NAME"]) // e.g. "Ubuntu 24.04 LTS" (Linux only)
|
|
54
|
+
* }
|
|
52
55
|
* ```
|
|
53
56
|
*/
|
|
54
57
|
export declare function osRelease(): OsRelease | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"osRelease.d.ts","sourceRoot":"","sources":["../../src/node/osRelease.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"osRelease.d.ts","sourceRoot":"","sources":["../../src/node/osRelease.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGtD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;CACf,GAAG,aAAa,CAAA;AAuEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,SAAS,IAAI,SAAS,GAAG,IAAI,CAqB5C"}
|