@bgord/bun 1.1.5 → 1.1.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.
Files changed (117) hide show
  1. package/dist/healthcheck.service.d.ts +7 -4
  2. package/dist/healthcheck.service.d.ts.map +1 -1
  3. package/dist/healthcheck.service.js +1 -1
  4. package/dist/healthcheck.service.js.map +1 -1
  5. package/dist/prerequisites/binary.d.ts +2 -1
  6. package/dist/prerequisites/binary.d.ts.map +1 -1
  7. package/dist/prerequisites/binary.js +7 -5
  8. package/dist/prerequisites/binary.js.map +1 -1
  9. package/dist/prerequisites/bun.d.ts +2 -1
  10. package/dist/prerequisites/bun.d.ts.map +1 -1
  11. package/dist/prerequisites/bun.js +10 -5
  12. package/dist/prerequisites/bun.js.map +1 -1
  13. package/dist/prerequisites/clock-drift.d.ts +2 -2
  14. package/dist/prerequisites/clock-drift.d.ts.map +1 -1
  15. package/dist/prerequisites/clock-drift.js +7 -5
  16. package/dist/prerequisites/clock-drift.js.map +1 -1
  17. package/dist/prerequisites/dependency-vulnerabilities.d.ts +2 -1
  18. package/dist/prerequisites/dependency-vulnerabilities.d.ts.map +1 -1
  19. package/dist/prerequisites/dependency-vulnerabilities.js +8 -6
  20. package/dist/prerequisites/dependency-vulnerabilities.js.map +1 -1
  21. package/dist/prerequisites/directory.d.ts +3 -2
  22. package/dist/prerequisites/directory.d.ts.map +1 -1
  23. package/dist/prerequisites/directory.js +6 -4
  24. package/dist/prerequisites/directory.js.map +1 -1
  25. package/dist/prerequisites/external-api.d.ts +2 -1
  26. package/dist/prerequisites/external-api.d.ts.map +1 -1
  27. package/dist/prerequisites/external-api.js +7 -5
  28. package/dist/prerequisites/external-api.js.map +1 -1
  29. package/dist/prerequisites/jobs.d.ts +2 -1
  30. package/dist/prerequisites/jobs.d.ts.map +1 -1
  31. package/dist/prerequisites/jobs.js +6 -4
  32. package/dist/prerequisites/jobs.js.map +1 -1
  33. package/dist/prerequisites/log-file.d.ts +2 -1
  34. package/dist/prerequisites/log-file.d.ts.map +1 -1
  35. package/dist/prerequisites/log-file.js +7 -5
  36. package/dist/prerequisites/log-file.js.map +1 -1
  37. package/dist/prerequisites/mailer.d.ts +2 -1
  38. package/dist/prerequisites/mailer.d.ts.map +1 -1
  39. package/dist/prerequisites/mailer.js +6 -4
  40. package/dist/prerequisites/mailer.js.map +1 -1
  41. package/dist/prerequisites/memory.d.ts +2 -1
  42. package/dist/prerequisites/memory.d.ts.map +1 -1
  43. package/dist/prerequisites/memory.js +5 -4
  44. package/dist/prerequisites/memory.js.map +1 -1
  45. package/dist/prerequisites/node.d.ts +2 -1
  46. package/dist/prerequisites/node.d.ts.map +1 -1
  47. package/dist/prerequisites/node.js +8 -5
  48. package/dist/prerequisites/node.js.map +1 -1
  49. package/dist/prerequisites/outside-connectivity.d.ts +2 -1
  50. package/dist/prerequisites/outside-connectivity.d.ts.map +1 -1
  51. package/dist/prerequisites/outside-connectivity.js +7 -5
  52. package/dist/prerequisites/outside-connectivity.js.map +1 -1
  53. package/dist/prerequisites/port.d.ts +2 -1
  54. package/dist/prerequisites/port.d.ts.map +1 -1
  55. package/dist/prerequisites/port.js +6 -4
  56. package/dist/prerequisites/port.js.map +1 -1
  57. package/dist/prerequisites/ram.d.ts +2 -1
  58. package/dist/prerequisites/ram.d.ts.map +1 -1
  59. package/dist/prerequisites/ram.js +7 -4
  60. package/dist/prerequisites/ram.js.map +1 -1
  61. package/dist/prerequisites/running-user.d.ts +2 -1
  62. package/dist/prerequisites/running-user.d.ts.map +1 -1
  63. package/dist/prerequisites/running-user.js +6 -4
  64. package/dist/prerequisites/running-user.js.map +1 -1
  65. package/dist/prerequisites/self.d.ts +2 -1
  66. package/dist/prerequisites/self.d.ts.map +1 -1
  67. package/dist/prerequisites/self.js +5 -3
  68. package/dist/prerequisites/self.js.map +1 -1
  69. package/dist/prerequisites/space.d.ts +2 -1
  70. package/dist/prerequisites/space.d.ts.map +1 -1
  71. package/dist/prerequisites/space.js +6 -5
  72. package/dist/prerequisites/space.js.map +1 -1
  73. package/dist/prerequisites/sqlite.d.ts +2 -1
  74. package/dist/prerequisites/sqlite.d.ts.map +1 -1
  75. package/dist/prerequisites/sqlite.js +7 -5
  76. package/dist/prerequisites/sqlite.js.map +1 -1
  77. package/dist/prerequisites/ssl-certificate-expiry.d.ts +2 -1
  78. package/dist/prerequisites/ssl-certificate-expiry.d.ts.map +1 -1
  79. package/dist/prerequisites/ssl-certificate-expiry.js +9 -5
  80. package/dist/prerequisites/ssl-certificate-expiry.js.map +1 -1
  81. package/dist/prerequisites/timezone-utc.d.ts +3 -2
  82. package/dist/prerequisites/timezone-utc.d.ts.map +1 -1
  83. package/dist/prerequisites/timezone-utc.js +6 -4
  84. package/dist/prerequisites/timezone-utc.js.map +1 -1
  85. package/dist/prerequisites/translations.d.ts +2 -1
  86. package/dist/prerequisites/translations.d.ts.map +1 -1
  87. package/dist/prerequisites/translations.js +8 -6
  88. package/dist/prerequisites/translations.js.map +1 -1
  89. package/dist/prerequisites.service.d.ts +24 -14
  90. package/dist/prerequisites.service.d.ts.map +1 -1
  91. package/dist/prerequisites.service.js +15 -11
  92. package/dist/prerequisites.service.js.map +1 -1
  93. package/dist/tsconfig.tsbuildinfo +1 -1
  94. package/package.json +2 -2
  95. package/src/healthcheck.service.ts +1 -1
  96. package/src/prerequisites/binary.ts +9 -5
  97. package/src/prerequisites/bun.ts +12 -5
  98. package/src/prerequisites/clock-drift.ts +8 -6
  99. package/src/prerequisites/dependency-vulnerabilities.ts +11 -6
  100. package/src/prerequisites/directory.ts +8 -5
  101. package/src/prerequisites/external-api.ts +9 -5
  102. package/src/prerequisites/jobs.ts +8 -4
  103. package/src/prerequisites/log-file.ts +9 -5
  104. package/src/prerequisites/mailer.ts +8 -4
  105. package/src/prerequisites/memory.ts +7 -4
  106. package/src/prerequisites/node.ts +10 -5
  107. package/src/prerequisites/outside-connectivity.ts +9 -5
  108. package/src/prerequisites/port.ts +10 -4
  109. package/src/prerequisites/ram.ts +9 -4
  110. package/src/prerequisites/running-user.ts +8 -4
  111. package/src/prerequisites/self.ts +7 -3
  112. package/src/prerequisites/space.ts +8 -5
  113. package/src/prerequisites/sqlite.ts +9 -5
  114. package/src/prerequisites/ssl-certificate-expiry.ts +12 -5
  115. package/src/prerequisites/timezone-utc.ts +8 -5
  116. package/src/prerequisites/translations.ts +10 -7
  117. package/src/prerequisites.service.ts +30 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/bun",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": "Bartosz Gordon",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@axiomhq/winston": "1.3.1",
