@darthcav/ts-utils 0.11.0 → 0.12.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 +43 -6
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +10 -6
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +10 -6
- package/dist/main.js.map +1 -1
- package/dist/osRelease.d.ts +4 -2
- package/dist/osRelease.d.ts.map +1 -1
- package/dist/osRelease.js.map +1 -1
- package/dist/type-testing/Assert.d.ts +23 -0
- package/dist/type-testing/Assert.d.ts.map +1 -0
- package/dist/type-testing/Assert.js +2 -0
- package/dist/type-testing/Assert.js.map +1 -0
- package/dist/type-testing/Equal.d.ts +25 -0
- package/dist/type-testing/Equal.d.ts.map +1 -0
- package/dist/type-testing/Equal.js +2 -0
- package/dist/type-testing/Equal.js.map +1 -0
- package/dist/type-testing/Extends.d.ts +22 -0
- package/dist/type-testing/Extends.d.ts.map +1 -0
- package/dist/type-testing/Extends.js +2 -0
- package/dist/type-testing/Extends.js.map +1 -0
- package/dist/type-testing/IsAny.d.ts +17 -0
- package/dist/type-testing/IsAny.d.ts.map +1 -0
- package/dist/type-testing/IsAny.js +2 -0
- package/dist/type-testing/IsAny.js.map +1 -0
- package/dist/type-testing/IsNever.d.ts +17 -0
- package/dist/type-testing/IsNever.d.ts.map +1 -0
- package/dist/type-testing/IsNever.js +2 -0
- package/dist/type-testing/IsNever.js.map +1 -0
- package/dist/type-testing/IsUnknown.d.ts +20 -0
- package/dist/type-testing/IsUnknown.d.ts.map +1 -0
- package/dist/type-testing/IsUnknown.js +2 -0
- package/dist/type-testing/IsUnknown.js.map +1 -0
- package/dist/type-testing/Not.d.ts +17 -0
- package/dist/type-testing/Not.d.ts.map +1 -0
- package/dist/type-testing/Not.js +2 -0
- package/dist/type-testing/Not.js.map +1 -0
- package/package.json +5 -7
- package/src/index.ts +14 -0
- package/src/main.ts +10 -6
- package/src/osRelease.ts +4 -2
- package/src/type-testing/Assert.ts +22 -0
- package/src/type-testing/Equal.ts +27 -0
- package/src/type-testing/Extends.ts +21 -0
- package/src/type-testing/IsAny.ts +16 -0
- package/src/type-testing/IsNever.ts +16 -0
- package/src/type-testing/IsUnknown.ts +21 -0
- package/src/type-testing/Not.ts +16 -0
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ npm install @darthcav/ts-utils
|
|
|
28
28
|
|
|
29
29
|
### `getConsoleLogger`
|
|
30
30
|
|
|
31
|
-
Configures logging and
|
|
31
|
+
Configures logging and resolves to a `Logger` for the given category name. Records at or above
|
|
32
32
|
`lowestLevel` are written to the console with RFC 3339 timestamps. The internal `logtape/meta`
|
|
33
33
|
logger is silenced. The function is safe to call more than once — each call reconfigures logtape
|
|
34
34
|
from scratch (the most recent call wins).
|
|
@@ -214,8 +214,9 @@ Before exiting, `main` flushes and disposes the configured logtape sinks (for at
|
|
|
214
214
|
`flushTimeoutMs`, 3 seconds by default), so buffered or asynchronous sinks keep the final messages.
|
|
215
215
|
On `SIGINT`/`SIGTERM` it logs the signal at `info` level and then re-raises it, so the process ends
|
|
216
216
|
as killed by that signal (exit status 130/143), which shells and supervisors such as systemd treat
|
|
217
|
-
as a clean stop.
|
|
218
|
-
`
|
|
217
|
+
as a clean stop. If another listener for that signal is registered, the process exits with status
|
|
218
|
+
`128 + signal number` instead. Uncaught exceptions, unhandled rejections, and launcher failures exit
|
|
219
|
+
with status `1`. A second signal or error during the flush exits immediately.
|
|
219
220
|
|
|
220
221
|
Optional settings are passed as a `MainOptions` object:
|
|
221
222
|
|
|
@@ -255,12 +256,15 @@ main("my-app", logger, {
|
|
|
255
256
|
})
|
|
256
257
|
|
|
257
258
|
// 3. Manage graceful shutdown in the application instead:
|
|
259
|
+
let server: Server | undefined
|
|
258
260
|
const teardown = main("my-app", logger, {
|
|
259
|
-
launcher: () =>
|
|
261
|
+
launcher: () => {
|
|
262
|
+
server = startServer()
|
|
263
|
+
},
|
|
260
264
|
defaultInterruptionHandler: false,
|
|
261
265
|
})
|
|
262
266
|
process.once("SIGTERM", async () => {
|
|
263
|
-
await server
|
|
267
|
+
await server?.close()
|
|
264
268
|
teardown()
|
|
265
269
|
})
|
|
266
270
|
```
|
|
@@ -268,6 +272,38 @@ process.once("SIGTERM", async () => {
|
|
|
268
272
|
The positional forms of earlier versions (e.g. `main("my-app", logger, () => startServer(), 2)`)
|
|
269
273
|
were removed in 0.11.0; passing anything other than an options object throws a `TypeError`.
|
|
270
274
|
|
|
275
|
+
### Type testing
|
|
276
|
+
|
|
277
|
+
Type-level helpers to check types at compile time, e.g. in test files. They are types only, so they
|
|
278
|
+
add no code at runtime:
|
|
279
|
+
|
|
280
|
+
- `Assert<T>` type-checks only when `T` is exactly `true`.
|
|
281
|
+
- `Equal<X, Y>` is `true` when `X` and `Y` are identical types. It is stricter than mutual
|
|
282
|
+
assignability: `any` only equals `any`, and `readonly` and `?` modifiers must match.
|
|
283
|
+
- `Extends<X, Y>` is `true` when `X` is assignable to `Y` (unions are compared as a whole).
|
|
284
|
+
- `Not<T>` negates a predicate result.
|
|
285
|
+
- `IsAny<T>`, `IsNever<T>`, and `IsUnknown<T>` detect those special types.
|
|
286
|
+
|
|
287
|
+
Declare each assertion as an (unused) type alias; a failing one is reported by `tsc` (e.g.
|
|
288
|
+
`tsc --noEmit`), not by the test runner, since Node.js strips types without checking them. Use
|
|
289
|
+
`@ts-expect-error` to assert that an assertion fails.
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
import {
|
|
293
|
+
type Assert,
|
|
294
|
+
asString,
|
|
295
|
+
type Equal,
|
|
296
|
+
type IsUnknown,
|
|
297
|
+
type Not,
|
|
298
|
+
} from "@darthcav/ts-utils"
|
|
299
|
+
|
|
300
|
+
type _AsString = Assert<Equal<ReturnType<typeof asString>, string | undefined>>
|
|
301
|
+
type _NotAny = Assert<Not<Equal<ReturnType<typeof asString>, any>>>
|
|
302
|
+
type _Parsed = Assert<IsUnknown<Parameters<typeof asString>[0]>>
|
|
303
|
+
// @ts-expect-error -- `string` is not `number`
|
|
304
|
+
type _Fails = Assert<Equal<string, number>>
|
|
305
|
+
```
|
|
306
|
+
|
|
271
307
|
For the full API reference see the [API Documentation][pages-url].
|
|
272
308
|
|
|
273
309
|
## Development
|
|
@@ -305,6 +341,7 @@ src/
|
|
|
305
341
|
osRelease.ts # OS release utilities
|
|
306
342
|
types.ts # RuntimeObject type and type guards
|
|
307
343
|
loggers/ # Logger utilities
|
|
344
|
+
type-testing/ # Type-level assertion helpers
|
|
308
345
|
__tests__/ # Test files
|
|
309
346
|
dist/ # Compiled output (generated)
|
|
310
347
|
public/ # Documentation output (generated)
|
|
@@ -316,7 +353,7 @@ public/ # Documentation output (generated)
|
|
|
316
353
|
|
|
317
354
|
[node-version]: https://img.shields.io/badge/node-%3E%3D26-orange.svg?style=flat-square
|
|
318
355
|
[node-url]: https://nodejs.org
|
|
319
|
-
[version-image]: https://img.shields.io/badge/version-0.
|
|
356
|
+
[version-image]: https://img.shields.io/badge/version-0.12.1-blue.svg?style=flat-square
|
|
320
357
|
[ci-badge]: https://github.com/darthcav/ts-utils/actions/workflows/tests.yml/badge.svg
|
|
321
358
|
[coverage-badge]:
|
|
322
359
|
https://codecov.io/github/darthcav/ts-utils/branch/dev/graph/badge.svg?token=RNEPER4KEI
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,13 @@ import { millisecondsToString } from "./millisecondsToString.ts";
|
|
|
10
10
|
import { monitorMemory } from "./monitorMemory.ts";
|
|
11
11
|
import { noop } from "./noop.ts";
|
|
12
12
|
import { type OsRelease, osRelease } from "./osRelease.ts";
|
|
13
|
+
import type { Assert } from "./type-testing/Assert.ts";
|
|
14
|
+
import type { Equal } from "./type-testing/Equal.ts";
|
|
15
|
+
import type { Extends } from "./type-testing/Extends.ts";
|
|
16
|
+
import type { IsAny } from "./type-testing/IsAny.ts";
|
|
17
|
+
import type { IsNever } from "./type-testing/IsNever.ts";
|
|
18
|
+
import type { IsUnknown } from "./type-testing/IsUnknown.ts";
|
|
19
|
+
import type { Not } from "./type-testing/Not.ts";
|
|
13
20
|
import { asRuntimeObject, asString, isRuntimeObject, isString, type RuntimeObject, toRuntimeObjectArray } from "./types.ts";
|
|
14
|
-
export { asRuntimeObject, asString, getConsoleLogger, getDummyLogger, isRuntimeObject, isString, type LauncherFunction, type MainOptions, main, millisecondsToString, monitorMemory, noop, type OsRelease, osRelease, type RuntimeObject, toRuntimeObjectArray, };
|
|
21
|
+
export { type Assert, asRuntimeObject, asString, type Equal, type Extends, getConsoleLogger, getDummyLogger, type IsAny, type IsNever, type IsUnknown, isRuntimeObject, isString, type LauncherFunction, type MainOptions, main, millisecondsToString, monitorMemory, type Not, noop, type OsRelease, osRelease, type RuntimeObject, toRuntimeObjectArray, };
|
|
15
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EACH,eAAe,EACf,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,KAAK,aAAa,EAClB,oBAAoB,EACvB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAC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Y,CAAA;AAEnB,OAAO,EACH,KAAK,MAAM,EACX,eAAe,EACf,QAAQ,EACR,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,gBAAgB,EAChB,cAAc,EACd,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,eAAe,EACf,QAAQ,EACR,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,IAAI,EACJ,oBAAoB,EACpB,aAAa,EACb,KAAK,GAAG,EACR,IAAI,EACJ,KAAK,SAAS,EACd,SAAS,EACT,KAAK,aAAa,EAClB,oBAAoB,GACvB,CAAA"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAA2C,IAAI,EAAE,MAAM,WAAW,CAAA;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAkB,SAAS,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAA2C,IAAI,EAAE,MAAM,WAAW,CAAA;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAkB,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAQ1D,OAAO,EACH,eAAe,EACf,QAAQ,EACR,eAAe,EACf,QAAQ,EAER,oBAAoB,GACvB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAEH,eAAe,EACf,QAAQ,EAGR,gBAAgB,EAChB,cAAc,EAId,eAAe,EACf,QAAQ,EAGR,IAAI,EACJ,oBAAoB,EACpB,aAAa,EAEb,IAAI,EAEJ,SAAS,EAET,oBAAoB,GACvB,CAAA"}
|
package/dist/main.d.ts
CHANGED
|
@@ -39,10 +39,11 @@ export type MainOptions = {
|
|
|
39
39
|
flushTimeoutMs?: number;
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
|
-
* Bootstraps an application process: logs startup information,
|
|
43
|
-
* handlers for `SIGINT
|
|
44
|
-
*
|
|
45
|
-
*
|
|
42
|
+
* Bootstraps an application process: logs startup information, optionally
|
|
43
|
+
* registers handlers for `SIGINT` and `SIGTERM` (see
|
|
44
|
+
* {@link MainOptions.defaultInterruptionHandler}), always registers handlers
|
|
45
|
+
* for `uncaughtException` and `unhandledRejection`, optionally starts memory
|
|
46
|
+
* monitoring, then runs the optional launcher function.
|
|
46
47
|
*
|
|
47
48
|
* The process title, PID, name, and `NODE_ENV` are logged at `info` level.
|
|
48
49
|
* The Node.js process options (`execArgv` and `NODE_OPTIONS`) are logged at
|
|
@@ -94,12 +95,15 @@ export type MainOptions = {
|
|
|
94
95
|
*
|
|
95
96
|
* @example Managing graceful shutdown in the application:
|
|
96
97
|
* ```ts
|
|
98
|
+
* let server: Server | undefined
|
|
97
99
|
* const teardown = main("my-app", logger, {
|
|
98
|
-
* launcher: () =>
|
|
100
|
+
* launcher: () => {
|
|
101
|
+
* server = startServer()
|
|
102
|
+
* },
|
|
99
103
|
* defaultInterruptionHandler: false,
|
|
100
104
|
* })
|
|
101
105
|
* process.once("SIGTERM", async () => {
|
|
102
|
-
* await server
|
|
106
|
+
* await server?.close()
|
|
103
107
|
* teardown()
|
|
104
108
|
* })
|
|
105
109
|
* ```
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAA;AA8CvD;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEzD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;;;;OAKG;IACH,0BAA0B,CAAC,EAAE,OAAO,CAAA;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAA;AA8CvD;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEzD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;;;;OAKG;IACH,0BAA0B,CAAC,EAAE,OAAO,CAAA;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACH,wBAAgB,IAAI,CAChB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,WAAW,GACtB,MAAM,IAAI,CA0IZ"}
|
package/dist/main.js
CHANGED
|
@@ -43,10 +43,11 @@ function describe(value) {
|
|
|
43
43
|
: String(value);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
|
-
* Bootstraps an application process: logs startup information,
|
|
47
|
-
* handlers for `SIGINT
|
|
48
|
-
*
|
|
49
|
-
*
|
|
46
|
+
* Bootstraps an application process: logs startup information, optionally
|
|
47
|
+
* registers handlers for `SIGINT` and `SIGTERM` (see
|
|
48
|
+
* {@link MainOptions.defaultInterruptionHandler}), always registers handlers
|
|
49
|
+
* for `uncaughtException` and `unhandledRejection`, optionally starts memory
|
|
50
|
+
* monitoring, then runs the optional launcher function.
|
|
50
51
|
*
|
|
51
52
|
* The process title, PID, name, and `NODE_ENV` are logged at `info` level.
|
|
52
53
|
* The Node.js process options (`execArgv` and `NODE_OPTIONS`) are logged at
|
|
@@ -98,12 +99,15 @@ function describe(value) {
|
|
|
98
99
|
*
|
|
99
100
|
* @example Managing graceful shutdown in the application:
|
|
100
101
|
* ```ts
|
|
102
|
+
* let server: Server | undefined
|
|
101
103
|
* const teardown = main("my-app", logger, {
|
|
102
|
-
* launcher: () =>
|
|
104
|
+
* launcher: () => {
|
|
105
|
+
* server = startServer()
|
|
106
|
+
* },
|
|
103
107
|
* defaultInterruptionHandler: false,
|
|
104
108
|
* })
|
|
105
109
|
* process.once("SIGTERM", async () => {
|
|
106
|
-
* await server
|
|
110
|
+
* await server?.close()
|
|
107
111
|
* teardown()
|
|
108
112
|
* })
|
|
109
113
|
* ```
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,OAAO,EAAE,EAAE,GAAG,EAAE,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,iBAAiB,GAAG,CAAC,KAAc,EAAiB,EAAE;QACxD,QAAQ,CAAC,KAAK,CAAA,oBAAoB,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAA;QACnD,OAAO,cAAc,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IAChD,CAAC,CAAA;IACD,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,QAAQ,EAAE,EAAE,CAAA;QAC3B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;QACpD,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,KAAK,iBAAiB,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;IAED,OAAO,QAAQ,CAAA;AACnB,CAAC"}
|
package/dist/osRelease.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ import type { RuntimeObject } from "./types.ts";
|
|
|
2
2
|
/**
|
|
3
3
|
* OS release information with normalized fields and optional platform-specific extras.
|
|
4
4
|
*
|
|
5
|
-
* `name`, `version`, and `arch` are always present. On Linux,
|
|
6
|
-
* `/etc/os-release
|
|
5
|
+
* `name`, `version`, and `arch` are always present. On Linux, the keys read from
|
|
6
|
+
* the os-release file (`/etc/os-release`, or `/usr/lib/os-release` as a
|
|
7
|
+
* fallback; e.g. `ID`, `PRETTY_NAME`, `ID_LIKE`) are also accessible by string
|
|
8
|
+
* index.
|
|
7
9
|
*/
|
|
8
10
|
export type OsRelease = {
|
|
9
11
|
/** Human-readable OS name, e.g. `"Ubuntu"` or `"Windows 11"`. */
|
package/dist/osRelease.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"osRelease.d.ts","sourceRoot":"","sources":["../src/osRelease.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C
|
|
1
|
+
{"version":3,"file":"osRelease.d.ts","sourceRoot":"","sources":["../src/osRelease.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAA;IACZ,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;CACf,GAAG,aAAa,CAAA;AAwEjB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,SAAS,IAAI,SAAS,GAAG,IAAI,CAuD5C"}
|
package/dist/osRelease.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"osRelease.js","sourceRoot":"","sources":["../src/osRelease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"osRelease.js","sourceRoot":"","sources":["../src/osRelease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAoBlE;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CAAC,iBAAiB,EAAE,qBAAqB,CAAU,CAAA;AAE5E;;;GAGG;AACH,MAAM,cAAc,GAAG,mBAAmB,CAAA;AAE1C;;;GAGG;AACH,SAAS,iBAAiB;IACtB,KAAK,MAAM,IAAI,IAAI,gBAAgB,EAAE,CAAC;QAClC,IAAI,CAAC;YACD,OAAO,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACtC,CAAC;QAAC,MAAM,CA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AAC;aAAM,CAAC;YACJ,QAAQ,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;gBAC9B,KAAK,KAAK;oBACN,IAAI,IAAI,IAAI,CAAA;oBACZ,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,KAAK,CAAA;oBACb,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,GAAG,CAAA;oBACX,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,GAAG,CAAA;oBACX,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,OAAO,CAAA;oBACf,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,mBAAmB,CAAA;oBAC3B,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,IAAI,CAAA;oBACZ,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,MAAM,CAAA;oBACd,MAAK;gBACT;oBACI,IAAI,IAAI,iBAAiB,CAAA;oBACzB,MAAK;YACb,CAAC;QACL,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAA;IAC1C,CAAC;IACD,OAAO,IAAI,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time assertion: type-checks only when `T` is exactly `true`.
|
|
3
|
+
*
|
|
4
|
+
* Wrap one of the type-level predicates of this module ({@link Equal},
|
|
5
|
+
* {@link Extends}, {@link Not}, {@link IsAny}, {@link IsNever},
|
|
6
|
+
* {@link IsUnknown}) in it and declare the result as an (unused) type alias.
|
|
7
|
+
* A predicate that evaluates to `false` or `boolean` becomes a type error that
|
|
8
|
+
* `tsc` reports. The alias resolves to `true` and, like every type, is erased
|
|
9
|
+
* at runtime.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T - The predicate result that must be `true`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import type { Assert, Equal } from "@darthcav/ts-utils"
|
|
16
|
+
*
|
|
17
|
+
* type _Ok = Assert<Equal<ReturnType<typeof parseInt>, number>>
|
|
18
|
+
* // @ts-expect-error -- `string` is not `number`
|
|
19
|
+
* type _Fails = Assert<Equal<string, number>>
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export type Assert<T extends true> = T;
|
|
23
|
+
//# sourceMappingURL=Assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Assert.d.ts","sourceRoot":"","sources":["../../src/type-testing/Assert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Assert.js","sourceRoot":"","sources":["../../src/type-testing/Assert.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level predicate: `true` when `X` and `Y` are identical types, `false`
|
|
3
|
+
* otherwise.
|
|
4
|
+
*
|
|
5
|
+
* The comparison is the one the compiler uses for type identity, so it is
|
|
6
|
+
* stricter than mutual assignability: `any` only equals `any`, and modifiers
|
|
7
|
+
* such as `readonly` and `?` must match. An intersection is not identical to
|
|
8
|
+
* the equivalent flattened object type (`{ a: 1 } & { b: 2 }` is not
|
|
9
|
+
* `{ a: 1; b: 2 }`); flatten it with a mapped type before comparing when
|
|
10
|
+
* needed.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam X - The first type to compare.
|
|
13
|
+
* @typeParam Y - The second type to compare.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import type { Assert, Equal, Not } from "@darthcav/ts-utils"
|
|
18
|
+
*
|
|
19
|
+
* type _Same = Assert<Equal<{ a: string }, { a: string }>>
|
|
20
|
+
* type _Readonly = Assert<Not<Equal<{ readonly a: string }, { a: string }>>>
|
|
21
|
+
* type _Any = Assert<Not<Equal<any, string>>>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
25
|
+
//# sourceMappingURL=Equal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Equal.d.ts","sourceRoot":"","sources":["../../src/type-testing/Equal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAClB,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,GAC7D,IAAI,GACJ,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Equal.js","sourceRoot":"","sources":["../../src/type-testing/Equal.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level predicate: `true` when `X` is assignable to `Y`, `false`
|
|
3
|
+
* otherwise.
|
|
4
|
+
*
|
|
5
|
+
* Unions are compared as a whole rather than member by member, so
|
|
6
|
+
* `Extends<string | number, string>` is `false`. Since `any` and `never` are
|
|
7
|
+
* assignable to every type, `Extends<any, Y>` and `Extends<never, Y>` are
|
|
8
|
+
* always `true`; use {@link Equal} to check for an exact type.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam X - The type to check.
|
|
11
|
+
* @typeParam Y - The type `X` must be assignable to.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import type { Assert, Extends, Not } from "@darthcav/ts-utils"
|
|
16
|
+
*
|
|
17
|
+
* type _Literal = Assert<Extends<"a", string>>
|
|
18
|
+
* type _Union = Assert<Not<Extends<string | number, string>>>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type Extends<X, Y> = [X] extends [Y] ? true : false;
|
|
22
|
+
//# sourceMappingURL=Extends.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Extends.d.ts","sourceRoot":"","sources":["../../src/type-testing/Extends.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Extends.js","sourceRoot":"","sources":["../../src/type-testing/Extends.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level predicate: `true` when `T` is `any`, `false` otherwise.
|
|
3
|
+
*
|
|
4
|
+
* Useful to catch a value or return type that silently widened to `any`.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam T - The type to check.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import type { Assert, IsAny, Not } from "@darthcav/ts-utils"
|
|
11
|
+
*
|
|
12
|
+
* type _Parsed = Assert<IsAny<ReturnType<typeof JSON.parse>>>
|
|
13
|
+
* type _Typed = Assert<Not<IsAny<unknown>>>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
17
|
+
//# sourceMappingURL=IsAny.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsAny.d.ts","sourceRoot":"","sources":["../../src/type-testing/IsAny.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsAny.js","sourceRoot":"","sources":["../../src/type-testing/IsAny.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level predicate: `true` when `T` is `never`, `false` otherwise.
|
|
3
|
+
*
|
|
4
|
+
* Useful to check that a union has been exhausted or that a conditional type
|
|
5
|
+
* filters out every member.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T - The type to check.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { Assert, IsNever } from "@darthcav/ts-utils"
|
|
12
|
+
*
|
|
13
|
+
* type _Empty = Assert<IsNever<Exclude<"a" | "b", string>>>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
17
|
+
//# sourceMappingURL=IsNever.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsNever.d.ts","sourceRoot":"","sources":["../../src/type-testing/IsNever.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsNever.js","sourceRoot":"","sources":["../../src/type-testing/IsNever.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IsAny } from "./IsAny.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Type-level predicate: `true` when `T` is `unknown`, `false` otherwise
|
|
4
|
+
* (including for `any`).
|
|
5
|
+
*
|
|
6
|
+
* Useful to check that an untrusted value (e.g. parsed input) is typed as
|
|
7
|
+
* `unknown` and has to be narrowed before use.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam T - The type to check.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import type { Assert, IsUnknown, Not } from "@darthcav/ts-utils"
|
|
14
|
+
*
|
|
15
|
+
* type _Unknown = Assert<IsUnknown<unknown>>
|
|
16
|
+
* type _Any = Assert<Not<IsUnknown<any>>>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type IsUnknown<T> = IsAny<T> extends true ? false : unknown extends T ? true : false;
|
|
20
|
+
//# sourceMappingURL=IsUnknown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsUnknown.d.ts","sourceRoot":"","sources":["../../src/type-testing/IsUnknown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IACnB,KAAK,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,OAAO,SAAS,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsUnknown.js","sourceRoot":"","sources":["../../src/type-testing/IsUnknown.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level predicate: negates a boolean predicate result.
|
|
3
|
+
*
|
|
4
|
+
* `Not<true>` is `false` and `Not<false>` is `true`. An undecided `boolean`
|
|
5
|
+
* stays `boolean`, so `Assert<Not<boolean>>` still fails.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T - The predicate result to negate.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { Assert, Equal, Not } from "@darthcav/ts-utils"
|
|
12
|
+
*
|
|
13
|
+
* type _Different = Assert<Not<Equal<string, number>>>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type Not<T extends boolean> = T extends true ? false : true;
|
|
17
|
+
//# sourceMappingURL=Not.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Not.d.ts","sourceRoot":"","sources":["../../src/type-testing/Not.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,IAAI,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Not.js","sourceRoot":"","sources":["../../src/type-testing/Not.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darthcav/ts-utils",
|
|
3
3
|
"description": "A collection of utility functions for TypeScript applications and modules",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "darthcav",
|
|
7
7
|
"url": "https://github.com/darthcav"
|
|
@@ -24,14 +24,12 @@
|
|
|
24
24
|
"!dist/__tests__"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@logtape/logtape": "2.3.
|
|
27
|
+
"@logtape/logtape": "2.3.11"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@biomejs/biome": "2.5.15",
|
|
31
31
|
"@types/node": "26.6.4",
|
|
32
|
-
"asserttt": "1.0.1",
|
|
33
32
|
"prettier": "3.9.9",
|
|
34
|
-
"shx": "0.4.0",
|
|
35
33
|
"typedoc": "0.28.20"
|
|
36
34
|
},
|
|
37
35
|
"repository": {
|
|
@@ -43,7 +41,7 @@
|
|
|
43
41
|
},
|
|
44
42
|
"scripts": {
|
|
45
43
|
"\n===== Build =====": "",
|
|
46
|
-
"clean": "
|
|
44
|
+
"clean": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\"",
|
|
47
45
|
"build": "npm run clean && tsc",
|
|
48
46
|
"prepare": "npm run build",
|
|
49
47
|
"\n===== Typecheck =====": "",
|
|
@@ -51,11 +49,11 @@
|
|
|
51
49
|
"\n===== Test =====": "",
|
|
52
50
|
"test": "node --env-file-if-exists=.env.local --experimental-test-module-mocks --test --test-reporter=spec \"src/**/*.test.ts\"",
|
|
53
51
|
"test:coverage": "node --env-file-if-exists=.env.local --experimental-test-module-mocks --experimental-test-coverage --test \"src/**/*.test.ts\"",
|
|
54
|
-
"test:coverage:lcov": "
|
|
52
|
+
"test:coverage:lcov": "node -e \"fs.mkdirSync('coverage', { recursive: true })\" && node --env-file-if-exists=.env.local --experimental-test-module-mocks --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-reporter=spec --test-reporter-destination=stdout --test \"src/**/*.test.ts\"",
|
|
55
53
|
"\n===== Linter =====": "",
|
|
56
54
|
"lint": "biome check . && prettier --check \"**/*.md\" --ignore-path .gitignore",
|
|
57
55
|
"lint:fix": "biome check --write . && prettier --write \"**/*.md\" --ignore-path .gitignore",
|
|
58
56
|
"\n===== TypeDoc =====": "",
|
|
59
|
-
"doc": "
|
|
57
|
+
"doc": "typedoc --tsconfig tsconfig.json"
|
|
60
58
|
}
|
|
61
59
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,13 @@ import { millisecondsToString } from "./millisecondsToString.ts"
|
|
|
11
11
|
import { monitorMemory } from "./monitorMemory.ts"
|
|
12
12
|
import { noop } from "./noop.ts"
|
|
13
13
|
import { type OsRelease, osRelease } from "./osRelease.ts"
|
|
14
|
+
import type { Assert } from "./type-testing/Assert.ts"
|
|
15
|
+
import type { Equal } from "./type-testing/Equal.ts"
|
|
16
|
+
import type { Extends } from "./type-testing/Extends.ts"
|
|
17
|
+
import type { IsAny } from "./type-testing/IsAny.ts"
|
|
18
|
+
import type { IsNever } from "./type-testing/IsNever.ts"
|
|
19
|
+
import type { IsUnknown } from "./type-testing/IsUnknown.ts"
|
|
20
|
+
import type { Not } from "./type-testing/Not.ts"
|
|
14
21
|
import {
|
|
15
22
|
asRuntimeObject,
|
|
16
23
|
asString,
|
|
@@ -21,10 +28,16 @@ import {
|
|
|
21
28
|
} from "./types.ts"
|
|
22
29
|
|
|
23
30
|
export {
|
|
31
|
+
type Assert,
|
|
24
32
|
asRuntimeObject,
|
|
25
33
|
asString,
|
|
34
|
+
type Equal,
|
|
35
|
+
type Extends,
|
|
26
36
|
getConsoleLogger,
|
|
27
37
|
getDummyLogger,
|
|
38
|
+
type IsAny,
|
|
39
|
+
type IsNever,
|
|
40
|
+
type IsUnknown,
|
|
28
41
|
isRuntimeObject,
|
|
29
42
|
isString,
|
|
30
43
|
type LauncherFunction,
|
|
@@ -32,6 +45,7 @@ export {
|
|
|
32
45
|
main,
|
|
33
46
|
millisecondsToString,
|
|
34
47
|
monitorMemory,
|
|
48
|
+
type Not,
|
|
35
49
|
noop,
|
|
36
50
|
type OsRelease,
|
|
37
51
|
osRelease,
|
package/src/main.ts
CHANGED
|
@@ -88,10 +88,11 @@ export type MainOptions = {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* Bootstraps an application process: logs startup information,
|
|
92
|
-
* handlers for `SIGINT
|
|
93
|
-
*
|
|
94
|
-
*
|
|
91
|
+
* Bootstraps an application process: logs startup information, optionally
|
|
92
|
+
* registers handlers for `SIGINT` and `SIGTERM` (see
|
|
93
|
+
* {@link MainOptions.defaultInterruptionHandler}), always registers handlers
|
|
94
|
+
* for `uncaughtException` and `unhandledRejection`, optionally starts memory
|
|
95
|
+
* monitoring, then runs the optional launcher function.
|
|
95
96
|
*
|
|
96
97
|
* The process title, PID, name, and `NODE_ENV` are logged at `info` level.
|
|
97
98
|
* The Node.js process options (`execArgv` and `NODE_OPTIONS`) are logged at
|
|
@@ -143,12 +144,15 @@ export type MainOptions = {
|
|
|
143
144
|
*
|
|
144
145
|
* @example Managing graceful shutdown in the application:
|
|
145
146
|
* ```ts
|
|
147
|
+
* let server: Server | undefined
|
|
146
148
|
* const teardown = main("my-app", logger, {
|
|
147
|
-
* launcher: () =>
|
|
149
|
+
* launcher: () => {
|
|
150
|
+
* server = startServer()
|
|
151
|
+
* },
|
|
148
152
|
* defaultInterruptionHandler: false,
|
|
149
153
|
* })
|
|
150
154
|
* process.once("SIGTERM", async () => {
|
|
151
|
-
* await server
|
|
155
|
+
* await server?.close()
|
|
152
156
|
* teardown()
|
|
153
157
|
* })
|
|
154
158
|
* ```
|
package/src/osRelease.ts
CHANGED
|
@@ -5,8 +5,10 @@ import type { RuntimeObject } from "./types.ts"
|
|
|
5
5
|
/**
|
|
6
6
|
* OS release information with normalized fields and optional platform-specific extras.
|
|
7
7
|
*
|
|
8
|
-
* `name`, `version`, and `arch` are always present. On Linux,
|
|
9
|
-
* `/etc/os-release
|
|
8
|
+
* `name`, `version`, and `arch` are always present. On Linux, the keys read from
|
|
9
|
+
* the os-release file (`/etc/os-release`, or `/usr/lib/os-release` as a
|
|
10
|
+
* fallback; e.g. `ID`, `PRETTY_NAME`, `ID_LIKE`) are also accessible by string
|
|
11
|
+
* index.
|
|
10
12
|
*/
|
|
11
13
|
export type OsRelease = {
|
|
12
14
|
/** Human-readable OS name, e.g. `"Ubuntu"` or `"Windows 11"`. */
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time assertion: type-checks only when `T` is exactly `true`.
|
|
3
|
+
*
|
|
4
|
+
* Wrap one of the type-level predicates of this module ({@link Equal},
|
|
5
|
+
* {@link Extends}, {@link Not}, {@link IsAny}, {@link IsNever},
|
|
6
|
+
* {@link IsUnknown}) in it and declare the result as an (unused) type alias.
|
|
7
|
+
* A predicate that evaluates to `false` or `boolean` becomes a type error that
|
|
8
|
+
* `tsc` reports. The alias resolves to `true` and, like every type, is erased
|
|
9
|
+
* at runtime.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T - The predicate result that must be `true`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import type { Assert, Equal } from "@darthcav/ts-utils"
|
|
16
|
+
*
|
|
17
|
+
* type _Ok = Assert<Equal<ReturnType<typeof parseInt>, number>>
|
|
18
|
+
* // @ts-expect-error -- `string` is not `number`
|
|
19
|
+
* type _Fails = Assert<Equal<string, number>>
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export type Assert<T extends true> = T
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level predicate: `true` when `X` and `Y` are identical types, `false`
|
|
3
|
+
* otherwise.
|
|
4
|
+
*
|
|
5
|
+
* The comparison is the one the compiler uses for type identity, so it is
|
|
6
|
+
* stricter than mutual assignability: `any` only equals `any`, and modifiers
|
|
7
|
+
* such as `readonly` and `?` must match. An intersection is not identical to
|
|
8
|
+
* the equivalent flattened object type (`{ a: 1 } & { b: 2 }` is not
|
|
9
|
+
* `{ a: 1; b: 2 }`); flatten it with a mapped type before comparing when
|
|
10
|
+
* needed.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam X - The first type to compare.
|
|
13
|
+
* @typeParam Y - The second type to compare.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import type { Assert, Equal, Not } from "@darthcav/ts-utils"
|
|
18
|
+
*
|
|
19
|
+
* type _Same = Assert<Equal<{ a: string }, { a: string }>>
|
|
20
|
+
* type _Readonly = Assert<Not<Equal<{ readonly a: string }, { a: string }>>>
|
|
21
|
+
* type _Any = Assert<Not<Equal<any, string>>>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type Equal<X, Y> =
|
|
25
|
+
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
|
|
26
|
+
? true
|
|
27
|
+
: false
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level predicate: `true` when `X` is assignable to `Y`, `false`
|
|
3
|
+
* otherwise.
|
|
4
|
+
*
|
|
5
|
+
* Unions are compared as a whole rather than member by member, so
|
|
6
|
+
* `Extends<string | number, string>` is `false`. Since `any` and `never` are
|
|
7
|
+
* assignable to every type, `Extends<any, Y>` and `Extends<never, Y>` are
|
|
8
|
+
* always `true`; use {@link Equal} to check for an exact type.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam X - The type to check.
|
|
11
|
+
* @typeParam Y - The type `X` must be assignable to.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import type { Assert, Extends, Not } from "@darthcav/ts-utils"
|
|
16
|
+
*
|
|
17
|
+
* type _Literal = Assert<Extends<"a", string>>
|
|
18
|
+
* type _Union = Assert<Not<Extends<string | number, string>>>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type Extends<X, Y> = [X] extends [Y] ? true : false
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level predicate: `true` when `T` is `any`, `false` otherwise.
|
|
3
|
+
*
|
|
4
|
+
* Useful to catch a value or return type that silently widened to `any`.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam T - The type to check.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import type { Assert, IsAny, Not } from "@darthcav/ts-utils"
|
|
11
|
+
*
|
|
12
|
+
* type _Parsed = Assert<IsAny<ReturnType<typeof JSON.parse>>>
|
|
13
|
+
* type _Typed = Assert<Not<IsAny<unknown>>>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level predicate: `true` when `T` is `never`, `false` otherwise.
|
|
3
|
+
*
|
|
4
|
+
* Useful to check that a union has been exhausted or that a conditional type
|
|
5
|
+
* filters out every member.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T - The type to check.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { Assert, IsNever } from "@darthcav/ts-utils"
|
|
12
|
+
*
|
|
13
|
+
* type _Empty = Assert<IsNever<Exclude<"a" | "b", string>>>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type IsNever<T> = [T] extends [never] ? true : false
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IsAny } from "./IsAny.ts"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type-level predicate: `true` when `T` is `unknown`, `false` otherwise
|
|
5
|
+
* (including for `any`).
|
|
6
|
+
*
|
|
7
|
+
* Useful to check that an untrusted value (e.g. parsed input) is typed as
|
|
8
|
+
* `unknown` and has to be narrowed before use.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T - The type to check.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import type { Assert, IsUnknown, Not } from "@darthcav/ts-utils"
|
|
15
|
+
*
|
|
16
|
+
* type _Unknown = Assert<IsUnknown<unknown>>
|
|
17
|
+
* type _Any = Assert<Not<IsUnknown<any>>>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type IsUnknown<T> =
|
|
21
|
+
IsAny<T> extends true ? false : unknown extends T ? true : false
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level predicate: negates a boolean predicate result.
|
|
3
|
+
*
|
|
4
|
+
* `Not<true>` is `false` and `Not<false>` is `true`. An undecided `boolean`
|
|
5
|
+
* stays `boolean`, so `Assert<Not<boolean>>` still fails.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T - The predicate result to negate.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { Assert, Equal, Not } from "@darthcav/ts-utils"
|
|
12
|
+
*
|
|
13
|
+
* type _Different = Assert<Not<Equal<string, number>>>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type Not<T extends boolean> = T extends true ? false : true
|