@bgord/bun 1.4.20 → 1.4.23

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.
Files changed (31) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/modules/preferences/command-handlers/handleSetUserLanguageCommand.d.ts +7 -1
  6. package/dist/modules/preferences/command-handlers/handleSetUserLanguageCommand.d.ts.map +1 -1
  7. package/dist/modules/preferences/command-handlers/handleSetUserLanguageCommand.js +4 -4
  8. package/dist/modules/preferences/command-handlers/handleSetUserLanguageCommand.js.map +1 -1
  9. package/dist/tsconfig.tsbuildinfo +1 -1
  10. package/dist/visitor-id-hash-hono.adapter.d.ts +1 -1
  11. package/dist/visitor-id-hash-hono.adapter.d.ts.map +1 -1
  12. package/dist/visitor-id-hash-hono.adapter.js +2 -1
  13. package/dist/visitor-id-hash-hono.adapter.js.map +1 -1
  14. package/dist/visitor-id-hash.adapter.d.ts +1 -1
  15. package/dist/visitor-id-hash.adapter.d.ts.map +1 -1
  16. package/dist/visitor-id-hash.adapter.js +3 -1
  17. package/dist/visitor-id-hash.adapter.js.map +1 -1
  18. package/dist/visitor-id.port.d.ts +1 -1
  19. package/dist/visitor-id.port.d.ts.map +1 -1
  20. package/dist/visitor-id.vo.d.ts +9 -0
  21. package/dist/visitor-id.vo.d.ts.map +1 -0
  22. package/dist/visitor-id.vo.js +12 -0
  23. package/dist/visitor-id.vo.js.map +1 -0
  24. package/package.json +1 -1
  25. package/readme.md +1 -0
  26. package/src/index.ts +1 -0
  27. package/src/modules/preferences/command-handlers/handleSetUserLanguageCommand.ts +11 -10
  28. package/src/visitor-id-hash-hono.adapter.ts +2 -1
  29. package/src/visitor-id-hash.adapter.ts +4 -1
  30. package/src/visitor-id.port.ts +1 -1
  31. package/src/visitor-id.vo.ts +15 -0
@@ -3,6 +3,6 @@ import type { VisitorIdPort } from "./visitor-id.port";
3
3
  export declare class VisitorIdHashHonoAdapter implements VisitorIdPort {
4
4
  private readonly delegate;
5
5
  constructor(context: Context);
6
- get(): Promise<string>;
6
+ get(): Promise<string & import("zod").$brand<"VisitorId">>;
7
7
  }
8
8
  //# sourceMappingURL=visitor-id-hash-hono.adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"visitor-id-hash-hono.adapter.d.ts","sourceRoot":"","sources":["../src/visitor-id-hash-hono.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,qBAAa,wBAAyB,YAAW,aAAa;IAC5D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;gBAEpC,OAAO,EAAE,OAAO;IAItB,GAAG;CAGV"}