41
- "@bgord/tools": "1.1.4",
41
+ "@bgord/tools": "1.1.5",
42
42
  "@hono/ua-blocker": "0.1.15",
43
43
  "better-auth": "1.3.34",
44
44
  "croner": "9.1.0",
@@ -31,7 +31,7 @@ export class Healthcheck {
31
31
  const details: HealthcheckResultType["details"][number][] = [];
32
32
 
33
33
  for (const prerequisite of prerequisites) {
34
- details.push({ label: prerequisite.label, outcome: await prerequisite.verify() });
34
+ details.push({ label: prerequisite.label, outcome: await prerequisite.verify(deps.Clock) });
35
35
  }
36
36
 
37
37
  const ok = details.every((result) => result.outcome.status !== prereqs.PrerequisiteStatusEnum.failure)
@@ -1,5 +1,7 @@
1
1
  import bun from "bun";
2
+ import * as tools from "@bgord/tools";
2
3
  import type { BinaryType } from "../binary.vo";
4
+ import type { ClockPort } from "../clock.port";
3
5
  import * as prereqs from "../prerequisites.service";
4
6
 
5
7
  export class PrerequisiteBinary implements prereqs.Prerequisite {
@@ -15,16 +17,18 @@ export class PrerequisiteBinary implements prereqs.Prerequisite {
15
17
  this.binary = config.binary;
16
18
  }
17
19
 
18
- async verify(): Promise<prereqs.VerifyOutcome> {
20
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
21
+ const stopwatch = new tools.Stopwatch(clock.now());
22
+
19
23
  try {
20
- if (!this.enabled) return prereqs.Verification.undetermined();
24
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
21
25
 
22
26
  const result = await bun.$`which ${this.binary}`.quiet();
23
27
 
24
- if (result.exitCode === 0) return prereqs.Verification.success();
25
- return prereqs.Verification.failure({ message: `Exit code ${result.exitCode}` });
28
+ if (result.exitCode === 0) return prereqs.Verification.success(stopwatch.stop());
29
+ return prereqs.Verification.failure(stopwatch.stop(), { message: `Exit code ${result.exitCode}` });
26
30
  } catch (error) {
27
- return prereqs.Verification.failure(error as Error);
31
+ return prereqs.Verification.failure(stopwatch.stop(), error as Error);
28
32
  }
29
33
  }
30
34
  }
@@ -1,4 +1,5 @@
1
1
  import * as tools from "@bgord/tools";
2
+ import type { ClockPort } from "../clock.port";
2
3
  import * as prereqs from "../prerequisites.service";
3
4
 
4
5
  export class PrerequisiteBun implements prereqs.Prerequisite {
@@ -16,16 +17,22 @@ export class PrerequisiteBun implements prereqs.Prerequisite {
16
17
  this.current = config.current;
17
18
  }
18
19
 
19
- async verify(): Promise<prereqs.VerifyOutcome> {
20
- if (!this.enabled) return prereqs.Verification.undetermined();
20
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
21
+ const stopwatch = new tools.Stopwatch(clock.now());
22
+
23
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
21
24
 
22
25
  try {
23
26
  const current = tools.PackageVersion.fromString(this.current);
24
27
 
25
- if (current.isGreaterThanOrEqual(this.version)) return prereqs.Verification.success();
26
- return prereqs.Verification.failure({ message: `Version: ${this.version.toString()}` });
28
+ if (current.isGreaterThanOrEqual(this.version)) return prereqs.Verification.success(stopwatch.stop());
29
+ return prereqs.Verification.failure(stopwatch.stop(), {
30
+ message: `Version: ${this.version.toString()}`,
31
+ });
27
32
  } catch {
28
- return prereqs.Verification.failure({ message: `Invalid version passed: ${this.current}` });
33
+ return prereqs.Verification.failure(stopwatch.stop(), {
34
+ message: `Invalid version passed: ${this.current}`,
35
+ });
29
36
  }
30
37
  }
31
38
  }
@@ -1,4 +1,4 @@
1
- import type * as tools from "@bgord/tools";
1
+ import * as tools from "@bgord/tools";
2
2
  import type { ClockPort } from "../clock.port";
3
3
  import * as prereqs from "../prerequisites.service";
4
4
  import type { TimekeeperPort } from "../timekeeper.port";
@@ -27,17 +27,19 @@ export class PrerequisiteClockDrift implements prereqs.Prerequisite {
27
27
  this.clock = config.clock;
28
28
  }
29
29
 
30
- async verify(): Promise<prereqs.VerifyOutcome> {
31
- if (!this.enabled) return prereqs.Verification.undetermined();
30
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
31
+ const stopwatch = new tools.Stopwatch(clock.now());
32
+
33
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
32
34
 
33
35
  const now = this.clock.now();
34
36
 
35
37
  const timestamp = await this.timekeeper.get();
36
- if (!timestamp) return prereqs.Verification.undetermined();
38
+ if (!timestamp) return prereqs.Verification.undetermined(stopwatch.stop());
37
39
 
38
40
  const duration = now.difference(timestamp).toAbolute();
39
41
 
40
- if (duration.isShorterThan(this.skew)) return prereqs.Verification.success();
41
- return prereqs.Verification.failure({ message: `Difference: ${duration.seconds}s` });
42
+ if (duration.isShorterThan(this.skew)) return prereqs.Verification.success(stopwatch.stop());
43
+ return prereqs.Verification.failure(stopwatch.stop(), { message: `Difference: ${duration.seconds}s` });
42
44
  }
43
45
  }
