@bgord/bun 1.2.1 → 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/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/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/readme.md +1 -0
- package/src/prerequisites/external-api.ts +11 -3
- package/src/prerequisites/index.ts +1 -0
- package/src/prerequisites/os.ts +33 -0
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
|
@@ -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
|
+
}
|