1
+ {"version":3,"file":"visitor-id-hash-hono.adapter.d.ts","sourceRoot":"","sources":["../src/visitor-id-hash-hono.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvD,qBAAa,wBAAyB,YAAW,aAAa;IAC5D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;gBAEpC,OAAO,EAAE,OAAO;IAItB,GAAG;CAGV"}
@@ -1,4 +1,5 @@
1
1
  import { ClientFromHonoAdapter } from "./client-from-hono.adapter";
2
+ import { VisitorId } from "./visitor-id.vo";
2
3
  import { VisitorIdHashAdapter } from "./visitor-id-hash.adapter";
3
4
  export class VisitorIdHashHonoAdapter {
4
5
  delegate;
@@ -6,7 +7,7 @@ export class VisitorIdHashHonoAdapter {
6
7
  this.delegate = new VisitorIdHashAdapter(ClientFromHonoAdapter.extract(context));
7
8
  }
8
9
  async get() {
9
- return this.delegate.get();
10
+ return VisitorId.parse(await this.delegate.get());
10
11
  }
11
12
  }
12
13
  //# sourceMappingURL=visitor-id-hash-hono.adapter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"visitor-id-hash-hono.adapter.js","sourceRoot":"","sources":["../src/visitor-id-hash-hono.adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,OAAO,wBAAwB;IAClB,QAAQ,CAAuB;IAEhD,YAAY,OAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,oBAAoB,CAAC,qBAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACnF,CAAC;IAED,KAAK,CAAC,GAAG;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IAC7B,CAAC;CACF"}
1
+ {"version":3,"file":"visitor-id-hash-hono.adapter.js","sourceRoot":"","sources":["../src/visitor-id-hash-hono.adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,OAAO,wBAAwB;IAClB,QAAQ,CAAuB;IAEhD,YAAY,OAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,oBAAoB,CAAC,qBAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACnF,CAAC;IAED,KAAK,CAAC,GAAG;QACP,OAAO,SAAS,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IACpD,CAAC;CACF"}
@@ -3,6 +3,6 @@ import type { VisitorIdPort } from "./visitor-id.port";
3
3
  export declare class VisitorIdHashAdapter implements VisitorIdPort {
4
4
  private readonly client;
5
5
  constructor(client: Client);
6
- get(): Promise<string>;
6
+ get(): Promise<string & import("zod").$brand<"VisitorId">>;
7
7
  }
8
8
  //# sourceMappingURL=visitor-id-hash.adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"visitor-id-hash.adapter.d.ts","sourceRoot":"","sources":["../src/visitor-id-hash.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,qBAAa,oBAAqB,YAAW,aAAa;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAErC,GAAG;CAWV"}
1
+ {"version":3,"file":"visitor-id-hash.adapter.d.ts","sourceRoot":"","sources":["../src/visitor-id-hash.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,qBAAa,oBAAqB,YAAW,aAAa;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAErC,GAAG;CAaV"}
@@ -1,3 +1,4 @@
1
+ import { VisitorId } from "./visitor-id.vo";
1
2
  export class VisitorIdHashAdapter {
2
3
  client;
3
4
  constructor(client) {
@@ -7,10 +8,11 @@ export class VisitorIdHashAdapter {
7
8
  const { ip, ua } = this.client.toJSON();
8
9
  const value = `${ip}|${ua}`;
9
10
  const buffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value));
10
- return Array.from(new Uint8Array(buffer))
11
+ const result = Array.from(new Uint8Array(buffer))
11
12
  .slice(0, 8)
12
13
  .map((b) => b.toString(16).padStart(2, "0"))
13
14
  .join("");
15
+ return VisitorId.parse(result);
14
16
  }
15
17
  }
16
18
  //# sourceMappingURL=visitor-id-hash.adapter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"visitor-id-hash.adapter.js","sourceRoot":"","sources":["../src/visitor-id-hash.adapter.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,oBAAoB;IACF;IAA7B,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,KAAK,CAAC,GAAG;QACP,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAExC,MAAM,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAEtF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;aACtC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;aACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;aAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;CACF"}
1
+ {"version":3,"file":"visitor-id-hash.adapter.js","sourceRoot":"","sources":["../src/visitor-id-hash.adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,oBAAoB;IACF;IAA7B,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,KAAK,CAAC,GAAG;QACP,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAExC,MAAM,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAEtF,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;aAC9C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;aACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;aAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,OAAO,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- export type VisitorIdType = string;
1
+ import type { VisitorIdType } from "./visitor-id.vo";
2
2
  export interface VisitorIdPort {
3
3
  get(): Promise<VisitorIdType>;
4
4
  }
@@ -1 +1 @@
1
- {"version":3,"file":"visitor-id.port.d.ts","sourceRoot":"","sources":["../src/visitor-id.port.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,MAAM,WAAW,aAAa;IAC5B,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CAC/B"}
1
+ {"version":3,"file":"visitor-id.port.d.ts","sourceRoot":"","sources":["../src/visitor-id.port.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,WAAW,aAAa;IAC5B,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CAC/B"}
@@ -0,0 +1,9 @@
1
+ import { z } from "zod/v4";
2
+ export declare const VisitorIdError: {
3
+ readonly Type: "visitor.id.type";
4
+ readonly Empty: "visitor.id.empty";
5
+ readonly TooLong: "visitor.id.too.long";
6
+ };
7
+ export declare const VisitorId: z.core.$ZodBranded<z.ZodString, "VisitorId">;
8
+ export type VisitorIdType = z.infer<typeof VisitorId>;
9
+ //# sourceMappingURL=visitor-id.vo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visitor-id.vo.d.ts","sourceRoot":"","sources":["../src/visitor-id.vo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,eAAO,MAAM,cAAc;;;;CAIjB,CAAC;AAEX,eAAO,MAAM,SAAS,8CAID,CAAC;AAEtB,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { z } from "zod/v4";
2
+ export const VisitorIdError = {
3
+ Type: "visitor.id.type",
4
+ Empty: "visitor.id.empty",
5
+ TooLong: "visitor.id.too.long",
6
+ };
7
+ export const VisitorId = z
8
+ .string(VisitorIdError.Type)
9
+ .min(1, VisitorIdError.Empty)
10
+ .max(16, VisitorIdError.TooLong)
11
+ .brand("VisitorId");
12
+ //# sourceMappingURL=visitor-id.vo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visitor-id.vo.js","sourceRoot":"","sources":["../src/visitor-id.vo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,iBAAiB;IACvB,KAAK,EAAE,kBAAkB;IACzB,OAAO,EAAE,qBAAqB;CACtB,CAAC;AAEX,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC;KACvB,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;KAC3B,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC;KAC5B,GAAG,CAAC,EAAE,EAAE,cAAc,CAAC,OAAO,CAAC;KAC/B,KAAK,CAAC,WAAW,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/bun",
3
- "version": "1.4.20",
3
+ "version": "1.4.23",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": "Bartosz Gordon",
package/readme.md CHANGED
@@ -266,6 +266,7 @@ src/
266
266
  ├── visitor-id-hash-hono.adapter.ts
267
267
  ├── visitor-id-hash.adapter.ts
268
268
  ├── visitor-id.port.ts
269
+ ├── visitor-id.vo.ts
269
270
  └── weak-etag-extractor.middleware.ts
270
271
  ```
271
272
 
package/src/index.ts CHANGED
@@ -185,6 +185,7 @@ export * from "./translations.service";
185
185
  export * from "./uptime.service";
186
186
  export * from "./uuid.vo";
187
187
  export * from "./visitor-id.port";
188
+ export * from "./visitor-id.vo";
188
189
  export * from "./visitor-id-hash.adapter";
189
190
  export * from "./visitor-id-hash-hono.adapter";
190
191
  export * from "./weak-etag-extractor.middleware";
@@ -9,27 +9,28 @@ import * as Invariants from "../invariants";
9
9
  import type * as Ports from "../ports";
10
10
  import type * as VO from "../value-objects";
11
11
 
12
+ type Dependencies = {
13
+ EventStore: EventStoreLike<AcceptedEvent>;
14
+ IdProvider: IdProviderPort;
15
+ Clock: ClockPort;
16
+ UserLanguageQuery: Ports.UserLanguageQueryPort;
17
+ };
18
+
12
19
  type AcceptedEvent = Events.UserLanguageSetEventType;
13
20
 
14
21
  export const handleSetUserLanguageCommand =
15
- <L extends readonly tools.LanguageType[]>(
16
- EventStore: EventStoreLike<AcceptedEvent>,
17
- IdProvider: IdProviderPort,
18
- Clock: ClockPort,
19
- query: Ports.UserLanguageQueryPort,
20
- supported: VO.SupportedLanguagesSet<L>,
21
- ) =>
22
+ <L extends readonly tools.LanguageType[]>(supported: VO.SupportedLanguagesSet<L>, deps: Dependencies) =>
22
23
  async (command: Commands.SetUserLanguageCommandType) => {
23
24
  const candidate = supported.ensure(command.payload.language);
24
- const current = await query.get(command.payload.userId);
25
+ const current = await deps.UserLanguageQuery.get(command.payload.userId);
25
26
 
26
27
  if (Invariants.UserLanguageHasChanged.fails({ current, candidate: command.payload.language })) return;
27
28
 
28
29
  const event = Events.UserLanguageSetEvent.parse({
29
- ...createEventEnvelope(`preferences_${command.payload.userId}`, { IdProvider, Clock }),
30
+ ...createEventEnvelope(`preferences_${command.payload.userId}`, deps),
30
31
  name: Events.USER_LANGUAGE_SET_EVENT,
31
32
  payload: { userId: command.payload.userId, language: candidate },
32
33
  } satisfies Events.UserLanguageSetEventType);
33
34
 
34
- await EventStore.save([event]);
35
+ await deps.EventStore.save([event]);
35
36
  };
@@ -1,6 +1,7 @@
1
1
  import type { Context } from "hono";
2
2
  import { ClientFromHonoAdapter } from "./client-from-hono.adapter";
3
3
  import type { VisitorIdPort } from "./visitor-id.port";
4
+ import { VisitorId } from "./visitor-id.vo";
4
5
  import { VisitorIdHashAdapter } from "./visitor-id-hash.adapter";
5
6
 
6
7
  export class VisitorIdHashHonoAdapter implements VisitorIdPort {
@@ -11,6 +12,6 @@ export class VisitorIdHashHonoAdapter implements VisitorIdPort {
11
12
  }
12
13
 
13
14
  async get() {
14
- return this.delegate.get();
15
+ return VisitorId.parse(await this.delegate.get());
15
16
  }
16
17
  }
@@ -1,5 +1,6 @@
1
1
  import type { Client } from "./client.vo";
2
2
  import type { VisitorIdPort } from "./visitor-id.port";
3
+ import { VisitorId } from "./visitor-id.vo";
3
4
 
4
5
  export class VisitorIdHashAdapter implements VisitorIdPort {
5
6
  constructor(private readonly client: Client) {}
@@ -10,9 +11,11 @@ export class VisitorIdHashAdapter implements VisitorIdPort {
10
11
  const value = `${ip}|${ua}`;
11
12
  const buffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value));
12
13
 
13
- return Array.from(new Uint8Array(buffer))
14
+ const result = Array.from(new Uint8Array(buffer))
14
15
  .slice(0, 8)
15
16
  .map((b) => b.toString(16).padStart(2, "0"))
16
17
  .join("");
18
+
19
+ return VisitorId.parse(result);
17
20
  }
18
21
  }
@@ -1,4 +1,4 @@
1
- export type VisitorIdType = string;
1
+ import type { VisitorIdType } from "./visitor-id.vo";
2
2
 
3
3
  export interface VisitorIdPort {
4
4
  get(): Promise<VisitorIdType>;
@@ -0,0 +1,15 @@
1
+ import { z } from "zod/v4";
2
+
3
+ export const VisitorIdError = {
4
+ Type: "visitor.id.type",
5
+ Empty: "visitor.id.empty",
6
+ TooLong: "visitor.id.too.long",
7
+ } as const;
8
+
9
+ export const VisitorId = z
10
+ .string(VisitorIdError.Type)
11
+ .min(1, VisitorIdError.Empty)
12
+ .max(16, VisitorIdError.TooLong)
13
+ .brand("VisitorId");
14
+
15
+ export type VisitorIdType = z.infer<typeof VisitorId>;