@@ -1,4 +1,6 @@
1
1
  import bun from "bun";
2
+ import * as tools from "@bgord/tools";
3
+ import type { ClockPort } from "../clock.port";
2
4
  import * as prereqs from "../prerequisites.service";
3
5
 
4
6
  type BunAuditOutput = { [packageName: string]: { severity: "low" | "moderate" | "high" | "critical" }[] };
@@ -13,13 +15,16 @@ export class PrerequisiteDependencyVulnerabilities implements prereqs.Prerequisi
13
15
  this.enabled = config.enabled === undefined ? true : config.enabled;
14
16
  }
15
17
 
16
- async verify(): Promise<prereqs.VerifyOutcome> {
17
- if (!this.enabled) return prereqs.Verification.undetermined();
18
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
19
+ const stopwatch = new tools.Stopwatch(clock.now());
20
+
21
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
18
22
 
19
23
  try {
20
24
  const command = await bun.$`bun audit --json`.quiet();
21
25
 
22
- if (command.exitCode !== 0) return prereqs.Verification.failure({ message: "Audit failure" });
26
+ if (command.exitCode !== 0)
27
+ return prereqs.Verification.failure(stopwatch.stop(), { message: "Audit failure" });
23
28
 
24
29
  const audit = JSON.parse(command.stdout.toString()) as BunAuditOutput;
25
30
 
@@ -32,13 +37,13 @@ export class PrerequisiteDependencyVulnerabilities implements prereqs.Prerequisi
32
37
  ).length;
33
38
 
34
39
  if (criticalVulnerabilitiesCount > 0 || highVulnerabilitiesCount > 0)
35
- return prereqs.Verification.failure({
40
+ return prereqs.Verification.failure(stopwatch.stop(), {
36
41
  message: `Critical: ${criticalVulnerabilitiesCount} and high: ${highVulnerabilitiesCount}`,
37
42
  });
38
43
 
39
- return prereqs.Verification.success();
44
+ return prereqs.Verification.success(stopwatch.stop());
40
45
  } catch (error) {
41
- return prereqs.Verification.failure(error as Error);
46
+ return prereqs.Verification.failure(stopwatch.stop(), error as Error);
42
47
  }
43
48
  }
44
49
  }
