@bgord/bun 0.5.0 → 0.6.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/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/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 +26 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -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 +10 -1
- package/dist/mailer.d.ts.map +1 -0
- package/dist/mailer.js +27 -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 +6 -4
- package/dist/prerequisites/timezone-utc.d.ts.map +1 -0
- package/dist/prerequisites/timezone-utc.js +22 -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/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/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 +26 -7
- package/src/jobs.ts +91 -0
- package/src/logger.ts +156 -0
- package/src/mailer.ts +48 -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 +34 -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
package/dist/healthcheck.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import { AbstractPrerequisite, BasePrerequisiteConfig, PrerequisiteLabelType, PrerequisiteStatusEnum } from "./prerequisites";
|
|
2
3
|
export declare class Healthcheck {
|
|
3
|
-
static build: (prerequisites:
|
|
4
|
-
ok:
|
|
5
|
-
version:
|
|
4
|
+
static build: (prerequisites: AbstractPrerequisite<BasePrerequisiteConfig>[]) => [import("hono/types").H<import("hono").Env, string, {}, Promise<Response & import("hono").TypedResponse<{
|
|
5
|
+
ok: PrerequisiteStatusEnum;
|
|
6
|
+
version: tools.BuildVersionType;
|
|
6
7
|
details: {
|
|
7
|
-
label:
|
|
8
|
-
status:
|
|
8
|
+
label: PrerequisiteLabelType;
|
|
9
|
+
status: PrerequisiteStatusEnum;
|
|
9
10
|
}[];
|
|
10
11
|
uptime: {
|
|
11
|
-
seconds:
|
|
12
|
-
formatted: ReturnType<(typeof
|
|
12
|
+
seconds: tools.TimestampType;
|
|
13
|
+
formatted: ReturnType<(typeof tools.DateFormatters)["relative"]>;
|
|
13
14
|
};
|
|
14
15
|
memory: {
|
|
15
|
-
bytes:
|
|
16
|
-
formatted: ReturnType<
|
|
16
|
+
bytes: tools.Size["bytes"];
|
|
17
|
+
formatted: ReturnType<tools.Size["format"]>;
|
|
17
18
|
};
|
|
18
|
-
durationMs:
|
|
19
|
+
durationMs: tools.TimestampType;
|
|
19
20
|
}, 200 | 424, "json">>>];
|
|
20
21
|
}
|
|
21
22
|
//# sourceMappingURL=healthcheck.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"healthcheck.d.ts","sourceRoot":"","sources":["../src/healthcheck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"healthcheck.d.ts","sourceRoot":"","sources":["../src/healthcheck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAKtC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAmBzB,qBAAa,WAAW;IACtB,MAAM,CAAC,KAAK,GAAI,eAAe,oBAAoB,CAAC,sBAAsB,CAAC,EAAE;YAdzE,sBAAsB;iBACjB,KAAK,CAAC,gBAAgB;;mBAEtB,qBAAqB;oBACpB,sBAAsB;;;;mCAjBU,2BACpC;;;mBAoBG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;uBACf,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;;;6BAqCxC;CACN"}
|
package/dist/healthcheck.js
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
2
|
import { createFactory } from "hono/factory";
|
|
3
|
+
import { BuildInfoRepository } from "./build-info-repository";
|
|
4
|
+
import { MemoryConsumption } from "./memory-consumption";
|
|
5
|
+
import { PrerequisiteStatusEnum, } from "./prerequisites";
|
|
6
|
+
import { Uptime } from "./uptime";
|
|
3
7
|
const handler = createFactory();
|
|
4
8
|
export class Healthcheck {
|
|
5
9
|
static build = (prerequisites) => handler.createHandlers(async (c) => {
|
|
6
|
-
const stopwatch = new
|
|
7
|
-
const build = await
|
|
10
|
+
const stopwatch = new tools.Stopwatch();
|
|
11
|
+
const build = await BuildInfoRepository.extract();
|
|
8
12
|
const details = [];
|
|
9
13
|
for (const prerequisite of prerequisites) {
|
|
10
14
|
const status = await prerequisite.verify();
|
|
11
15
|
details.push({ label: prerequisite.label, status });
|
|
12
16
|
}
|
|
13
|
-
const ok = details.every((result) => result.status !==
|
|
14
|
-
?
|
|
15
|
-
:
|
|
16
|
-
const code = ok ===
|
|
17
|
+
const ok = details.every((result) => result.status !== PrerequisiteStatusEnum.failure)
|
|
18
|
+
? PrerequisiteStatusEnum.success
|
|
19
|
+
: PrerequisiteStatusEnum.failure;
|
|
20
|
+
const code = ok === PrerequisiteStatusEnum.success ? 200 : 424;
|
|
17
21
|
const result = {
|
|
18
22
|
ok,
|
|
19
23
|
details,
|
|
20
|
-
version: build.BUILD_VERSION ??
|
|
21
|
-
uptime:
|
|
24
|
+
version: build.BUILD_VERSION ?? tools.BuildVersion.parse("unknown"),
|
|
25
|
+
uptime: Uptime.get(),
|
|
22
26
|
memory: {
|
|
23
|
-
bytes:
|
|
24
|
-
formatted:
|
|
27
|
+
bytes: MemoryConsumption.get().toBytes(),
|
|
28
|
+
formatted: MemoryConsumption.get().format(tools.SizeUnit.MB),
|
|
25
29
|
},
|
|
26
30
|
...stopwatch.stop(),
|
|
27
31
|
};
|
package/dist/healthcheck.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"healthcheck.js","sourceRoot":"","sources":["../src/healthcheck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"healthcheck.js","sourceR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/D,MAAM,MAAM,GAA0B;YACpC,EAAE;YACF,OAAO;YACP,OAAO,EAAE,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC;YACnE,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE;YACpB,MAAM,EAAE;gBACN,KAAK,EAAE,iBAAiB,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE;gBACxC,SAAS,EAAE,iBAAiB,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;aAC7D;YACD,GAAG,SAAS,CAAC,IAAI,EAAE;SACpB,CAAC;QAEF,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC"}
|
package/dist/http-logger.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Logger } from "./logger";
|
|
2
2
|
export declare class HttpLogger {
|
|
3
3
|
private static simplify;
|
|
4
4
|
private static uninformativeHeaders;
|
|
5
|
-
static build: (logger:
|
|
5
|
+
static build: (logger: Logger) => import("hono").MiddlewareHandler<any, string, {}>;
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=http-logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-logger.d.ts","sourceRoot":"","sources":["../src/http-logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-logger.d.ts","sourceRoot":"","sources":["../src/http-logger.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,QAAQ;IAQvB,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAoBjC;IAEF,MAAM,CAAC,KAAK,GAAI,QAAQ,MAAM,uDAoEzB;CACN"}
|
package/dist/http-logger.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import * as bg from "@bgord/node";
|
|
2
1
|
import { getConnInfo } from "hono/bun";
|
|
3
2
|
import { createMiddleware } from "hono/factory";
|
|
4
3
|
import _ from "lodash";
|
|
4
|
+
import { CacheHitEnum } from "./cache-resolver";
|
|
5
|
+
import { CacheResponse } from "./cache-response";
|
|
5
6
|
export class HttpLogger {
|
|
6
7
|
static simplify(response) {
|
|
7
8
|
const result = JSON.stringify(response, (_key, value) => Array.isArray(value) ? { type: "Array", length: value.length } : value);
|
|
@@ -58,8 +59,8 @@ export class HttpLogger {
|
|
|
58
59
|
metadata: _.pickBy(httpRequestBeforeMetadata, (value) => !_.isEmpty(value)),
|
|
59
60
|
});
|
|
60
61
|
await next();
|
|
61
|
-
const cacheHitHeader = c.res.clone().headers.get(
|
|
62
|
-
const cacheHit = cacheHitHeader ===
|
|
62
|
+
const cacheHitHeader = c.res.clone().headers.get(CacheResponse.CACHE_HIT_HEADER);
|
|
63
|
+
const cacheHit = cacheHitHeader === CacheHitEnum.hit ? CacheHitEnum.hit : undefined;
|
|
63
64
|
let response;
|
|
64
65
|
try {
|
|
65
66
|
response = await c.res.clone().json();
|
package/dist/http-logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-logger.js","sourceRoot":"","sources":["../src/http-logger.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"http-logger.js","sourceRoot":"","sources":["../src/http-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIjD,MAAM,OAAO,UAAU;IACb,MAAM,CAAC,QAAQ,CAAC,QA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K,EAAE,CAAC,CAAA,CAAC;QAElB,MAAM,wBAAwB,GAAG;YAC/B,QAAQ;YACR,QAAQ;SACT,CAAC;QAEF,MAAM,cAAc,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAElE,MAAM,eAAe,GAAG,cAAc,EAAE,KAAK,CAAC,uBAAuB,CAAC,IAAI,SAAS,CAAC;QAEpF,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAEjF,MAAM,CAAC,IAAI,CAAC;YACV,SAAS,EAAE,oBAAoB;YAC/B,aAAa;YACb,OAAO,EAAE,UAAU;YACnB,MAAM;YACN,GAAG;YACH,YAAY,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM;YAC1B,UAAU;YACV,MAAM;YACN,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,wBAAwB,CAAC;SACxD,CAAC,CAAC;IACL,CAAC,CAAC,CAAC"}
|
package/dist/i18n.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import { PathType } from "./path";
|
|
2
3
|
export type TranslationsKeyType = string;
|
|
3
4
|
export type TranslationsValueType = string;
|
|
4
5
|
export type TranslationsType = Record<TranslationsKeyType, TranslationsValueType>;
|
|
@@ -6,22 +7,16 @@ export type TranslationPlaceholderType = string;
|
|
|
6
7
|
export type TranslationPlaceholderValueType = string | number;
|
|
7
8
|
export type TranslationVariableType = Record<TranslationPlaceholderType, TranslationPlaceholderValueType>;
|
|
8
9
|
export type I18nConfigType = {
|
|
9
|
-
translationsPath?:
|
|
10
|
-
defaultLanguage?:
|
|
11
|
-
supportedLanguages: Record<string,
|
|
12
|
-
};
|
|
13
|
-
export type I18nVariablesType = {
|
|
14
|
-
language: bgn.Schema.LanguageType;
|
|
15
|
-
supportedLanguages: bgn.Schema.LanguageType[];
|
|
16
|
-
translationsPath: bgn.Schema.PathType;
|
|
10
|
+
translationsPath?: PathType;
|
|
11
|
+
defaultLanguage?: tools.LanguageType;
|
|
12
|
+
supportedLanguages: Record<string, tools.LanguageType>;
|
|
17
13
|
};
|
|
18
14
|
export declare class I18n {
|
|
19
|
-
|
|
15
|
+
private translationsPath;
|
|
20
16
|
static DEFAULT_TRANSLATIONS_PATH: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
static getTranslationPathForLanguage(language: bgn.Schema.LanguageType, translationsPath?: string): bgn.Schema.PathType;
|
|
17
|
+
constructor(translationsPath?: PathType);
|
|
18
|
+
getTranslations(language: tools.LanguageType): Promise<TranslationsType>;
|
|
19
|
+
useTranslations(translations: TranslationsType): (key: TranslationsKeyType, variables?: TranslationVariableType) => string;
|
|
20
|
+
getTranslationPathForLanguage(language: tools.LanguageType): PathType;
|
|
26
21
|
}
|
|
27
22
|
//# sourceMappingURL=i18n.d.ts.map
|
package/dist/i18n.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAQ,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACzC,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAC3C,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,mBAAmB,EAAE,qBAAqB,CAAC,CAAC;AAElF,MAAM,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAChD,MAAM,MAAM,+BAA+B,GAAG,MAAM,GAAG,MAAM,CAAC;AAC9D,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,0BAA0B,EAAE,+BAA+B,CAAC,CAAC;AAE1G,MAAM,MAAM,cAAc,GAAG;IAC3B,gBAAgB,CAAC,EAAE,QAAQ,CAAC;IAC5B,eAAe,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IACrC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CACxD,CAAC;AAEF,qBAAa,IAAI;IAGH,OAAO,CAAC,gBAAgB;IAFpC,MAAM,CAAC,yBAAyB,SAAoC;gBAEhD,gBAAgB,GAAE,QAAyC;IAEzE,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAW9E,eAAe,CAAC,YAAY,EAAE,gBAAgB,IAClB,KAAK,mBAAmB,EAAE,YAAY,uBAAuB;IAiBzF,6BAA6B,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,GAAG,QAAQ;CAGtE"}
|
package/dist/i18n.js
CHANGED
|
@@ -1,29 +1,14 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import
|
|
3
|
-
import { getCookie } from "hono/cookie";
|
|
4
|
-
import { createMiddleware } from "hono/factory";
|
|
2
|
+
import { Path } from "./path";
|
|
5
3
|
export class I18n {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
static applyTo(config) {
|
|
11
|
-
return createMiddleware(async (c, next) => {
|
|
12
|
-
const translationsPath = config?.translationsPath ?? I18n.DEFAULT_TRANSLATIONS_PATH;
|
|
13
|
-
const defaultLanguage = config?.defaultLanguage ?? I18n.FALLBACK_LANGUAGE;
|
|
14
|
-
const chosenLanguage = getCookie(c, I18n.LANGUAGE_COOKIE_NAME) ?? defaultLanguage;
|
|
15
|
-
const language = Object.keys(config.supportedLanguages).find((language) => language === chosenLanguage)
|
|
16
|
-
? chosenLanguage
|
|
17
|
-
: I18n.FALLBACK_LANGUAGE;
|
|
18
|
-
c.set("supportedLanguages", Object.keys(config.supportedLanguages));
|
|
19
|
-
c.set("language", language);
|
|
20
|
-
c.set("translationsPath", translationsPath);
|
|
21
|
-
return next();
|
|
22
|
-
});
|
|
4
|
+
translationsPath;
|
|
5
|
+
static DEFAULT_TRANSLATIONS_PATH = Path.parse("infra/translations");
|
|
6
|
+
constructor(translationsPath = I18n.DEFAULT_TRANSLATIONS_PATH) {
|
|
7
|
+
this.translationsPath = translationsPath;
|
|
23
8
|
}
|
|
24
|
-
|
|
9
|
+
async getTranslations(language) {
|
|
25
10
|
try {
|
|
26
|
-
return Bun.file(
|
|
11
|
+
return Bun.file(this.getTranslationPathForLanguage(language)).json();
|
|
27
12
|
}
|
|
28
13
|
catch (error) {
|
|
29
14
|
// biome-ignore lint: lint/suspicious/noConsoleLog
|
|
@@ -31,7 +16,7 @@ export class I18n {
|
|
|
31
16
|
return {};
|
|
32
17
|
}
|
|
33
18
|
}
|
|
34
|
-
|
|
19
|
+
useTranslations(translations) {
|
|
35
20
|
return function translate(key, variables) {
|
|
36
21
|
const translation = translations[key];
|
|
37
22
|
if (!translation) {
|
|
@@ -43,8 +28,8 @@ export class I18n {
|
|
|
43
28
|
return Object.entries(variables).reduce((result, [placeholder, value]) => result.replace(`{{${placeholder}}}`, String(value)), translation);
|
|
44
29
|
};
|
|
45
30
|
}
|
|
46
|
-
|
|
47
|
-
return
|
|
31
|
+
getTranslationPathForLanguage(language) {
|
|
32
|
+
return Path.parse(path.join(this.translationsPath, `${language}.json`));
|
|
48
33
|
}
|
|
49
34
|
}
|
|
50
35
|
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAA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W,CACZ,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAED,6BAA6B,CAAC,QAA4B;QACxD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,QAAQ,OAAO,CAAC,CAAC,CAAC;IAC1E,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
export * from "./api-key-shield";
|
|
2
2
|
export * from "./api-version";
|
|
3
3
|
export * from "./auth-shield";
|
|
4
|
+
export * from "./build-info-repository";
|
|
5
|
+
export * from "./cache-resolver";
|
|
6
|
+
export * from "./cache-response";
|
|
7
|
+
export * from "./cache-static-files";
|
|
4
8
|
export * from "./context";
|
|
9
|
+
export * from "./correlation-id";
|
|
10
|
+
export * from "./download-file";
|
|
5
11
|
export * from "./etag-extractor";
|
|
12
|
+
export * from "./file-uploader";
|
|
6
13
|
export * from "./graceful-shutdown";
|
|
7
14
|
export * from "./healthcheck";
|
|
8
15
|
export * from "./http-logger";
|
|
9
|
-
export * from "./rate-limit-shield";
|
|
10
|
-
export * from "./time-zone-offset";
|
|
11
|
-
export * from "./cache-static-files";
|
|
12
|
-
export * from "./cache-response";
|
|
13
|
-
export * from "./download-file";
|
|
14
16
|
export * from "./i18n";
|
|
15
|
-
export * from "./
|
|
16
|
-
export * from "./
|
|
17
|
+
export * from "./jobs";
|
|
18
|
+
export * from "./logger";
|
|
19
|
+
export * from "./mailer";
|
|
20
|
+
export * from "./memory-consumption";
|
|
21
|
+
export * from "./new-uuid";
|
|
22
|
+
export * from "./node-env.vo";
|
|
23
|
+
export * from "./passwords";
|
|
24
|
+
export * from "./path";
|
|
25
|
+
export * from "./port";
|
|
26
|
+
export * from "./prerequisites";
|
|
27
|
+
export * from "./prerequisites/index";
|
|
28
|
+
export * from "./rate-limit-shield";
|
|
29
|
+
export * from "./session-id";
|
|
17
30
|
export * from "./setup";
|
|
31
|
+
export * from "./time-zone-offset";
|
|
32
|
+
export * from "./uptime";
|
|
33
|
+
export * from "./username";
|
|
34
|
+
export * from "./uuid";
|
|
35
|
+
export * from "./weak-etag-extractor";
|
|
36
|
+
export { default as sharp } from "sharp";
|
|
18
37
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
export * from "./api-key-shield";
|
|
2
2
|
export * from "./api-version";
|
|
3
3
|
export * from "./auth-shield";
|
|
4
|
+
export * from "./build-info-repository";
|
|
5
|
+
export * from "./cache-resolver";
|
|
6
|
+
export * from "./cache-response";
|
|
7
|
+
export * from "./cache-static-files";
|
|
4
8
|
export * from "./context";
|
|
9
|
+
export * from "./correlation-id";
|
|
10
|
+
export * from "./download-file";
|
|
5
11
|
export * from "./etag-extractor";
|
|
12
|
+
export * from "./file-uploader";
|
|
6
13
|
export * from "./graceful-shutdown";
|
|
7
14
|
export * from "./healthcheck";
|
|
8
15
|
export * from "./http-logger";
|
|
9
|
-
export * from "./rate-limit-shield";
|
|
10
|
-
export * from "./time-zone-offset";
|
|
11
|
-
export * from "./cache-static-files";
|
|
12
|
-
export * from "./cache-response";
|
|
13
|
-
export * from "./download-file";
|
|
14
16
|
export * from "./i18n";
|
|
15
|
-
export * from "./
|
|
16
|
-
export * from "./
|
|
17
|
+
export * from "./jobs";
|
|
18
|
+
export * from "./logger";
|
|
19
|
+
export * from "./mailer";
|
|
20
|
+
export * from "./memory-consumption";
|
|
21
|
+
export * from "./new-uuid";
|
|
22
|
+
export * from "./node-env.vo";
|
|
23
|
+
export * from "./passwords";
|
|
24
|
+
export * from "./path";
|
|
25
|
+
export * from "./port";
|
|
26
|
+
export * from "./prerequisites";
|
|
27
|
+
export * from "./prerequisites/index";
|
|
28
|
+
export * from "./rate-limit-shield";
|
|
29
|
+
export * from "./session-id";
|
|
17
30
|
export * from "./setup";
|
|
31
|
+
export * from "./time-zone-offset";
|
|
32
|
+
export * from "./uptime";
|
|
33
|
+
export * from "./username";
|
|
34
|
+
export * from "./uuid";
|
|
35
|
+
export * from "./weak-etag-extractor";
|
|
36
|
+
export { default as sharp } from "sharp";
|
|
18
37
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAA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T,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C,MAAM,CAAC,YAAY,EAAE,gBAAgB;IAsCrC,OAAO,CAAC,IAAI,EAAE,IAAI;CAWnB"}
|
package/dist/jobs.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import { CorrelationId } from "./correlation-id";
|
|
3
|
+
import { NewUUID } from "./new-uuid";
|
|
4
|
+
export var UTC_DAY_OF_THE_WEEK;
|
|
5
|
+
(function (UTC_DAY_OF_THE_WEEK) {
|
|
6
|
+
UTC_DAY_OF_THE_WEEK[UTC_DAY_OF_THE_WEEK["Monday"] = 1] = "Monday";
|
|
7
|
+
UTC_DAY_OF_THE_WEEK[UTC_DAY_OF_THE_WEEK["Tuesday"] = 2] = "Tuesday";
|
|
8
|
+
UTC_DAY_OF_THE_WEEK[UTC_DAY_OF_THE_WEEK["Wednesday"] = 3] = "Wednesday";
|
|
9
|
+
UTC_DAY_OF_THE_WEEK[UTC_DAY_OF_THE_WEEK["Thursday"] = 4] = "Thursday";
|
|
10
|
+
UTC_DAY_OF_THE_WEEK[UTC_DAY_OF_THE_WEEK["Friday"] = 5] = "Friday";
|
|
11
|
+
UTC_DAY_OF_THE_WEEK[UTC_DAY_OF_THE_WEEK["Saturday"] = 6] = "Saturday";
|
|
12
|
+
UTC_DAY_OF_THE_WEEK[UTC_DAY_OF_THE_WEEK["Sunday"] = 0] = "Sunday";
|
|
13
|
+
})(UTC_DAY_OF_THE_WEEK || (UTC_DAY_OF_THE_WEEK = {}));
|
|
14
|
+
export class Jobs {
|
|
15
|
+
static SCHEDULES = { EVERY_MINUTE: "* * * * *", EVERY_HOUR: "0 * * * *" };
|
|
16
|
+
static stopAll(jobs) {
|
|
17
|
+
Object.values(jobs).forEach((job) => job.stop());
|
|
18
|
+
}
|
|
19
|
+
static areAllRunning(jobs) {
|
|
20
|
+
return Object.values(jobs).every((job) => job.isRunning());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class JobHandler {
|
|
24
|
+
logger;
|
|
25
|
+
constructor(logger) {
|
|
26
|
+
this.logger = logger;
|
|
27
|
+
}
|
|
28
|
+
handle(jobProcessor) {
|
|
29
|
+
const correlationId = CorrelationId.parse(NewUUID.generate());
|
|
30
|
+
// biome-ignore lint: lint/complexity/noUselessThisAlias
|
|
31
|
+
const that = this;
|
|
32
|
+
return async () => {
|
|
33
|
+
const stopwatch = new tools.Stopwatch();
|
|
34
|
+
try {
|
|
35
|
+
that.logger.info({
|
|
36
|
+
message: `${jobProcessor.label} start`,
|
|
37
|
+
operation: "job_start",
|
|
38
|
+
correlationId,
|
|
39
|
+
});
|
|
40
|
+
await jobProcessor.process();
|
|
41
|
+
that.logger.info({
|
|
42
|
+
message: `${jobProcessor.label} success`,
|
|
43
|
+
operation: "job_success",
|
|
44
|
+
correlationId,
|
|
45
|
+
metadata: stopwatch.stop(),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
that.logger.error({
|
|
50
|
+
message: `${jobProcessor.label} error`,
|
|
51
|
+
operation: "job_error",
|
|
52
|
+
correlationId,
|
|
53
|
+
metadata: {
|
|
54
|
+
...that.logger.formatError(error),
|
|
55
|
+
...stopwatch.stop(),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
protect(cron) {
|
|
62
|
+
// biome-ignore lint: lint/complexity/noUselessThisAlias
|
|
63
|
+
const that = this;
|
|
64
|
+
return async () => {
|
|
65
|
+
that.logger.info({
|
|
66
|
+
message: `${cron.name} overrun`,
|
|
67
|
+
operation: "job_overrun",
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=jobs.js.map
|
package/dist/jobs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"j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AE,CAAC;YAExC,IAAI,CAAC;gBACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;oBACf,OAAO,EAAE,GAAG,YAAY,CAAC,KAAK,QAAQ;oBACtC,SAAS,EAAE,WAAW;oBACtB,aAAa;iBACd,CAAC,CAAC;gBAEH,MAAM,YAAY,CAAC,OAAO,EAAE,CAAC;gBAE7B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;oBACf,OAAO,EAAE,GAAG,YAAY,CAAC,KAAK,UAAU;oBACxC,SAAS,EAAE,aAAa;oBACxB,aAAa;oBACb,QAAQ,EAAE,SAAS,CAAC,IAAI,EAAE;iBAC3B,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;oBAChB,OAAO,EAAE,GAAG,YAAY,CAAC,KAAK,QAAQ;oBACtC,SAAS,EAAE,WAAW;oBACtB,aAAa;oBACb,QAAQ,EAAE;wBACR,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC;wBACjC,GAAG,SAAS,CAAC,IAAI,EAAE;qBACpB;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,IAAU;QAChB,wDAAwD;QACxD,MAAM,IAAI,GAAG,IAAI,CAAC;QAElB,OAAO,KAAK,IAAI,EAAE;YAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBACf,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,UAAU;gBAC/B,SAAS,EAAE,aAAa;aACzB,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;CACF"}
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
import { CorrelationIdType } from "./correlation-id";
|
|
4
|
+
import { NodeEnvironmentEnum } from "./node-env.vo";
|
|
5
|
+
import { PathType } from "./path";
|
|
6
|
+
export declare enum LogLevelEnum {
|
|
7
|
+
/** @public */
|
|
8
|
+
silent = "silent",
|
|
9
|
+
error = "error",
|
|
10
|
+
warn = "warn",
|
|
11
|
+
info = "info",
|
|
12
|
+
http = "http",
|
|
13
|
+
verbose = "verbose"
|
|
14
|
+
}
|
|
15
|
+
export declare const LogLevel: z.ZodEnum<typeof LogLevelEnum>;
|
|
2
16
|
type LogTimestampType = number;
|
|
3
17
|
type LogAppType = string;
|
|
4
|
-
type LogEnvironmentType =
|
|
18
|
+
type LogEnvironmentType = NodeEnvironmentEnum;
|
|
5
19
|
type LogMessageType = string;
|
|
6
20
|
type LogOperationType = string;
|
|
7
21
|
type LogMetadataType = Record<string, any>;
|
|
8
|
-
type LogCorrelationIdType =
|
|
22
|
+
type LogCorrelationIdType = CorrelationIdType;
|
|
9
23
|
type LogFullType = {
|
|
10
24
|
timestamp: LogTimestampType;
|
|
11
25
|
app: LogAppType;
|
|
12
26
|
environment: LogEnvironmentType;
|
|
13
|
-
level:
|
|
27
|
+
level: LogLevelEnum;
|
|
14
28
|
message: LogMessageType;
|
|
15
29
|
operation: LogOperationType;
|
|
16
30
|
method: string;
|
|
@@ -21,7 +35,7 @@ type LogFullType = {
|
|
|
21
35
|
};
|
|
22
36
|
correlationId?: LogCorrelationIdType;
|
|
23
37
|
responseCode?: number;
|
|
24
|
-
durationMs?:
|
|
38
|
+
durationMs?: tools.TimestampType;
|
|
25
39
|
metadata?: LogMetadataType;
|
|
26
40
|
};
|
|
27
41
|
type LogErrorType = Omit<LogFullType, "app" | "client" | "environment" | "duration" | "level" | "method" | "responseCode" | "timestamp" | "url">;
|
|
@@ -30,8 +44,8 @@ type LogInfoType = Omit<LogFullType, "app" | "client" | "environment" | "duratio
|
|
|
30
44
|
type LogHttpType = Omit<LogFullType, "app" | "environment" | "timestamp" | "level">;
|
|
31
45
|
type LoggerOptionsType = {
|
|
32
46
|
app: LogAppType;
|
|
33
|
-
environment:
|
|
34
|
-
level?:
|
|
47
|
+
environment: NodeEnvironmentEnum;
|
|
48
|
+
level?: LogLevelEnum;
|
|
35
49
|
};
|
|
36
50
|
export declare class Logger {
|
|
37
51
|
private readonly instance;
|
|
@@ -44,6 +58,7 @@ export declare class Logger {
|
|
|
44
58
|
error(log: LogErrorType): void;
|
|
45
59
|
warn(log: LogWarnType): void;
|
|
46
60
|
http(log: LogHttpType): void;
|
|
61
|
+
getProductionLogFilePath(): PathType;
|
|
47
62
|
formatError(_error: unknown): {
|
|
48
63
|
message: string;
|
|
49
64
|
name: string;
|
|
@@ -51,3 +66,4 @@ export declare class Logger {
|
|
|
51
66
|
};
|
|
52
67
|
}
|
|
53
68
|
export {};
|
|
69
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,oBAAY,YAAY;IACtB,cAAc;IACd,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;IACb,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AACD,eAAO,MAAM,QAAQ,gCAAuB,CAAC;AAE7C,KAAK,gBAAgB,GAAG,MAAM,CAAC;AAC/B,KAAK,UAAU,GAAG,MAAM,CAAC;AACzB,KAAK,kBAAkB,GAAG,mBAAmB,CAAC;AAC9C,KAAK,cAAc,GAAG,MAAM,CAAC;AAC7B,KAAK,gBAAgB,GAAG,MAAM,CAAC;AAC/B,KAAK,e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AAC,CAAC;AAEpF,KAAK,iBAAiB,GAAG;IACvB,GAAG,EAAE,UAAU,CAAC;IAChB,WAAW,EAAE,mBAAmB,CAAC;IACjC,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAE1C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA2B;IAE/C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmC;IAE/D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoD;gBAE9D,OAAO,EAAE,iBAAiB;IA8BtC,OAAO,CAAC,OAAO;IAQf,IAAI,CAAC,GAAG,EAAE,WAAW;IAIrB,KAAK,CAAC,GAAG,EAAE,YAAY;IAQvB,IAAI,CAAC,GAAG,EAAE,WAAW;IAIrB,IAAI,CAAC,GAAG,EAAE,WAAW;IAIrB,wBAAwB,IAAI,QAAQ;IAIpC,WAAW,CAAC,MAAM,EAAE,OAAO;;;;;CAS5B"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import * as winston from "winston";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
import { NodeEnvironmentEnum } from "./node-env.vo";
|
|
5
|
+
export var LogLevelEnum;
|
|
6
|
+
(function (LogLevelEnum) {
|
|
7
|
+
/** @public */
|
|
8
|
+
LogLevelEnum["silent"] = "silent";
|
|
9
|
+
LogLevelEnum["error"] = "error";
|
|
10
|
+
LogLevelEnum["warn"] = "warn";
|
|
11
|
+
LogLevelEnum["info"] = "info";
|
|
12
|
+
LogLevelEnum["http"] = "http";
|
|
13
|
+
LogLevelEnum["verbose"] = "verbose";
|
|
14
|
+
})(LogLevelEnum || (LogLevelEnum = {}));
|
|
15
|
+
export const LogLevel = z.enum(LogLevelEnum);
|
|
16
|
+
const levels = {
|
|
17
|
+
silent: 0,
|
|
18
|
+
error: 0,
|
|
19
|
+
warn: 1,
|
|
20
|
+
info: 2,
|
|
21
|
+
http: 3,
|
|
22
|
+
verbose: 4,
|
|
23
|
+
};
|
|
24
|
+
export class Logger {
|
|
25
|
+
instance;
|
|
26
|
+
app;
|
|
27
|
+
environment;
|
|
28
|
+
level = LogLevelEnum.verbose;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.app = options.app;
|
|
31
|
+
this.environment = options.environment;
|
|
32
|
+
this.level = options.level ?? LogLevelEnum.verbose;
|
|
33
|
+
const formats = [
|
|
34
|
+
winston.format.json(),
|
|
35
|
+
this.environment !== NodeEnvironmentEnum.production ? winston.format.prettyPrint() : undefined,
|
|
36
|
+
].filter(Boolean);
|
|
37
|
+
this.instance = winston.createLogger({
|
|
38
|
+
level: this.level,
|
|
39
|
+
levels,
|
|
40
|
+
handleExceptions: true,
|
|
41
|
+
handleRejections: true,
|
|
42
|
+
format: winston.format.combine(...formats),
|
|
43
|
+
transports: [new winston.transports.Console()],
|
|
44
|
+
});
|
|
45
|
+
if (this.environment === NodeEnvironmentEnum.production) {
|
|
46
|
+
this.instance.add(new winston.transports.File({
|
|
47
|
+
filename: this.getProductionLogFilePath(),
|
|
48
|
+
maxsize: tools.Size.toBytes({ unit: tools.SizeUnit.MB, value: 100 }),
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
getBase() {
|
|
53
|
+
return {
|
|
54
|
+
app: this.app,
|
|
55
|
+
environment: this.environment,
|
|
56
|
+
timestamp: Date.now(),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
info(log) {
|
|
60
|
+
this.instance.info({ level: LogLevelEnum.info, ...this.getBase(), ...log });
|
|
61
|
+
}
|
|
62
|
+
error(log) {
|
|
63
|
+
this.instance.error({
|
|
64
|
+
level: LogLevelEnum.error,
|
|
65
|
+
...this.getBase(),
|
|
66
|
+
...log,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
warn(log) {
|
|
70
|
+
this.instance.warn({ level: LogLevelEnum.warn, ...this.getBase(), ...log });
|
|
71
|
+
}
|
|
72
|
+
http(log) {
|
|
73
|
+
this.instance.http({ level: LogLevelEnum.http, ...this.getBase(), ...log });
|
|
74
|
+
}
|
|
75
|
+
getProductionLogFilePath() {
|
|
76
|
+
return `/var/log/${this.app}-${this.environment}.log`;
|
|
77
|
+
}
|
|
78
|
+
formatError(_error) {
|
|
79
|
+
const error = _error;
|
|
80
|
+
return {
|
|
81
|
+
message: error?.message,
|
|
82
|
+
name: error?.name,
|
|
83
|
+
stack: error?.stack,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=logger.js.map
|