@bgord/bun 1.7.0 → 1.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/bun",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": "Bartosz Gordon",
@@ -3,7 +3,7 @@ import { BuildInfoRepository } from "./build-info-repository.service";
3
3
  import type { ClockPort } from "./clock.port";
4
4
  import type { FileReaderJsonPort } from "./file-reader-json.port";
5
5
 
6
- type Dependencies = { Clock: ClockPort; JsonFileReader: FileReaderJsonPort };
6
+ type Dependencies = { Clock: ClockPort; FileReaderJson: FileReaderJsonPort };
7
7
 
8
8
  export class ApiVersion {
9
9
  static readonly HEADER_NAME = "api-version";
@@ -4,14 +4,14 @@ import type { FileReaderJsonPort } from "./file-reader-json.port";
4
4
 
5
5
  export type BuildInfoType = { BUILD_DATE: tools.TimestampValueType; BUILD_VERSION?: string };
6
6
 
7
- type Dependencies = { Clock: ClockPort; JsonFileReader: FileReaderJsonPort };
7
+ type Dependencies = { Clock: ClockPort; FileReaderJson: FileReaderJsonPort };
8
8
 
9
9
  export class BuildInfoRepository {
10
10
  static async extract(deps: Dependencies): Promise<BuildInfoType> {
11
11
  const BUILD_DATE = deps.Clock.now().ms;
12
12
 
13
13
  try {
14
- const packageJson = await deps.JsonFileReader.read("package.json");
14
+ const packageJson = await deps.FileReaderJson.read("package.json");
15
15
 
16
16
  return { BUILD_DATE, BUILD_VERSION: tools.PackageVersion.fromString(packageJson.version).toString() };
17
17
  } catch {
@@ -1,32 +1,54 @@
1
- import { LRUCache } from "lru-cache";
1
+ import type { LRUCache } from "lru-cache";
2
2
  import type { CacheRepositoryPort, CacheRepositoryTtlType } from "./cache-repository.port";
3
3
  import type { Hash } from "./hash.vo";
4
4
  import type { HashValueType } from "./hash-value.vo";
5
5
 
6
+ export const CacheRepositoryLruCacheAdapterError = {
7
+ MissingDependency: "cache.repository.lru.cache.adapter.error.missing.dependency",
8
+ };
9
+
6
10
  export class CacheRepositoryLruCacheAdapter implements CacheRepositoryPort {
7
- private readonly store;
11
+ private readonly store: LRUCache<HashValueType, any>;
12
+
13
+ private constructor(store: LRUCache<HashValueType, any>) {
14
+ this.store = store;
15
+ }
16
+
17
+ static async build(config: CacheRepositoryTtlType): Promise<CacheRepositoryLruCacheAdapter> {
18
+ // biome-ignore lint: lint/suspicious/noAssignInExpressions
19
+ let LRUCacheConstructor;
8
20
 
9
- constructor(config: CacheRepositoryTtlType) {
10
- this.store = new LRUCache<HashValueType, any>({
21
+ try {
22
+ const module = await import("lru-cache");
23
+
24
+ LRUCacheConstructor = module.LRUCache;
25
+ } catch {
26
+ throw new Error(CacheRepositoryLruCacheAdapterError.MissingDependency);
27
+ }
28
+
29
+ const store = new LRUCacheConstructor<HashValueType, any>({
11
30
  max: 100_000,
12
31
  ttl: config.type === "finite" ? config.ttl.ms : undefined,
13
32
  ttlAutopurge: true,
14
33
  });
34
+
35
+ return new CacheRepositoryLruCacheAdapter(store);
15
36
  }
16
37
 
38
+ // 5. Clean implementation without null checks
17
39
  async get<T>(subject: Hash): Promise<T | null> {
18
40
  return (this.store.get(subject.get()) as T) ?? null;
19
41
  }
20
42
 
21
- async set<T>(subject: Hash, value: T) {
43
+ async set<T>(subject: Hash, value: T): Promise<void> {
22
44
  this.store.set(subject.get(), value);
23
45
  }
24
46
 
25
- async delete(subject: Hash) {
47
+ async delete(subject: Hash): Promise<void> {
26
48
  this.store.delete(subject.get());
27
49
  }
28
50
 
29
- async flush() {
51
+ async flush(): Promise<void> {
30
52
  this.store.clear();
31
53
  }
32
54
  }
@@ -1,7 +1,7 @@
1
1
  import type * as tools from "@bgord/tools";
2
2
  import type { FileReaderJsonOutputType, FileReaderJsonPort } from "./file-reader-json.port";
3
3
 
4
- export class JsonFileReaderBunAdapter implements FileReaderJsonPort {
4
+ export class FileReaderJsonBunAdapter implements FileReaderJsonPort {
5
5
  async read(
6
6
  path: tools.FilePathRelative | tools.FilePathAbsolute | string,
7
7
  ): Promise<FileReaderJsonOutputType> {
@@ -42,7 +42,7 @@ type HealthcheckResultType = {
42
42
  timestamp: tools.TimestampValueType;
43
43
  };
44
44
 
45
- type Dependencies = { Clock: ClockPort; JsonFileReader: FileReaderJsonPort; Logger: LoggerPort };
45
+ type Dependencies = { Clock: ClockPort; FileReaderJson: FileReaderJsonPort; Logger: LoggerPort };
46
46
 
47
47
  export class Healthcheck {
48
48
  static build = (Env: NodeEnvironmentEnum, _prerequisites: Prerequisite[], deps: Dependencies) =>
@@ -17,7 +17,7 @@ export type I18nConfigType = {
17
17
  defaultLanguage?: string;
18
18
  };
19
19
 
20
- type Dependencies = { JsonFileReader: FileReaderJsonPort; Logger: LoggerPort };
20
+ type Dependencies = { FileReaderJson: FileReaderJsonPort; Logger: LoggerPort };
21
21
 
22
22
  export class I18n {
23
23
  private readonly base = { component: "infra", operation: "translations" };
@@ -30,7 +30,7 @@ export class I18n {
30
30
  ) {}
31
31
 
32
32
  async getTranslations(language: tools.LanguageType): Promise<TranslationsType> {
33
- return this.deps.JsonFileReader.read(this.getTranslationPathForLanguage(language));
33
+ return this.deps.FileReaderJson.read(this.getTranslationPathForLanguage(language));
34
34
  }
35
35
 
36
36
  useTranslations(translations: TranslationsType) {
@@ -13,7 +13,7 @@ type PrerequisiteTranslationsProblemType = {
13
13
  missingIn: tools.LanguageType;
14
14
  };
15
15
 
16
- type Dependencies = { Logger: LoggerPort; JsonFileReader: FileReaderJsonPort };
16
+ type Dependencies = { Logger: LoggerPort; FileReaderJson: FileReaderJsonPort };
17
17
 
18
18
  export class PrerequisiteVerifierTranslationsAdapter implements PrerequisiteVerifierPort {
19
19
  constructor(
@@ -33,7 +33,7 @@ type Dependencies = {
33
33
  IdProvider: IdProviderPort;
34
34
  I18n: I18nConfigType;
35
35
  Clock: ClockPort;
36
- JsonFileReader: FileReaderJsonPort;
36
+ FileReaderJson: FileReaderJsonPort;
37
37
  };
38
38
 
39
39
  export class Setup {
@@ -45,7 +45,7 @@ export class Setup {
45
45
  MaintenanceMode.build(overrides?.maintenanceMode),
46
46
  secureHeaders(secureHeadersOptions),
47
47
  bodyLimit({ maxSize: BODY_LIMIT_MAX_SIZE }),
48
- ApiVersion.build({ Clock: deps.Clock, JsonFileReader: deps.JsonFileReader }),
48
+ ApiVersion.build({ Clock: deps.Clock, FileReaderJson: deps.FileReaderJson }),
49
49
  cors(corsOptions),
50
50
  languageDetector({
51
51
  supportedLanguages: Object.keys(deps.I18n.supportedLanguages),
@@ -7,7 +7,7 @@ const handler = createFactory();
7
7
 
8
8
  type Config = TranslationsSupportedLanguagesType;
9
9
 
10
- type Dependencies = { JsonFileReader: FileReaderJsonPort; Logger: LoggerPort };
10
+ type Dependencies = { FileReaderJson: FileReaderJsonPort; Logger: LoggerPort };
11
11
 
12
12
  export class Translations {
13
13
  static build = (config: Config, deps: Dependencies) =>