@@ -1,6 +1,7 @@
1
1
  import { constants } from "node:fs";
2
2
  import fsp from "node:fs/promises";
3
- import type * as tools from "@bgord/tools";
3
+ import * as tools from "@bgord/tools";
4
+ import type { ClockPort } from "../clock.port";
4
5
  import * as prereqs from "../prerequisites.service";
5
6
 
6
7
  export class PrerequisiteDirectory implements prereqs.Prerequisite {
@@ -24,8 +25,10 @@ export class PrerequisiteDirectory implements prereqs.Prerequisite {
24
25
  this.access = config.access;
25
26
  }
26
27
 
27
- async verify(): Promise<prereqs.VerifyOutcome> {
28
- if (!this.enabled) return prereqs.Verification.undetermined();
28
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
29
+ const stopwatch = new tools.Stopwatch(clock.now());
30
+
31
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
29
32
 
30
33
  const write = this.access?.write ?? false;
31
34
  const execute = this.access?.execute ?? false;
@@ -35,9 +38,9 @@ export class PrerequisiteDirectory implements prereqs.Prerequisite {
35
38
  try {
36
39
  await fsp.access(this.directory, flags);
37
40
 
38
- return prereqs.Verification.success();
41
+ return prereqs.Verification.success(stopwatch.stop());
39
42
  } catch (error) {
40
- return prereqs.Verification.failure(error as Error);
43
+ return prereqs.Verification.failure(stopwatch.stop(), error as Error);
41
44
  }
42
45
  }
43
46
  }
@@ -1,3 +1,5 @@
1
+ import * as tools from "@bgord/tools";
2
+ import type { ClockPort } from "../clock.port";
1
3
  import * as prereqs from "../prerequisites.service";
2
4
 
3
5
  export class PrerequisiteExternalApi implements prereqs.Prerequisite {
@@ -14,16 +16,18 @@ export class PrerequisiteExternalApi implements prereqs.Prerequisite {
14
16
  this.request = config.request;
15
17
  }
16
18
 
17
- async verify(): Promise<prereqs.VerifyOutcome> {
18
- if (!this.enabled) return prereqs.Verification.undetermined();
19
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
20
+ const stopwatch = new tools.Stopwatch(clock.now());
21
+
22
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
19
23
 
20
24
  try {
21
25
  const response = await this.request();
22
26
 
23
- if (response.ok) return prereqs.Verification.success();
24
- return prereqs.Verification.failure({ message: `HTTP ${response.status}` });
27
+ if (response.ok) return prereqs.Verification.success(stopwatch.stop());
28
+ return prereqs.Verification.failure(stopwatch.stop(), { message: `HTTP ${response.status}` });
25
29
  } catch (error) {
26
- return prereqs.Verification.failure(error as Error);
30
+ return prereqs.Verification.failure(stopwatch.stop(), error as Error);
27
31
  }
28
32
  }
29
33
  }
@@ -1,3 +1,5 @@
1
+ import * as tools from "@bgord/tools";
2
+ import type { ClockPort } from "../clock.port";
1
3
  import { Jobs, type MultipleJobsType } from "../jobs.service";
2
4
  import * as prereqs from "../prerequisites.service";
3
5
 
@@ -15,9 +17,11 @@ export class PrerequisiteJobs implements prereqs.Prerequisite {
15
17
  this.jobs = config.jobs;
16
18
  }
17
19
 
18
- async verify(): Promise<prereqs.VerifyOutcome> {
19
- if (!this.enabled) return prereqs.Verification.undetermined();
20
- if (Jobs.areAllRunning(this.jobs)) return prereqs.Verification.success();
21
- return prereqs.Verification.failure();
20
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
21
+ const stopwatch = new tools.Stopwatch(clock.now());
22
+
23
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
24
+ if (Jobs.areAllRunning(this.jobs)) return prereqs.Verification.success(stopwatch.stop());
25
+ return prereqs.Verification.failure(stopwatch.stop());
22
26
  }
23
27
  }
