@bgord/bun 1.0.2 → 1.0.4
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/cache-response.middleware.d.ts.map +1 -1
- package/dist/cache-response.middleware.js +1 -2
- package/dist/cache-response.middleware.js.map +1 -1
- package/dist/disk-space-checker-bun.adapter.d.ts +6 -0
- package/dist/disk-space-checker-bun.adapter.d.ts.map +1 -0
- package/dist/disk-space-checker-bun.adapter.js +14 -0
- package/dist/disk-space-checker-bun.adapter.js.map +1 -0
- package/dist/disk-space-checker-noop.adapter.d.ts +8 -0
- package/dist/disk-space-checker-noop.adapter.d.ts.map +1 -0
- package/dist/disk-space-checker-noop.adapter.js +10 -0
- package/dist/disk-space-checker-noop.adapter.js.map +1 -0
- package/dist/disk-space-checker-package.adapter.d.ts +6 -0
- package/dist/disk-space-checker-package.adapter.d.ts.map +1 -0
- package/dist/disk-space-checker-package.adapter.js +9 -0
- package/dist/disk-space-checker-package.adapter.js.map +1 -0
- package/dist/disk-space-checker.port.d.ts +5 -0
- package/dist/disk-space-checker.port.d.ts.map +1 -0
- package/dist/disk-space-checker.port.js +2 -0
- package/dist/disk-space-checker.port.js.map +1 -0
- package/dist/http-logger.middleware.d.ts.map +1 -1
- package/dist/http-logger.middleware.js +5 -4
- package/dist/http-logger.middleware.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/prerequisites/space.d.ts +3 -0
- package/dist/prerequisites/space.d.ts.map +1 -1
- package/dist/prerequisites/space.js +4 -4
- package/dist/prerequisites/space.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/readme.md +4 -0
- package/src/cache-response.middleware.ts +1 -2
- package/src/disk-space-checker-bun.adapter.ts +18 -0
- package/src/disk-space-checker-noop.adapter.ts +10 -0
- package/src/disk-space-checker-package.adapter.ts +11 -0
- package/src/disk-space-checker.port.ts +5 -0
- package/src/http-logger.middleware.ts +14 -4
- package/src/index.ts +4 -0
- package/src/prerequisites/space.ts +9 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/bun",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -20,17 +20,17 @@
|
|
|
20
20
|
"preinstall": "bunx only-allow bun"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@biomejs/biome": "2.
|
|
23
|
+
"@biomejs/biome": "2.3.0",
|
|
24
24
|
"@commitlint/cli": "20.1.0",
|
|
25
25
|
"@commitlint/config-conventional": "20.0.0",
|
|
26
|
-
"@types/bun": "1.3.
|
|
26
|
+
"@types/bun": "1.3.1",
|
|
27
27
|
"@types/lodash": "4.17.20",
|
|
28
28
|
"@types/mime-types": "3.0.1",
|
|
29
|
-
"@types/nodemailer": "7.0.
|
|
29
|
+
"@types/nodemailer": "7.0.3",
|
|
30
30
|
"@types/yazl": "3.3.0",
|
|
31
31
|
"cspell": "9.2.2",
|
|
32
|
-
"knip": "5.66.
|
|
33
|
-
"lefthook": "2.0.
|
|
32
|
+
"knip": "5.66.3",
|
|
33
|
+
"lefthook": "2.0.1",
|
|
34
34
|
"only-allow": "1.2.1",
|
|
35
35
|
"shellcheck": "4.1.0",
|
|
36
36
|
"typescript": "5.9.3",
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@axiomhq/winston": "1.3.1",
|
|
41
|
-
"@bgord/tools": "1.0.
|
|
42
|
-
"@hono/ua-blocker": "0.1.
|
|
43
|
-
"better-auth": "1.3.
|
|
41
|
+
"@bgord/tools": "1.0.2",
|
|
42
|
+
"@hono/ua-blocker": "0.1.15",
|
|
43
|
+
"better-auth": "1.3.32",
|
|
44
44
|
"check-disk-space": "3.4.0",
|
|
45
45
|
"croner": "9.1.0",
|
|
46
46
|
"csv": "6.4.1",
|
|
47
47
|
"hcaptcha": "0.2.0",
|
|
48
|
-
"hono": "4.10.
|
|
48
|
+
"hono": "4.10.3",
|
|
49
49
|
"lodash": "4.17.21",
|
|
50
50
|
"mime-types": "3.0.1",
|
|
51
51
|
"node-cache": "5.1.2",
|
package/readme.md
CHANGED
|
@@ -55,6 +55,10 @@ src/
|
|
|
55
55
|
├── csv-stringifier.adapter.ts
|
|
56
56
|
├── csv-stringifier.port.ts
|
|
57
57
|
├── decorators.service.ts
|
|
58
|
+
├── disk-space-checker-bun.adapter.ts
|
|
59
|
+
├── disk-space-checker-noop.adapter.ts
|
|
60
|
+
├── disk-space-checker-package.adapter.ts
|
|
61
|
+
├── disk-space-checker.port.ts
|
|
58
62
|
├── dispatching-event-store.ts
|
|
59
63
|
├── env-validator.service.ts
|
|
60
64
|
├── etag-extractor.middleware.ts
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createMiddleware } from "hono/factory";
|
|
2
|
-
import _ from "lodash";
|
|
3
2
|
import type NodeCache from "node-cache";
|
|
4
3
|
import { CacheHitEnum } from "./cache-resolver.service";
|
|
5
4
|
|
|
@@ -9,7 +8,7 @@ export class CacheResponse {
|
|
|
9
8
|
constructor(private readonly cache: NodeCache) {}
|
|
10
9
|
|
|
11
10
|
handle = createMiddleware(async (c, next) => {
|
|
12
|
-
const url =
|
|
11
|
+
const url = c.req.url;
|
|
13
12
|
|
|
14
13
|
if (this.cache.has(url)) {
|
|
15
14
|
c.res.headers.set(CacheResponse.CACHE_HIT_HEADER, CacheHitEnum.hit);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import bun from "bun";
|
|
2
|
+
import * as tools from "@bgord/tools";
|
|
3
|
+
import type { DiskSpaceCheckerPort } from "./disk-space-checker.port";
|
|
4
|
+
|
|
5
|
+
// Example command output:
|
|
6
|
+
// Filesystem 1024-blocks Used Available Capacity Mounted on
|
|
7
|
+
// /dev/disk3s1s1 239362496 10997540 43650948 21% /
|
|
8
|
+
|
|
9
|
+
export class DiskSpaceCheckerBunAdapter implements DiskSpaceCheckerPort {
|
|
10
|
+
async get(root: string) {
|
|
11
|
+
const stdout = await bun.$`df -kP ${root}`.text();
|
|
12
|
+
|
|
13
|
+
const line = stdout.trim().split(/\r?\n/)[1]; // Select the second line
|
|
14
|
+
const free = Number(line?.trim().split(/\s+/)[3]); // Get the fourth block
|
|
15
|
+
|
|
16
|
+
return tools.Size.fromKb(free);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as tools from "@bgord/tools";
|
|
2
|
+
import type { DiskSpaceCheckerPort } from "./disk-space-checker.port";
|
|
3
|
+
|
|
4
|
+
export class DiskSpaceCheckerNoopAdapter implements DiskSpaceCheckerPort {
|
|
5
|
+
constructor(private readonly value: tools.Size) {}
|
|
6
|
+
|
|
7
|
+
async get(_root: string) {
|
|
8
|
+
return this.value;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import checkDiskSpace from "check-disk-space";
|
|
3
|
+
import type { DiskSpaceCheckerPort } from "./disk-space-checker.port";
|
|
4
|
+
|
|
5
|
+
export class DiskSpaceCheckerPackageAdapter implements DiskSpaceCheckerPort {
|
|
6
|
+
async get(root: string) {
|
|
7
|
+
const result = await checkDiskSpace(root);
|
|
8
|
+
|
|
9
|
+
return tools.Size.fromBytes(result.free);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as tools from "@bgord/tools";
|
|
2
2
|
import { createMiddleware } from "hono/factory";
|
|
3
|
-
import _ from "lodash";
|
|
4
3
|
import { CacheHitEnum } from "./cache-resolver.service";
|
|
5
4
|
import { CacheResponse } from "./cache-response.middleware";
|
|
6
5
|
import { ClientFromHonoAdapter } from "./client-from-hono.adapter";
|
|
@@ -50,8 +49,11 @@ export class HttpLogger {
|
|
|
50
49
|
|
|
51
50
|
const httpRequestBeforeMetadata = {
|
|
52
51
|
params: context.req.param(),
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
headers: Object.fromEntries(
|
|
53
|
+
Object.entries(request.headers.toJSON()).filter(
|
|
54
|
+
([header]) => !UNINFORMATIVE_HEADERS.includes(header),
|
|
55
|
+
),
|
|
56
|
+
),
|
|
55
57
|
body: await HttpLogger.parseJSON(request),
|
|
56
58
|
query: context.req.queries(),
|
|
57
59
|
};
|
|
@@ -64,7 +66,15 @@ export class HttpLogger {
|
|
|
64
66
|
method: request.method,
|
|
65
67
|
url: request.url,
|
|
66
68
|
client,
|
|
67
|
-
metadata:
|
|
69
|
+
metadata: Object.fromEntries(
|
|
70
|
+
Object.entries(httpRequestBeforeMetadata).filter(
|
|
71
|
+
([, value]) =>
|
|
72
|
+
value !== undefined &&
|
|
73
|
+
value !== null &&
|
|
74
|
+
typeof value === "object" &&
|
|
75
|
+
Object.keys(value).length > 0,
|
|
76
|
+
),
|
|
77
|
+
),
|
|
68
78
|
});
|
|
69
79
|
|
|
70
80
|
const stopwatch = new tools.Stopwatch(deps.Clock.nowMs());
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,10 @@ export * from "./correlation-storage.service";
|
|
|
29
29
|
export * from "./csv-stringifier.adapter";
|
|
30
30
|
export * from "./csv-stringifier.port";
|
|
31
31
|
export * from "./decorators.service";
|
|
32
|
+
export * from "./disk-space-checker.port";
|
|
33
|
+
export * from "./disk-space-checker-bun.adapter";
|
|
34
|
+
export * from "./disk-space-checker-noop.adapter";
|
|
35
|
+
export * from "./disk-space-checker-package.adapter";
|
|
32
36
|
export * from "./dispatching-event-store";
|
|
33
37
|
export * from "./env-validator.service";
|
|
34
38
|
export * from "./etag-extractor.middleware";
|
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import * as tools from "@bgord/tools";
|
|
3
|
-
import
|
|
3
|
+
import type { DiskSpaceCheckerPort } from "../disk-space-checker.port";
|
|
4
4
|
import * as prereqs from "../prerequisites.service";
|
|
5
5
|
|
|
6
6
|
export class PrerequisiteSpace implements prereqs.Prerequisite {
|
|
7
7
|
readonly kind = "space";
|
|
8
8
|
readonly label: prereqs.PrerequisiteLabelType;
|
|
9
9
|
readonly enabled?: boolean = true;
|
|
10
|
+
|
|
10
11
|
private readonly minimum: tools.Size;
|
|
12
|
+
private readonly checker: DiskSpaceCheckerPort;
|
|
11
13
|
|
|
12
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
|
+
config: prereqs.PrerequisiteConfigType & { minimum: tools.Size; checker: DiskSpaceCheckerPort },
|
|
16
|
+
) {
|
|
13
17
|
this.label = config.label;
|
|
14
18
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
15
19
|
|
|
16
20
|
this.minimum = config.minimum;
|
|
21
|
+
this.checker = config.checker;
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
async verify(): Promise<prereqs.VerifyOutcome> {
|
|
20
25
|
if (!this.enabled) return prereqs.Verification.undetermined();
|
|
21
26
|
|
|
22
27
|
try {
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const freeDiskSpace = tools.Size.fromBytes(bytes.free);
|
|
28
|
+
const root = path.sep;
|
|
29
|
+
const freeDiskSpace = await this.checker.get(root);
|
|
26
30
|
|
|
27
31
|
if (freeDiskSpace.isGreaterThan(this.minimum)) return prereqs.Verification.success();
|
|
28
32
|
return prereqs.Verification.failure({
|