@bgord/bun 0.5.0 → 0.7.0
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/api-key-shield.d.ts +2 -2
- package/dist/api-key-shield.d.ts.map +1 -1
- package/dist/api-version.d.ts.map +1 -1
- package/dist/api-version.js +2 -2
- package/dist/api-version.js.map +1 -1
- package/dist/auth-shield.d.ts +11 -10
- package/dist/auth-shield.d.ts.map +1 -1
- package/dist/auth-shield.js +6 -13
- package/dist/auth-shield.js.map +1 -1
- package/dist/basic-auth.d.ts +6 -0
- package/dist/basic-auth.d.ts.map +1 -0
- package/dist/basic-auth.js +4 -0
- package/dist/basic-auth.js.map +1 -0
- package/dist/build-info-repository.d.ts +5 -3
- package/dist/build-info-repository.d.ts.map +1 -0
- package/dist/build-info-repository.js +18 -0
- package/dist/build-info-repository.js.map +1 -0
- package/dist/cache-resolver.d.ts +46 -0
- package/dist/cache-resolver.d.ts.map +1 -0
- package/dist/cache-resolver.js +44 -0
- package/dist/cache-resolver.js.map +1 -0
- package/dist/cache-response.d.ts +0 -4
- package/dist/cache-response.d.ts.map +1 -1
- package/dist/cache-response.js +2 -6
- package/dist/cache-response.js.map +1 -1
- package/dist/cache-static-files.js +3 -3
- package/dist/cache-static-files.js.map +1 -1
- package/dist/context.d.ts +7 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/correlation-id.d.ts +4 -0
- package/dist/correlation-id.d.ts.map +1 -0
- package/dist/correlation-id.js +3 -0
- package/dist/correlation-id.js.map +1 -0
- package/dist/download-file.d.ts +5 -4
- package/dist/download-file.d.ts.map +1 -1
- package/dist/env-validator.d.ts +21 -0
- package/dist/env-validator.d.ts.map +1 -0
- package/dist/env-validator.js +28 -0
- package/dist/env-validator.js.map +1 -0
- package/dist/etag-extractor.d.ts +3 -8
- package/dist/etag-extractor.d.ts.map +1 -1
- package/dist/etag-extractor.js +3 -18
- package/dist/etag-extractor.js.map +1 -1
- package/dist/file-uploader.d.ts +2 -2
- package/dist/file-uploader.d.ts.map +1 -1
- package/dist/file-uploader.js +3 -3
- package/dist/file-uploader.js.map +1 -1
- package/dist/graceful-shutdown.d.ts.map +1 -1
- package/dist/graceful-shutdown.js +3 -3
- package/dist/graceful-shutdown.js.map +1 -1
- package/dist/healthcheck.d.ts +12 -11
- package/dist/healthcheck.d.ts.map +1 -1
- package/dist/healthcheck.js +15 -11
- package/dist/healthcheck.js.map +1 -1
- package/dist/http-logger.d.ts +2 -2
- package/dist/http-logger.d.ts.map +1 -1
- package/dist/http-logger.js +4 -3
- package/dist/http-logger.js.map +1 -1
- package/dist/i18n.d.ts +10 -15
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +10 -25
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +28 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -7
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +1 -0
- package/dist/jobs.d.ts.map +1 -0
- package/dist/jobs.js +72 -0
- package/dist/jobs.js.map +1 -0
- package/dist/logger.d.ts +23 -7
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +87 -0
- package/dist/logger.js.map +1 -0
- package/dist/mailer.d.ts +23 -1
- package/dist/mailer.d.ts.map +1 -0
- package/dist/mailer.js +33 -0
- package/dist/mailer.js.map +1 -0
- package/dist/memory-consumption.d.ts +3 -2
- package/dist/memory-consumption.d.ts.map +1 -0
- package/dist/memory-consumption.js +8 -0
- package/dist/memory-consumption.js.map +1 -0
- package/dist/new-uuid.d.ts +4 -0
- package/dist/new-uuid.d.ts.map +1 -0
- package/dist/new-uuid.js +6 -0
- package/dist/new-uuid.js.map +1 -0
- package/dist/node-env.vo.d.ts +9 -0
- package/dist/node-env.vo.d.ts.map +1 -0
- package/dist/node-env.vo.js +10 -0
- package/dist/node-env.vo.js.map +1 -0
- package/dist/passwords.d.ts +21 -0
- package/dist/passwords.d.ts.map +1 -0
- package/dist/passwords.js +42 -0
- package/dist/passwords.js.map +1 -0
- package/dist/path.d.ts +4 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +3 -0
- package/dist/path.js.map +1 -0
- package/dist/port.d.ts +4 -0
- package/dist/port.d.ts.map +1 -0
- package/dist/port.js +3 -0
- package/dist/port.js.map +1 -0
- package/dist/prerequisites/binary.d.ts +4 -3
- package/dist/prerequisites/binary.d.ts.map +1 -0
- package/dist/prerequisites/binary.js +29 -0
- package/dist/prerequisites/binary.js.map +1 -0
- package/dist/prerequisites/bun.d.ts +7 -4
- package/dist/prerequisites/bun.d.ts.map +1 -0
- package/dist/prerequisites/bun.js +18 -0
- package/dist/prerequisites/bun.js.map +1 -0
- package/dist/prerequisites/index.d.ts +17 -0
- package/dist/prerequisites/index.d.ts.map +1 -0
- package/dist/prerequisites/index.js +17 -0
- package/dist/prerequisites/index.js.map +1 -0
- package/dist/prerequisites/jobs.d.ts +4 -2
- package/dist/prerequisites/jobs.d.ts.map +1 -0
- package/dist/prerequisites/jobs.js +16 -0
- package/dist/prerequisites/jobs.js.map +1 -0
- package/dist/prerequisites/log-file.d.ts +15 -0
- package/dist/prerequisites/log-file.d.ts.map +1 -0
- package/dist/prerequisites/log-file.js +22 -0
- package/dist/prerequisites/log-file.js.map +1 -0
- package/dist/prerequisites/mailer.d.ts +4 -2
- package/dist/prerequisites/mailer.d.ts.map +1 -0
- package/dist/prerequisites/mailer.js +21 -0
- package/dist/prerequisites/mailer.js.map +1 -0
- package/dist/prerequisites/memory.d.ts +6 -4
- package/dist/prerequisites/memory.d.ts.map +1 -0
- package/dist/prerequisites/memory.js +20 -0
- package/dist/prerequisites/memory.js.map +1 -0
- package/dist/prerequisites/node.d.ts +6 -4
- package/dist/prerequisites/node.d.ts.map +1 -0
- package/dist/prerequisites/node.js +23 -0
- package/dist/prerequisites/node.js.map +1 -0
- package/dist/prerequisites/outside-connectivity.d.ts +4 -2
- package/dist/prerequisites/outside-connectivity.d.ts.map +1 -0
- package/dist/prerequisites/outside-connectivity.js +21 -0
- package/dist/prerequisites/outside-connectivity.js.map +1 -0
- package/dist/prerequisites/path.d.ts +4 -2
- package/dist/prerequisites/path.d.ts.map +1 -0
- package/dist/prerequisites/path.js +26 -0
- package/dist/prerequisites/path.js.map +1 -0
- package/dist/prerequisites/port.d.ts +6 -4
- package/dist/prerequisites/port.d.ts.map +1 -0
- package/dist/prerequisites/port.js +26 -0
- package/dist/prerequisites/port.js.map +1 -0
- package/dist/prerequisites/ram.d.ts +6 -4
- package/dist/prerequisites/ram.d.ts.map +1 -0
- package/dist/prerequisites/ram.js +23 -0
- package/dist/prerequisites/ram.js.map +1 -0
- package/dist/prerequisites/self.d.ts +4 -2
- package/dist/prerequisites/self.d.ts.map +1 -0
- package/dist/prerequisites/self.js +15 -0
- package/dist/prerequisites/self.js.map +1 -0
- package/dist/prerequisites/space.d.ts +6 -4
- package/dist/prerequisites/space.d.ts.map +1 -0
- package/dist/prerequisites/space.js +26 -0
- package/dist/prerequisites/space.js.map +1 -0
- package/dist/prerequisites/ssl-certificate-expiry.d.ts +4 -2
- package/dist/prerequisites/ssl-certificate-expiry.d.ts.map +1 -0
- package/dist/prerequisites/ssl-certificate-expiry.js +24 -0
- package/dist/prerequisites/ssl-certificate-expiry.js.map +1 -0
- package/dist/prerequisites/timezone-utc.d.ts +8 -4
- package/dist/prerequisites/timezone-utc.d.ts.map +1 -0
- package/dist/prerequisites/timezone-utc.js +23 -0
- package/dist/prerequisites/timezone-utc.js.map +1 -0
- package/dist/prerequisites/translations.d.ts +4 -2
- package/dist/prerequisites/translations.d.ts.map +1 -0
- package/dist/prerequisites/translations.js +59 -0
- package/dist/prerequisites/translations.js.map +1 -0
- package/dist/prerequisites.d.ts +2 -0
- package/dist/prerequisites.d.ts.map +1 -0
- package/dist/prerequisites.js +83 -0
- package/dist/prerequisites.js.map +1 -0
- package/dist/rate-limit-shield.d.ts +2 -2
- package/dist/rate-limit-shield.d.ts.map +1 -1
- package/dist/rate-limit-shield.js +2 -2
- package/dist/rate-limit-shield.js.map +1 -1
- package/dist/session-id.d.ts +7 -0
- package/dist/session-id.d.ts.map +1 -0
- package/dist/session-id.js +10 -0
- package/dist/session-id.js.map +1 -0
- package/dist/setup.d.ts +3 -2
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +11 -6
- package/dist/setup.js.map +1 -1
- package/dist/time-zone-offset.d.ts +6 -6
- package/dist/time-zone-offset.d.ts.map +1 -1
- package/dist/time-zone-offset.js +4 -4
- package/dist/time-zone-offset.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/uptime.d.ts +4 -4
- package/dist/uptime.d.ts.map +1 -0
- package/dist/uptime.js +10 -0
- package/dist/uptime.js.map +1 -0
- package/dist/username.d.ts +11 -0
- package/dist/username.d.ts.map +1 -0
- package/dist/username.js +13 -0
- package/dist/username.js.map +1 -0
- package/dist/uuid.d.ts +4 -3
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +4 -0
- package/dist/uuid.js.map +1 -0
- package/dist/weak-etag-extractor.d.ts +7 -0
- package/dist/weak-etag-extractor.d.ts.map +1 -0
- package/dist/weak-etag-extractor.js +18 -0
- package/dist/weak-etag-extractor.js.map +1 -0
- package/package.json +20 -13
- package/src/api-key-shield.ts +2 -2
- package/src/api-version.ts +3 -2
- package/src/auth-shield.ts +14 -23
- package/src/basic-auth.ts +7 -0
- package/src/build-info-repository.ts +26 -0
- package/src/cache-resolver.ts +93 -0
- package/src/cache-response.ts +2 -5
- package/src/cache-static-files.ts +3 -3
- package/src/context.ts +9 -4
- package/src/correlation-id.ts +6 -0
- package/src/download-file.ts +2 -2
- package/src/env-validator.ts +43 -0
- package/src/etag-extractor.ts +5 -20
- package/src/file-uploader.ts +4 -4
- package/src/graceful-shutdown.ts +3 -3
- package/src/healthcheck.ts +30 -20
- package/src/http-logger.ts +9 -5
- package/src/i18n.ts +13 -48
- package/src/index.ts +28 -7
- package/src/jobs.ts +91 -0
- package/src/logger.ts +156 -0
- package/src/mailer.ts +64 -0
- package/src/memory-consumption.ts +9 -0
- package/src/new-uuid.ts +5 -0
- package/src/node-env.vo.ts +9 -0
- package/src/passwords.ts +55 -0
- package/src/path.ts +4 -0
- package/src/port.ts +4 -0
- package/src/prerequisites/binary.ts +44 -0
- package/src/prerequisites/bun.ts +32 -0
- package/src/prerequisites/index.ts +16 -0
- package/src/prerequisites/jobs.ts +28 -0
- package/src/prerequisites/log-file.ts +35 -0
- package/src/prerequisites/mailer.ts +32 -0
- package/src/prerequisites/memory.ts +34 -0
- package/src/prerequisites/node.ts +36 -0
- package/src/prerequisites/outside-connectivity.ts +31 -0
- package/src/prerequisites/path.ts +41 -0
- package/src/prerequisites/port.ts +44 -0
- package/src/prerequisites/ram.ts +35 -0
- package/src/prerequisites/self.ts +24 -0
- package/src/prerequisites/space.ts +39 -0
- package/src/prerequisites/ssl-certificate-expiry.ts +37 -0
- package/src/prerequisites/timezone-utc.ts +36 -0
- package/src/prerequisites/translations.ts +92 -0
- package/src/prerequisites.ts +105 -0
- package/src/rate-limit-shield.ts +3 -3
- package/src/session-id.ts +13 -0
- package/src/setup.ts +14 -7
- package/src/time-zone-offset.ts +11 -14
- package/src/uptime.ts +16 -0
- package/src/username.ts +20 -0
- package/src/uuid.ts +6 -0
- package/src/weak-etag-extractor.ts +19 -0
- package/src/image-processor.ts +0 -5
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export type PrerequisiteLabelType = string;
|
|
2
|
+
|
|
3
|
+
export enum PrerequisiteStrategyEnum {
|
|
4
|
+
binary = "binary",
|
|
5
|
+
mailer = "mailer",
|
|
6
|
+
self = "self",
|
|
7
|
+
timezoneUTC = "timezoneUTC",
|
|
8
|
+
path = "path",
|
|
9
|
+
node = "node",
|
|
10
|
+
bun = "bun",
|
|
11
|
+
RAM = "RAM",
|
|
12
|
+
space = "space",
|
|
13
|
+
translations = "translations",
|
|
14
|
+
port = "port",
|
|
15
|
+
jobs = "jobs",
|
|
16
|
+
memory = "memory",
|
|
17
|
+
outsideConnectivity = "outsideConnectivity",
|
|
18
|
+
sslCertificateExpiry = "sslCertificateExpiry",
|
|
19
|
+
logFile = "logFile",
|
|
20
|
+
/** @public */
|
|
21
|
+
custom = "custom",
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export enum PrerequisiteStatusEnum {
|
|
25
|
+
success = "success",
|
|
26
|
+
failure = "failure",
|
|
27
|
+
undetermined = "undetermined",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type BasePrerequisiteConfig = {
|
|
31
|
+
label: PrerequisiteLabelType;
|
|
32
|
+
enabled?: boolean;
|
|
33
|
+
} & Record<string, unknown>;
|
|
34
|
+
|
|
35
|
+
export abstract class AbstractPrerequisite<T extends BasePrerequisiteConfig> {
|
|
36
|
+
readonly label: PrerequisiteLabelType;
|
|
37
|
+
readonly enabled: boolean = true;
|
|
38
|
+
abstract readonly strategy: PrerequisiteStrategyEnum;
|
|
39
|
+
abstract readonly config: T;
|
|
40
|
+
|
|
41
|
+
status: PrerequisiteStatusEnum = PrerequisiteStatusEnum.undetermined;
|
|
42
|
+
|
|
43
|
+
constructor(config: T) {
|
|
44
|
+
this.label = config.label;
|
|
45
|
+
this.enabled = config.enabled ?? true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
abstract verify(): Promise<PrerequisiteStatusEnum>;
|
|
49
|
+
|
|
50
|
+
protected pass(): PrerequisiteStatusEnum.success {
|
|
51
|
+
this.status = PrerequisiteStatusEnum.success;
|
|
52
|
+
return PrerequisiteStatusEnum.success;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
protected reject(): PrerequisiteStatusEnum.failure {
|
|
56
|
+
this.status = PrerequisiteStatusEnum.failure;
|
|
57
|
+
return PrerequisiteStatusEnum.failure;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
report() {
|
|
61
|
+
if (this.status === PrerequisiteStatusEnum.success) {
|
|
62
|
+
// biome-ignore lint: lint/suspicious/noConsoleLog
|
|
63
|
+
console.log(`[x] ${this.config.label} verified correctly with ${this.strategy} strategy`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (this.status === PrerequisiteStatusEnum.failure) {
|
|
67
|
+
// biome-ignore lint: lint/suspicious/noConsoleLog
|
|
68
|
+
console.log(`[-] ${this.config.label} not verified correctly with ${this.strategy} strategy`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (this.status === PrerequisiteStatusEnum.undetermined) {
|
|
72
|
+
// biome-ignore lint: lint/suspicious/noConsoleLog
|
|
73
|
+
console.log(`[?] ${this.config.label} not enabled with ${this.strategy} strategy`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export class Prerequisites {
|
|
79
|
+
static async check(prerequisites: AbstractPrerequisite<BasePrerequisiteConfig>[]) {
|
|
80
|
+
try {
|
|
81
|
+
const failedPrerequisiteLabels: PrerequisiteLabelType[] = [];
|
|
82
|
+
|
|
83
|
+
for (const prerequisite of prerequisites) {
|
|
84
|
+
await prerequisite.verify();
|
|
85
|
+
prerequisite.report();
|
|
86
|
+
|
|
87
|
+
if (prerequisite.status === PrerequisiteStatusEnum.failure) {
|
|
88
|
+
failedPrerequisiteLabels.push(prerequisite.label);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (failedPrerequisiteLabels.length > 0) {
|
|
93
|
+
const failedPrerequisiteLabelsFormatted = failedPrerequisiteLabels.join(", ");
|
|
94
|
+
|
|
95
|
+
// biome-ignore lint: lint/suspicious/noConsoleLog
|
|
96
|
+
console.log(`Prerequisites failed: ${failedPrerequisiteLabelsFormatted}, quitting...`);
|
|
97
|
+
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
} catch (error) {
|
|
101
|
+
// biome-ignore lint: lint/suspicious/noConsoleLog
|
|
102
|
+
console.log("Prerequisites error", String(error));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/rate-limit-shield.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
2
|
import { createMiddleware } from "hono/factory";
|
|
3
3
|
import { HTTPException } from "hono/http-exception";
|
|
4
4
|
|
|
5
|
-
type RateLimitShieldOptionsType = { ms:
|
|
5
|
+
type RateLimitShieldOptionsType = { ms: tools.TimestampType };
|
|
6
6
|
|
|
7
7
|
export const TooManyRequestsError = new HTTPException(429, {
|
|
8
8
|
message: "app.too_many_requests",
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
export const rateLimitShield = (options: RateLimitShieldOptionsType) => {
|
|
12
|
-
const rateLimiter = new
|
|
12
|
+
const rateLimiter = new tools.RateLimiter(options);
|
|
13
13
|
|
|
14
14
|
return createMiddleware(async (_c, next) => {
|
|
15
15
|
const currentTimestampMs = Date.now();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Lucia } from "lucia";
|
|
2
|
+
|
|
3
|
+
export class SessionId {
|
|
4
|
+
private value: string | null;
|
|
5
|
+
|
|
6
|
+
constructor(cookie: string | undefined, lucia: Lucia) {
|
|
7
|
+
this.value = lucia.readSessionCookie(cookie ?? "");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get(): SessionId["value"] {
|
|
11
|
+
return this.value;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/setup.ts
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
2
|
import { bodyLimit } from "hono/body-limit";
|
|
3
3
|
import { cors } from "hono/cors";
|
|
4
|
+
import { languageDetector } from "hono/language";
|
|
4
5
|
import { requestId } from "hono/request-id";
|
|
5
6
|
import { secureHeaders } from "hono/secure-headers";
|
|
6
7
|
import { timing } from "hono/timing";
|
|
7
8
|
|
|
8
9
|
import { ApiVersion } from "./api-version";
|
|
9
10
|
import { Context } from "./context";
|
|
10
|
-
import { ETagExtractor
|
|
11
|
+
import { ETagExtractor } from "./etag-extractor";
|
|
11
12
|
import { HttpLogger } from "./http-logger";
|
|
13
|
+
import { I18nConfigType } from "./i18n";
|
|
14
|
+
import { Logger } from "./logger";
|
|
12
15
|
import { TimeZoneOffset } from "./time-zone-offset";
|
|
16
|
+
import { WeakETagExtractor } from "./weak-etag-extractor";
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
export const BODY_LIMIT_MAX_SIZE = new bgn.Size({
|
|
18
|
+
export const BODY_LIMIT_MAX_SIZE = new tools.Size({
|
|
16
19
|
value: 128,
|
|
17
|
-
unit:
|
|
18
|
-
}).toBytes()
|
|
20
|
+
unit: tools.SizeUnit.kB,
|
|
21
|
+
}).toBytes();
|
|
19
22
|
|
|
20
23
|
export class Setup {
|
|
21
|
-
static essentials(logger:
|
|
24
|
+
static essentials(logger: Logger, i18n: I18nConfigType) {
|
|
22
25
|
return [
|
|
23
26
|
secureHeaders(),
|
|
24
27
|
bodyLimit({ maxSize: BODY_LIMIT_MAX_SIZE }),
|
|
25
28
|
ApiVersion.attach,
|
|
26
29
|
cors({ origin: "*" }),
|
|
30
|
+
languageDetector({
|
|
31
|
+
supportedLanguages: Object.keys(i18n.supportedLanguages),
|
|
32
|
+
fallbackLanguage: i18n.defaultLanguage,
|
|
33
|
+
}),
|
|
27
34
|
requestId(),
|
|
28
35
|
TimeZoneOffset.attach,
|
|
29
36
|
Context.attach,
|
package/src/time-zone-offset.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
2
|
import { createMiddleware } from "hono/factory";
|
|
3
3
|
|
|
4
4
|
export type TimeZoneOffsetVariables = {
|
|
5
5
|
timeZoneOffset: {
|
|
6
|
-
minutes:
|
|
7
|
-
seconds:
|
|
8
|
-
miliseconds:
|
|
6
|
+
minutes: tools.TimeResult["minutes"];
|
|
7
|
+
seconds: tools.TimeResult["seconds"];
|
|
8
|
+
miliseconds: tools.TimeResult["ms"];
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
|
|
@@ -13,14 +13,14 @@ export class TimeZoneOffset {
|
|
|
13
13
|
static TIME_ZONE_OFFSET_HEADER_NAME = "time-zone-offset";
|
|
14
14
|
|
|
15
15
|
static attach = createMiddleware(async (c, next) => {
|
|
16
|
-
const timeZoneOffsetMinutes =
|
|
16
|
+
const timeZoneOffsetMinutes = tools.TimeZoneOffsetValue.parse(
|
|
17
17
|
c.req.header(TimeZoneOffset.TIME_ZONE_OFFSET_HEADER_NAME),
|
|
18
18
|
);
|
|
19
19
|
|
|
20
20
|
const timeZoneOffset = {
|
|
21
21
|
minutes: timeZoneOffsetMinutes,
|
|
22
|
-
seconds:
|
|
23
|
-
miliseconds:
|
|
22
|
+
seconds: tools.Time.Minutes(timeZoneOffsetMinutes).seconds,
|
|
23
|
+
miliseconds: tools.Time.Minutes(timeZoneOffsetMinutes).ms,
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
c.set("timeZoneOffset", timeZoneOffset);
|
|
@@ -29,16 +29,13 @@ export class TimeZoneOffset {
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
static adjustTimestamp(
|
|
32
|
-
timestamp:
|
|
33
|
-
timeZoneOffsetMs:
|
|
34
|
-
):
|
|
32
|
+
timestamp: tools.TimestampType,
|
|
33
|
+
timeZoneOffsetMs: tools.TimeResult["ms"],
|
|
34
|
+
): tools.TimestampType {
|
|
35
35
|
return timestamp - timeZoneOffsetMs;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
static adjustDate(
|
|
39
|
-
timestamp: bg.Schema.TimestampType,
|
|
40
|
-
timeZoneOffsetMs: bg.Schema.TimeZoneOffsetValueType,
|
|
41
|
-
): Date {
|
|
38
|
+
static adjustDate(timestamp: tools.TimestampType, timeZoneOffsetMs: tools.TimeResult["ms"]): Date {
|
|
42
39
|
return new Date(timestamp - timeZoneOffsetMs);
|
|
43
40
|
}
|
|
44
41
|
}
|
package/src/uptime.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
|
|
3
|
+
export type UptimeResultType = {
|
|
4
|
+
seconds: tools.TimestampType;
|
|
5
|
+
formatted: ReturnType<(typeof tools.DateFormatters)["relative"]>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export class Uptime {
|
|
9
|
+
static get(): UptimeResultType {
|
|
10
|
+
const rounding = new tools.RoundToNearest();
|
|
11
|
+
const uptime = tools.Time.Seconds(rounding.round(process.uptime()));
|
|
12
|
+
const uptimeFormatted = tools.DateFormatters.relative(Date.now() - uptime.ms);
|
|
13
|
+
|
|
14
|
+
return { seconds: uptime.seconds, formatted: uptimeFormatted };
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/username.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
export type IdType = string;
|
|
4
|
+
|
|
5
|
+
type UsernameType = string;
|
|
6
|
+
|
|
7
|
+
export class Username {
|
|
8
|
+
private readonly schema: z.ZodSchema = z.string().max(256);
|
|
9
|
+
|
|
10
|
+
private readonly value: UsernameType;
|
|
11
|
+
|
|
12
|
+
constructor(value: UsernameType, schema?: z.ZodSchema) {
|
|
13
|
+
this.schema = schema ?? this.schema;
|
|
14
|
+
this.value = this.schema.parse(value) as UsernameType;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
read(): UsernameType {
|
|
18
|
+
return this.value;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/uuid.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import { createMiddleware } from "hono/factory";
|
|
3
|
+
|
|
4
|
+
import { EtagVariables } from "./etag-extractor";
|
|
5
|
+
|
|
6
|
+
export class WeakETagExtractor {
|
|
7
|
+
static attach = createMiddleware<{ Variables: EtagVariables }>(async (c, next) => {
|
|
8
|
+
try {
|
|
9
|
+
const header = String(c.req.header(tools.WeakETag.IF_MATCH_HEADER_NAME));
|
|
10
|
+
|
|
11
|
+
if (!header || header === "undefined") c.set("WeakETag", null);
|
|
12
|
+
else c.set("WeakETag", tools.WeakETag.fromHeader(header));
|
|
13
|
+
} catch (error) {
|
|
14
|
+
c.set("WeakETag", null);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
await next();
|
|
18
|
+
});
|
|
19
|
+
}
|