@@ -1,3 +1,5 @@
1
+ import * as tools from "@bgord/tools";
2
+ import type { ClockPort } from "../clock.port";
1
3
  import type { LoggerWinstonProductionAdapter } from "../logger-winston-production.adapter";
2
4
  import * as prereqs from "../prerequisites.service";
3
5
 
@@ -15,17 +17,19 @@ export class PrerequisiteLogFile implements prereqs.Prerequisite {
15
17
  this.logger = config.logger;
16
18
  }
17
19
 
18
- async verify(): Promise<prereqs.VerifyOutcome> {
19
- if (!this.enabled) return prereqs.Verification.undetermined();
20
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
21
+ const stopwatch = new tools.Stopwatch(clock.now());
22
+
23
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
20
24
 
21
25
  try {
22
26
  const path = this.logger.prodLogFile;
23
27
  const result = await Bun.file(path).exists();
24
28
 
25
- if (result) return prereqs.Verification.success();
26
- return prereqs.Verification.failure({ message: `Missing file: ${path}` });
29
+ if (result) return prereqs.Verification.success(stopwatch.stop());
30
+ return prereqs.Verification.failure(stopwatch.stop(), { message: `Missing file: ${path}` });
27
31
  } catch (error) {
28
- return prereqs.Verification.failure(error as Error);
32
+ return prereqs.Verification.failure(stopwatch.stop(), error as Error);
29
33
  }
30
34
  }
31
35
  }
@@ -1,3 +1,5 @@
1
+ import * as tools from "@bgord/tools";
2
+ import type { ClockPort } from "../clock.port";
1
3
  import type { MailerPort } from "../mailer.port";
2
4
  import * as prereqs from "../prerequisites.service";
3
5
 
@@ -15,14 +17,16 @@ export class PrerequisiteMailer implements prereqs.Prerequisite {
15
17
  this.mailer = config.mailer;
16
18
  }
17
19
 
18
- async verify(): Promise<prereqs.VerifyOutcome> {
19
- if (!this.enabled) return prereqs.Verification.undetermined();
20
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
21
+ const stopwatch = new tools.Stopwatch(clock.now());
22
+
23
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
20
24
 
21
25
  try {
22
26
  await this.mailer.verify();
23
- return prereqs.Verification.success();
27
+ return prereqs.Verification.success(stopwatch.stop());
24
28
  } catch (error) {
25
- return prereqs.Verification.failure(error as Error);
29
+ return prereqs.Verification.failure(stopwatch.stop(), error as Error);
26
30
  }
27
31
  }
28
32
  }
@@ -1,4 +1,5 @@
1
1
  import * as tools from "@bgord/tools";
2
+ import type { ClockPort } from "../clock.port";
2
3
  import { MemoryConsumption } from "../memory-consumption.service";
3
4
  import * as prereqs from "../prerequisites.service";
4
5
 
@@ -16,16 +17,18 @@ export class PrerequisiteMemory implements prereqs.Prerequisite {
16
17
  this.maximum = config.maximum;
17
18
  }
18
19
 
