@bgord/bun 1.2.0 → 1.2.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/dist/prerequisites/clock-drift.d.ts +1 -1
- package/dist/prerequisites/clock-drift.d.ts.map +1 -1
- package/dist/prerequisites/clock-drift.js +2 -1
- package/dist/prerequisites/clock-drift.js.map +1 -1
- package/dist/prerequisites/external-api.d.ts +4 -1
- package/dist/prerequisites/external-api.d.ts.map +1 -1
- package/dist/prerequisites/external-api.js +4 -1
- package/dist/prerequisites/external-api.js.map +1 -1
- package/dist/prerequisites/index.d.ts +1 -0
- package/dist/prerequisites/index.d.ts.map +1 -1
- package/dist/prerequisites/index.js +1 -0
- package/dist/prerequisites/index.js.map +1 -1
- package/dist/prerequisites/os.d.ts +13 -0
- package/dist/prerequisites/os.d.ts.map +1 -0
- package/dist/prerequisites/os.js +27 -0
- package/dist/prerequisites/os.js.map +1 -0
- package/dist/prerequisites/space.d.ts +1 -1
- package/dist/prerequisites/space.d.ts.map +1 -1
- package/dist/prerequisites/space.js +2 -1
- package/dist/prerequisites/space.js.map +1 -1
- package/dist/prerequisites/translations.d.ts +4 -4
- package/dist/prerequisites/translations.d.ts.map +1 -1
- package/dist/prerequisites/translations.js +6 -5
- package/dist/prerequisites/translations.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/readme.md +1 -0
- package/src/prerequisites/clock-drift.ts +3 -2
- package/src/prerequisites/external-api.ts +11 -3
- package/src/prerequisites/index.ts +1 -0
- package/src/prerequisites/os.ts +33 -0
- package/src/prerequisites/space.ts +3 -2
- package/src/prerequisites/translations.ts +8 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/bun",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"preinstall": "bunx only-allow bun"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@biomejs/biome": "2.3.
|
|
23
|
+
"@biomejs/biome": "2.3.4",
|
|
24
24
|
"@commitlint/cli": "20.1.0",
|
|
25
25
|
"@commitlint/config-conventional": "20.0.0",
|
|
26
26
|
"@types/bun": "1.3.1",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@types/mime-types": "3.0.1",
|
|
29
29
|
"@types/nodemailer": "7.0.3",
|
|
30
30
|
"@types/yazl": "3.3.0",
|
|
31
|
-
"cspell": "9.
|
|
31
|
+
"cspell": "9.3.0",
|
|
32
32
|
"knip": "5.67.1",
|
|
33
33
|
"lefthook": "2.0.2",
|
|
34
34
|
"only-allow": "1.2.1",
|
package/readme.md
CHANGED
|
@@ -2,6 +2,7 @@ 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";
|
|
5
|
+
import { TimekeeperGoogleAdapter } from "../timekeeper-google.adapter";
|
|
5
6
|
import { Timeout } from "../timeout.service";
|
|
6
7
|
|
|
7
8
|
export class PrerequisiteClockDrift implements prereqs.Prerequisite {
|
|
@@ -16,7 +17,7 @@ export class PrerequisiteClockDrift implements prereqs.Prerequisite {
|
|
|
16
17
|
constructor(
|
|
17
18
|
config: prereqs.PrerequisiteConfigType & {
|
|
18
19
|
skew: tools.Duration;
|
|
19
|
-
timekeeper
|
|
20
|
+
timekeeper?: TimekeeperPort;
|
|
20
21
|
timeout?: tools.Duration;
|
|
21
22
|
},
|
|
22
23
|
) {
|
|
@@ -24,7 +25,7 @@ export class PrerequisiteClockDrift implements prereqs.Prerequisite {
|
|
|
24
25
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
25
26
|
|
|
26
27
|
this.skew = config.skew;
|
|
27
|
-
this.timekeeper = config.timekeeper;
|
|
28
|
+
this.timekeeper = config.timekeeper ?? new TimekeeperGoogleAdapter();
|
|
28
29
|
this.timeout = config.timeout ?? tools.Duration.Seconds(2);
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import * as tools from "@bgord/tools";
|
|
2
2
|
import type { ClockPort } from "../clock.port";
|
|
3
3
|
import * as prereqs from "../prerequisites.service";
|
|
4
|
+
import { Timeout } from "../timeout.service";
|
|
4
5
|
|
|
5
6
|
export class PrerequisiteExternalApi implements prereqs.Prerequisite {
|
|
6
7
|
readonly kind = "external-api";
|
|
7
8
|
readonly label: prereqs.PrerequisiteLabelType;
|
|
8
9
|
readonly enabled?: boolean = true;
|
|
9
10
|
|
|
10
|
-
private readonly request: () => Promise<Response>;
|
|
11
|
+
private readonly request: (signal: AbortSignal) => Promise<Response>;
|
|
12
|
+
readonly timeout: tools.Duration;
|
|
11
13
|
|
|
12
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
|
+
config: prereqs.PrerequisiteConfigType & {
|
|
16
|
+
request: (signal: AbortSignal) => Promise<Response>;
|
|
17
|
+
timeout?: tools.Duration;
|
|
18
|
+
},
|
|
19
|
+
) {
|
|
13
20
|
this.label = config.label;
|
|
14
21
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
15
22
|
|
|
16
23
|
this.request = config.request;
|
|
24
|
+
this.timeout = config.timeout ?? tools.Duration.Seconds(2);
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
|
|
@@ -22,7 +30,7 @@ export class PrerequisiteExternalApi implements prereqs.Prerequisite {
|
|
|
22
30
|
if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
|
|
23
31
|
|
|
24
32
|
try {
|
|
25
|
-
const response = await this.request();
|
|
33
|
+
const response = await Timeout.cancellable((signal: AbortSignal) => this.request(signal), this.timeout);
|
|
26
34
|
|
|
27
35
|
if (response.ok) return prereqs.Verification.success(stopwatch.stop());
|
|
28
36
|
return prereqs.Verification.failure(stopwatch.stop(), { message: `HTTP ${response.status}` });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import * as tools from "@bgord/tools";
|
|
3
|
+
import type { ClockPort } from "../clock.port";
|
|
4
|
+
import * as prereqs from "../prerequisites.service";
|
|
5
|
+
|
|
6
|
+
export class PrerequisiteOs implements prereqs.Prerequisite {
|
|
7
|
+
readonly kind = "os";
|
|
8
|
+
readonly label: prereqs.PrerequisiteLabelType;
|
|
9
|
+
readonly enabled?: boolean = true;
|
|
10
|
+
|
|
11
|
+
private readonly accepted: string[];
|
|
12
|
+
|
|
13
|
+
constructor(config: prereqs.PrerequisiteConfigType & { accepted: string[] }) {
|
|
14
|
+
this.label = config.label;
|
|
15
|
+
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
16
|
+
this.accepted = config.accepted;
|
|
17
|
+
}
|
|
18
|
+
|
|
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());
|
|
23
|
+
|
|
24
|
+
const type = os.type();
|
|
25
|
+
|
|
26
|
+
if (this.accepted.map((type) => type.toLowerCase()).includes(type.toLowerCase())) {
|
|
27
|
+
return prereqs.Verification.success(stopwatch.stop());
|
|
28
|
+
}
|
|
29
|
+
return prereqs.Verification.failure(stopwatch.stop(), {
|
|
30
|
+
message: `Unacceptable os: ${this.accepted.join(", ")}`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -2,6 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
import * as tools from "@bgord/tools";
|
|
3
3
|
import type { ClockPort } from "../clock.port";
|
|
4
4
|
import type { DiskSpaceCheckerPort } from "../disk-space-checker.port";
|
|
5
|
+
import { DiskSpaceCheckerBunAdapter } from "../disk-space-checker-bun.adapter";
|
|
5
6
|
import * as prereqs from "../prerequisites.service";
|
|
6
7
|
|
|
7
8
|
export class PrerequisiteSpace implements prereqs.Prerequisite {
|
|
@@ -13,13 +14,13 @@ export class PrerequisiteSpace implements prereqs.Prerequisite {
|
|
|
13
14
|
private readonly checker: DiskSpaceCheckerPort;
|
|
14
15
|
|
|
15
16
|
constructor(
|
|
16
|
-
config: prereqs.PrerequisiteConfigType & { minimum: tools.Size; checker
|
|
17
|
+
config: prereqs.PrerequisiteConfigType & { minimum: tools.Size; checker?: DiskSpaceCheckerPort },
|
|
17
18
|
) {
|
|
18
19
|
this.label = config.label;
|
|
19
20
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
20
21
|
|
|
21
22
|
this.minimum = config.minimum;
|
|
22
|
-
this.checker = config.checker;
|
|
23
|
+
this.checker = config.checker ?? new DiskSpaceCheckerBunAdapter();
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
|
|
@@ -5,6 +5,7 @@ import type { ClockPort } from "../clock.port";
|
|
|
5
5
|
import type * as types from "../i18n.service";
|
|
6
6
|
import { I18n } from "../i18n.service";
|
|
7
7
|
import type { JsonFileReaderPort } from "../json-file-reader.port";
|
|
8
|
+
import { JsonFileReaderBunForgivingAdapter } from "../json-file-reader-bun-forgiving.adapter";
|
|
8
9
|
import type { LoggerPort } from "../logger.port";
|
|
9
10
|
import * as prereqs from "../prerequisites.service";
|
|
10
11
|
|
|
@@ -22,15 +23,15 @@ export class PrerequisiteTranslations implements prereqs.Prerequisite {
|
|
|
22
23
|
private readonly translationsPath?: typeof I18n.DEFAULT_TRANSLATIONS_PATH;
|
|
23
24
|
private readonly supportedLanguages: types.I18nConfigType["supportedLanguages"];
|
|
24
25
|
|
|
25
|
-
private readonly
|
|
26
|
-
private readonly
|
|
26
|
+
private readonly logger: LoggerPort;
|
|
27
|
+
private readonly jsonFileReader: JsonFileReaderPort;
|
|
27
28
|
|
|
28
29
|
constructor(
|
|
29
30
|
config: prereqs.PrerequisiteConfigType & {
|
|
30
31
|
translationsPath?: typeof I18n.DEFAULT_TRANSLATIONS_PATH;
|
|
31
32
|
supportedLanguages: types.I18nConfigType["supportedLanguages"];
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
logger: LoggerPort;
|
|
34
|
+
jsonFileReader?: JsonFileReaderPort;
|
|
34
35
|
},
|
|
35
36
|
) {
|
|
36
37
|
this.label = config.label;
|
|
@@ -39,8 +40,8 @@ export class PrerequisiteTranslations implements prereqs.Prerequisite {
|
|
|
39
40
|
this.translationsPath = config.translationsPath;
|
|
40
41
|
this.supportedLanguages = config.supportedLanguages;
|
|
41
42
|
|
|
42
|
-
this.
|
|
43
|
-
this.
|
|
43
|
+
this.logger = config.logger;
|
|
44
|
+
this.jsonFileReader = config.jsonFileReader ?? new JsonFileReaderBunForgivingAdapter();
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
|
|
@@ -51,7 +52,7 @@ export class PrerequisiteTranslations implements prereqs.Prerequisite {
|
|
|
51
52
|
const translationsPath = this.translationsPath ?? I18n.DEFAULT_TRANSLATIONS_PATH;
|
|
52
53
|
|
|
53
54
|
const supportedLanguages = Object.keys(this.supportedLanguages);
|
|
54
|
-
const i18n = new I18n({ Logger: this.
|
|
55
|
+
const i18n = new I18n({ Logger: this.logger, JsonFileReader: this.jsonFileReader });
|
|
55
56
|
|
|
56
57
|
try {
|
|
57
58
|
await fsp.access(translationsPath, constants.R_OK);
|