19
- async verify(): Promise<prereqs.VerifyOutcome> {
20
- if (!this.enabled) return prereqs.Verification.undetermined();
20
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
21
+ const stopwatch = new tools.Stopwatch(clock.now());
22
+
23
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
21
24
 
22
25
  const memoryConsumption = MemoryConsumption.get();
23
26
 
24
27
  if (memoryConsumption.isGreaterThan(this.maximum)) {
25
- return prereqs.Verification.failure({
28
+ return prereqs.Verification.failure(stopwatch.stop(), {
26
29
  message: `Memory consumption: ${memoryConsumption.format(tools.Size.unit.MB)}`,
27
30
  });
28
31
  }
29
- return prereqs.Verification.success();
32
+ return prereqs.Verification.success(stopwatch.stop());
30
33
  }
31
34
  }
@@ -1,4 +1,5 @@
1
1
  import * as tools from "@bgord/tools";
2
+ import type { ClockPort } from "../clock.port";
2
3
  import * as prereqs from "../prerequisites.service";
3
4
 
4
5
  export class PrerequisiteNode implements prereqs.Prerequisite {
@@ -17,16 +18,20 @@ export class PrerequisiteNode implements prereqs.Prerequisite {
17
18
  this.current = config.current;
18
19
  }
19
20
 
20
- async verify(): Promise<prereqs.VerifyOutcome> {
21
- if (!this.enabled) return prereqs.Verification.undetermined();
21
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
22
+ const stopwatch = new tools.Stopwatch(clock.now());
23
+
24
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
22
25
 
23
26
  try {
24
27
  const current = tools.PackageVersion.fromStringWithV(this.current);
25
28
 
26
- if (current.isGreaterThanOrEqual(this.version)) return prereqs.Verification.success();
27
- return prereqs.Verification.failure({ message: `Version: ${this.current}` });
29
+ if (current.isGreaterThanOrEqual(this.version)) return prereqs.Verification.success(stopwatch.stop());
30
+ return prereqs.Verification.failure(stopwatch.stop(), { message: `Version: ${this.current}` });
28
31
  } catch {
29
- return prereqs.Verification.failure({ message: `Invalid version passed: ${this.current}` });
32
+ return prereqs.Verification.failure(stopwatch.stop(), {
33
+ message: `Invalid version passed: ${this.current}`,
34
+ });
30
35
  }
31
36
  }
32
37
  }
@@ -1,3 +1,5 @@
1
+ import * as tools from "@bgord/tools";
2
+ import type { ClockPort } from "../clock.port";
1
3
  import * as prereqs from "../prerequisites.service";
2
4
 
3
5
  export class PrerequisiteOutsideConnectivity implements prereqs.Prerequisite {
@@ -12,16 +14,18 @@ export class PrerequisiteOutsideConnectivity implements prereqs.Prerequisite {
12
14
  this.enabled = config.enabled === undefined ? true : config.enabled;
13
15
  }
14
16
 
15
- async verify(): Promise<prereqs.VerifyOutcome> {
17
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
18
+ const stopwatch = new tools.Stopwatch(clock.now());
19
+
16
20
  try {
17
- if (!this.enabled) return prereqs.Verification.undetermined();
21
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
18
22
 
19
23
  const response = await fetch(this.url, { method: "HEAD" });
20
24
 
21
- if (response.ok) return prereqs.Verification.success();
22
- return prereqs.Verification.failure({ message: `HTTP ${response.status}` });
25
+ if (response.ok) return prereqs.Verification.success(stopwatch.stop());
26
+ return prereqs.Verification.failure(stopwatch.stop(), { message: `HTTP ${response.status}` });
23
27
  } catch (error) {
24
- return prereqs.Verification.failure(error as Error);
28
+ return prereqs.Verification.failure(stopwatch.stop(), error as Error);
25
29
  }
26
30
  }
27
31
  }
@@ -1,4 +1,6 @@
1
1
  import net from "node:net";
2
+ import * as tools from "@bgord/tools";
3
+ import type { ClockPort } from "../clock.port";
2
4
  import type { PortType } from "../port.vo";
3
5
  import * as prereqs from "../prerequisites.service";
4
6
 
@@ -16,13 +18,17 @@ export class PrerequisitePort implements prereqs.Prerequisite {
16
18
  this.port = config.port;
17
19
  }
18
20
 
19
- async verify(): Promise<prereqs.VerifyOutcome> {
20
- if (!this.enabled) return prereqs.Verification.undetermined();
21
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
22
+ const stopwatch = new tools.Stopwatch(clock.now());
23
+
24
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
21
25
 
22
26
  return new Promise((resolve) => {
23
27
  const server = net.createServer();
24
- server.listen(this.port, () => server.close(() => resolve(prereqs.Verification.success())));
25
- server.on("error", () => resolve(prereqs.Verification.failure()));
28
+ server.listen(this.port, () =>
29
+ server.close(() => resolve(prereqs.Verification.success(stopwatch.stop()))),
30
+ );
31
+ server.on("error", () => resolve(prereqs.Verification.failure(stopwatch.stop())));
26
32
  });
27
33
  }
28
34
  }
@@ -1,5 +1,6 @@
1
1
  import os from "node:os";
2
2
  import * as tools from "@bgord/tools";
3
+ import type { ClockPort } from "../clock.port";
3
4
  import * as prereqs from "../prerequisites.service";
4
5
 
5
6
  export class PrerequisiteRAM implements prereqs.Prerequisite {
@@ -16,12 +17,16 @@ export class PrerequisiteRAM implements prereqs.Prerequisite {
16
17
  this.minimum = config.minimum;
17
18
  }
18
19
 
19
- async verify(): Promise<prereqs.VerifyOutcome> {
20
- if (!this.enabled) return prereqs.Verification.undetermined();
20
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
21
+ const stopwatch = new tools.Stopwatch(clock.now());
22
+
23
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
21
24
 
22
25
  const freeRAM = tools.Size.fromBytes(os.freemem());
23
26
 
24
- if (freeRAM.isGreaterThan(this.minimum)) return prereqs.Verification.success();
25
- return prereqs.Verification.failure({ message: `Free RAM: ${freeRAM.format(tools.Size.unit.MB)}` });
27
+ if (freeRAM.isGreaterThan(this.minimum)) return prereqs.Verification.success(stopwatch.stop());
28
+ return prereqs.Verification.failure(stopwatch.stop(), {
29
+ message: `Free RAM: ${freeRAM.format(tools.Size.unit.MB)}`,
30
+ });
26
31
  }
27
32
  }
@@ -1,4 +1,6 @@
1
1
  import os from "node:os";
2
+ import * as tools from "@bgord/tools";
3
+ import type { ClockPort } from "../clock.port";
2
4
  import * as prereqs from "../prerequisites.service";
3
5
 
4
6
  export class PrerequisiteRunningUser implements prereqs.Prerequisite {
@@ -15,12 +17,14 @@ export class PrerequisiteRunningUser implements prereqs.Prerequisite {
15
17
  this.username = config.username;
16
18
  }
17
19
 
18
- async verify(): Promise<prereqs.VerifyOutcome> {
19
- if (!this.enabled) return prereqs.Verification.undetermined();
20
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
21
+ const stopwatch = new tools.Stopwatch(clock.now());
22
+
23
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
20
24
 
21
25
  const current = os.userInfo().username;
22
26
 
23
- if (current === this.username) return prereqs.Verification.success();
24
- return prereqs.Verification.failure({ message: `Current user: ${current}` });
27
+ if (current === this.username) return prereqs.Verification.success(stopwatch.stop());
28
+ return prereqs.Verification.failure(stopwatch.stop(), { message: `Current user: ${current}` });
25
29
  }
26
30
  }
@@ -1,3 +1,5 @@
1
+ import * as tools from "@bgord/tools";
2
+ import type { ClockPort } from "../clock.port";
1
3
  import * as prereqs from "../prerequisites.service";
2
4
 
3
5
  export class PrerequisiteSelf implements prereqs.Prerequisite {
@@ -10,8 +12,10 @@ export class PrerequisiteSelf implements prereqs.Prerequisite {
10
12
  this.enabled = config.enabled === undefined ? true : config.enabled;
11
13
  }
12
14
 
13
- async verify(): Promise<prereqs.VerifyOutcome> {
14
- if (!this.enabled) return prereqs.Verification.undetermined();
15
- return prereqs.Verification.success();
15
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
16
+ const stopwatch = new tools.Stopwatch(clock.now());
17
+
18
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
19
+ return prereqs.Verification.success(stopwatch.stop());
16
20
  }
17
21
  }
@@ -1,5 +1,6 @@
1
1
  import path from "node:path";
2
2
  import * as tools from "@bgord/tools";
3
+ import type { ClockPort } from "../clock.port";
3
4
  import type { DiskSpaceCheckerPort } from "../disk-space-checker.port";
4
5
  import * as prereqs from "../prerequisites.service";
5
6
 
@@ -21,19 +22,21 @@ export class PrerequisiteSpace implements prereqs.Prerequisite {
21
22
  this.checker = config.checker;
22
23
  }
23
24
 
24
- async verify(): Promise<prereqs.VerifyOutcome> {
25
- if (!this.enabled) return prereqs.Verification.undetermined();
25
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
26
+ const stopwatch = new tools.Stopwatch(clock.now());
27
+
28
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
26
29
 
27
30
  try {
28
31
  const root = path.sep;
29
32
  const freeDiskSpace = await this.checker.get(root);
30
33
 
31
- if (freeDiskSpace.isGreaterThan(this.minimum)) return prereqs.Verification.success();
32
- return prereqs.Verification.failure({
34
+ if (freeDiskSpace.isGreaterThan(this.minimum)) return prereqs.Verification.success(stopwatch.stop());
35
+ return prereqs.Verification.failure(stopwatch.stop(), {
33
36
  message: `Free disk space: ${freeDiskSpace.format(tools.Size.unit.MB)}`,
34
37
  });
35
38
  } catch (error) {
36
- return prereqs.Verification.failure(error as Error);
39
+ return prereqs.Verification.failure(stopwatch.stop(), error as Error);
37
40
  }
38
41
  }
39
42
  }
@@ -1,4 +1,6 @@
1
1
  import type { Database } from "bun:sqlite";
2
+ import * as tools from "@bgord/tools";
3
+ import type { ClockPort } from "../clock.port";
2
4
  import * as prereqs from "../prerequisites.service";
3
5
 
4
6
  export class PrerequisiteSQLite implements prereqs.Prerequisite {
@@ -15,8 +17,10 @@ export class PrerequisiteSQLite implements prereqs.Prerequisite {
15
17
  this.sqlite = config.sqlite;
16
18
  }
17
19
 
18
- async verify(): Promise<prereqs.VerifyOutcome> {
19
- if (!this.enabled) return prereqs.Verification.undetermined();
20
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
21
+ const stopwatch = new tools.Stopwatch(clock.now());
22
+
23
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
20
24
 
21
25
  try {
22
26
  const integrity = this.sqlite.query("PRAGMA integrity_check;").get() as
@@ -24,11 +28,11 @@ export class PrerequisiteSQLite implements prereqs.Prerequisite {
24
28
  | undefined;
25
29
 
26
30
  if (!integrity || (integrity.integrity_check ?? "").toLowerCase() !== "ok") {
27
- return prereqs.Verification.failure({ message: "Integrity check failed" });
31
+ return prereqs.Verification.failure(stopwatch.stop(), { message: "Integrity check failed" });
28
32
  }
29
- return prereqs.Verification.success();
33
+ return prereqs.Verification.success(stopwatch.stop());
30
34
  } catch (error) {
31
- return prereqs.Verification.failure(error as Error);
35
+ return prereqs.Verification.failure(stopwatch.stop(), error as Error);
32
36
  }
33
37
  }
34
38
  }
@@ -1,4 +1,6 @@
1
+ import * as tools from "@bgord/tools";
1
2
  import type { CertificateInspectorPort } from "../certificate-inspector.port";
3
+ import type { ClockPort } from "../clock.port";
2
4
  import * as prereqs from "../prerequisites.service";
3
5
 
4
6
  export class PrerequisiteSSLCertificateExpiry implements prereqs.Prerequisite {
@@ -25,15 +27,20 @@ export class PrerequisiteSSLCertificateExpiry implements prereqs.Prerequisite {
25
27
  this.inspector = config.inspector;
26
28
  }
27
29
 
28
- async verify(): Promise<prereqs.VerifyOutcome> {
29
- if (!this.enabled) return prereqs.Verification.undetermined();
30
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
31
+ const stopwatch = new tools.Stopwatch(clock.now());
32
+
33
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
30
34
 
31
35
  const result = await this.inspector.inspect(this.host);
32
36
 
33
- if (!result.success) return prereqs.Verification.failure({ message: "Certificate unavailable" });
37
+ if (!result.success)
38
+ return prereqs.Verification.failure(stopwatch.stop(), { message: "Certificate unavailable" });
34
39
  if (result.daysRemaining <= this.days) {
35
- return prereqs.Verification.failure({ message: `${result.daysRemaining} days remaining` });
40
+ return prereqs.Verification.failure(stopwatch.stop(), {
41
+ message: `${result.daysRemaining} days remaining`,
42
+ });
36
43
  }
37
- return prereqs.Verification.success();
44
+ return prereqs.Verification.success(stopwatch.stop());
38
45
  }
39
46
  }
@@ -1,5 +1,6 @@
1
- import type * as tools from "@bgord/tools";
1
+ import * as tools from "@bgord/tools";
2
2
  import { z } from "zod/v4";
3
+ import type { ClockPort } from "../clock.port";
3
4
  import * as prereqs from "../prerequisites.service";
4
5
 
5
6
  export const TimezoneUtc = z.literal("UTC");
@@ -18,12 +19,14 @@ export class PrerequisiteTimezoneUTC implements prereqs.Prerequisite {
18
19
  this.timezone = config.timezone;
19
20
  }
20
21
 
21
- async verify(): Promise<prereqs.VerifyOutcome> {
22
- if (!this.enabled) return prereqs.Verification.undetermined();
22
+ async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
23
+ const stopwatch = new tools.Stopwatch(clock.now());
24
+
25
+ if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
23
26
 
24
27
  const result = TimezoneUtc.safeParse(this.timezone);
25
28
 
26
- if (result.success) return prereqs.Verification.success();
27
- return prereqs.Verification.failure({ message: `Timezone: ${this.timezone}` });
29
+ if (result.success) return prereqs.Verification.success(stopwatch.stop());
30
+ return prereqs.Verification.failure(stopwatch.stop(), { message: `Timezone: ${this.timezone}` });
28
31
  }
29
32
  }