@bgord/bun 0.18.22 → 0.18.25

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 (93) 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/history/event-handlers/index.d.ts +3 -0
  6. package/dist/modules/history/event-handlers/index.d.ts.map +1 -0
  7. package/dist/modules/history/event-handlers/index.js +3 -0
  8. package/dist/modules/history/event-handlers/index.js.map +1 -0
  9. package/dist/modules/history/event-handlers/onHistoryClearedEvent.d.ts +4 -0
  10. package/dist/modules/history/event-handlers/onHistoryClearedEvent.d.ts.map +1 -0
  11. package/dist/modules/history/event-handlers/onHistoryClearedEvent.js +4 -0
  12. package/dist/modules/history/event-handlers/onHistoryClearedEvent.js.map +1 -0
  13. package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.d.ts +4 -0
  14. package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.d.ts.map +1 -0
  15. package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.js +6 -0
  16. package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.js.map +1 -0
  17. package/dist/modules/history/events/HISTORY_CLEARED_EVENT.d.ts +16 -0
  18. package/dist/modules/history/events/HISTORY_CLEARED_EVENT.d.ts.map +1 -0
  19. package/dist/modules/history/events/HISTORY_CLEARED_EVENT.js +16 -0
  20. package/dist/modules/history/events/HISTORY_CLEARED_EVENT.js.map +1 -0
  21. package/dist/modules/history/events/HISTORY_POPULATED_EVENT.d.ts +19 -0
  22. package/dist/modules/history/events/HISTORY_POPULATED_EVENT.d.ts.map +1 -0
  23. package/dist/modules/history/events/HISTORY_POPULATED_EVENT.js +21 -0
  24. package/dist/modules/history/events/HISTORY_POPULATED_EVENT.js.map +1 -0
  25. package/dist/modules/history/events/index.d.ts +3 -0
  26. package/dist/modules/history/events/index.d.ts.map +1 -0
  27. package/dist/modules/history/events/index.js +3 -0
  28. package/dist/modules/history/events/index.js.map +1 -0
  29. package/dist/modules/history/index.d.ts +6 -0
  30. package/dist/modules/history/index.d.ts.map +1 -0
  31. package/dist/modules/history/index.js +7 -0
  32. package/dist/modules/history/index.js.map +1 -0
  33. package/dist/modules/history/ports/history-projection.d.ts +7 -0
  34. package/dist/modules/history/ports/history-projection.d.ts.map +1 -0
  35. package/dist/modules/history/ports/history-projection.js +2 -0
  36. package/dist/modules/history/ports/history-projection.js.map +1 -0
  37. package/dist/modules/history/ports/index.d.ts +2 -0
  38. package/dist/modules/history/ports/index.d.ts.map +1 -0
  39. package/dist/modules/history/ports/index.js +2 -0
  40. package/dist/modules/history/ports/index.js.map +1 -0
  41. package/dist/modules/history/services/history-writer.d.ts +6 -0
  42. package/dist/modules/history/services/history-writer.d.ts.map +1 -0
  43. package/dist/modules/history/services/history-writer.js +2 -0
  44. package/dist/modules/history/services/history-writer.js.map +1 -0
  45. package/dist/modules/history/services/index.d.ts +2 -0
  46. package/dist/modules/history/services/index.d.ts.map +1 -0
  47. package/dist/modules/history/services/index.js +2 -0
  48. package/dist/modules/history/services/index.js.map +1 -0
  49. package/dist/modules/history/value-objects/history-id.d.ts +2 -0
  50. package/dist/modules/history/value-objects/history-id.d.ts.map +1 -0
  51. package/dist/modules/history/value-objects/history-id.js +3 -0
  52. package/dist/modules/history/value-objects/history-id.js.map +1 -0
  53. package/dist/modules/history/value-objects/history-operation.d.ts +3 -0
  54. package/dist/modules/history/value-objects/history-operation.d.ts.map +1 -0
  55. package/dist/modules/history/value-objects/history-operation.js +3 -0
  56. package/dist/modules/history/value-objects/history-operation.js.map +1 -0
  57. package/dist/modules/history/value-objects/history-payload.d.ts +4 -0
  58. package/dist/modules/history/value-objects/history-payload.d.ts.map +1 -0
  59. package/dist/modules/history/value-objects/history-payload.js +12 -0
  60. package/dist/modules/history/value-objects/history-payload.js.map +1 -0
  61. package/dist/modules/history/value-objects/history-subject.d.ts +4 -0
  62. package/dist/modules/history/value-objects/history-subject.d.ts.map +1 -0
  63. package/dist/modules/history/value-objects/history-subject.js +3 -0
  64. package/dist/modules/history/value-objects/history-subject.js.map +1 -0
  65. package/dist/modules/history/value-objects/history.d.ts +17 -0
  66. package/dist/modules/history/value-objects/history.d.ts.map +1 -0
  67. package/dist/modules/history/value-objects/history.js +18 -0
  68. package/dist/modules/history/value-objects/history.js.map +1 -0
  69. package/dist/modules/history/value-objects/index.d.ts +6 -0
  70. package/dist/modules/history/value-objects/index.d.ts.map +1 -0
  71. package/dist/modules/history/value-objects/index.js +6 -0
  72. package/dist/modules/history/value-objects/index.js.map +1 -0
  73. package/dist/tsconfig.tsbuildinfo +1 -1
  74. package/package.json +3 -3
  75. package/readme.md +18 -0
  76. package/src/index.ts +1 -0
  77. package/src/modules/history/event-handlers/index.ts +2 -0
  78. package/src/modules/history/event-handlers/onHistoryClearedEvent.ts +7 -0
  79. package/src/modules/history/event-handlers/onHistoryPopulatedEvent.ts +9 -0
  80. package/src/modules/history/events/HISTORY_CLEARED_EVENT.ts +19 -0
  81. package/src/modules/history/events/HISTORY_POPULATED_EVENT.ts +23 -0
  82. package/src/modules/history/events/index.ts +2 -0
  83. package/src/modules/history/index.ts +6 -0
  84. package/src/modules/history/ports/history-projection.ts +8 -0
  85. package/src/modules/history/ports/index.ts +1 -0
  86. package/src/modules/history/services/history-writer.ts +6 -0
  87. package/src/modules/history/services/index.ts +1 -0
  88. package/src/modules/history/value-objects/history-id.ts +3 -0
  89. package/src/modules/history/value-objects/history-operation.ts +3 -0
  90. package/src/modules/history/value-objects/history-payload.ts +12 -0
  91. package/src/modules/history/value-objects/history-subject.ts +4 -0
  92. package/src/modules/history/value-objects/history.ts +23 -0
  93. package/src/modules/history/value-objects/index.ts +5 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/bun",
3
- "version": "0.18.22",
3
+ "version": "0.18.25",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": "Bartosz Gordon",
@@ -38,8 +38,8 @@
38
38
  "dependencies": {
39
39
  "@axiomhq/winston": "1.3.1",
40
40
  "@bgord/tools": "0.12.11",
41
- "@hono/ua-blocker": "0.1.7",
42
- "better-auth": "1.3.6",
41
+ "@hono/ua-blocker": "0.1.8",
42
+ "better-auth": "1.3.7",
43
43
  "check-disk-space": "3.4.0",
44
44
  "croner": "9.1.0",
45
45
  "hcaptcha": "0.2.0",
package/readme.md CHANGED
@@ -67,6 +67,24 @@ src/
67
67
  ├── logger.service.ts
68
68
  ├── mailer.port.ts
69
69
  ├── memory-consumption.service.ts
70
+ ├── modules
71
+ │   └── history
72
+ │   ├── event-handlers
73
+ │   │   ├── onHistoryClearedEvent.ts
74
+ │   │   └── onHistoryPopulatedEvent.ts
75
+ │   ├── events
76
+ │   │   ├── HISTORY_CLEARED_EVENT.ts
77
+ │   │   ├── HISTORY_POPULATED_EVENT.ts
78
+ │   ├── ports
79
+ │   │   ├── history-projection.ts
80
+ │   ├── services
81
+ │   │   ├── history-writer.ts
82
+ │   └── value-objects
83
+ │   ├── history-id.ts
84
+ │   ├── history-operation.ts
85
+ │   ├── history-payload.ts
86
+ │   ├── history-subject.ts
87
+ │   ├── history.ts
70
88
  ├── node-cache-rate-limit-store.adapter.ts
71
89
  ├── node-env.vo.ts
72
90
  ├── noop-mailer.adapter.ts
package/src/index.ts CHANGED
@@ -40,6 +40,7 @@ export * from "./jobs.service";
40
40
  export * from "./logger.service";
41
41
  export * from "./mailer.port";
42
42
  export * from "./memory-consumption.service";
43
+ export * as History from "./modules/history";
43
44
  export * from "./node-cache-rate-limit-store.adapter";
44
45
  export * from "./node-env.vo";
45
46
  export * from "./noop-mailer.adapter";
@@ -0,0 +1,2 @@
1
+ export * from "./onHistoryClearedEvent";
2
+ export * from "./onHistoryPopulatedEvent";
@@ -0,0 +1,7 @@
1
+ import * as Events from "../events";
2
+ import * as Ports from "../ports";
3
+
4
+ export const onHistoryClearedEvent =
5
+ (projection: Ports.HistoryProjectionPort) => async (event: Events.HistoryClearedEventType) => {
6
+ await projection.clear(event.payload.subject);
7
+ };
@@ -0,0 +1,9 @@
1
+ import * as Events from "../events";
2
+ import * as Ports from "../ports";
3
+ import * as VO from "../value-objects";
4
+
5
+ export const onHistoryPopulatedEvent =
6
+ (projection: Ports.HistoryProjectionPort) => async (event: Events.HistoryPopulatedEventType) => {
7
+ const data = VO.HistoryParsed.parse(event.payload);
8
+ await projection.append(data, event.createdAt);
9
+ };
@@ -0,0 +1,19 @@
1
+ import * as tools from "@bgord/tools";
2
+ import { z } from "zod/v4";
3
+ import { UUID } from "../../../uuid.vo";
4
+ import * as VO from "../value-objects";
5
+
6
+ export const HISTORY_CLEARED_EVENT = "HISTORY_CLEARED_EVENT";
7
+
8
+ export const HistoryClearedEvent = z.object({
9
+ id: UUID,
10
+ correlationId: UUID,
11
+ createdAt: tools.Timestamp,
12
+ stream: z.string().min(1),
13
+ name: z.literal(HISTORY_CLEARED_EVENT),
14
+ version: z.literal(1),
15
+ revision: tools.RevisionValue.optional(),
16
+ payload: z.object({ subject: VO.HistorySubject }),
17
+ });
18
+
19
+ export type HistoryClearedEventType = z.infer<typeof HistoryClearedEvent>;
@@ -0,0 +1,23 @@
1
+ import * as tools from "@bgord/tools";
2
+ import { z } from "zod/v4";
3
+ import { UUID } from "../../../uuid.vo";
4
+ import * as VO from "../value-objects";
5
+
6
+ export const HISTORY_POPULATED_EVENT = "HISTORY_POPULATED_EVENT";
7
+
8
+ export const HistoryPopulatedEvent = z.object({
9
+ id: UUID,
10
+ correlationId: UUID,
11
+ createdAt: tools.Timestamp,
12
+ stream: z.string().min(1),
13
+ name: z.literal(HISTORY_POPULATED_EVENT),
14
+ version: z.literal(1),
15
+ revision: tools.RevisionValue.optional(),
16
+ payload: z.object({
17
+ id: VO.HistoryId,
18
+ operation: VO.HistoryOperation,
19
+ subject: VO.HistorySubject,
20
+ payload: VO.HistoryPayload,
21
+ }),
22
+ });
23
+ export type HistoryPopulatedEventType = z.infer<typeof HistoryPopulatedEvent>;
@@ -0,0 +1,2 @@
1
+ export * from "./HISTORY_CLEARED_EVENT";
2
+ export * from "./HISTORY_POPULATED_EVENT";
@@ -0,0 +1,6 @@
1
+ // TODO: tests
2
+ export * as EventHandlers from "./event-handlers";
3
+ export * as Events from "./events";
4
+ export * as Ports from "./ports";
5
+ export * as Services from "./services";
6
+ export * as VO from "./value-objects";
@@ -0,0 +1,8 @@
1
+ import * as tools from "@bgord/tools";
2
+ import * as VO from "../value-objects";
3
+
4
+ export interface HistoryProjectionPort {
5
+ append(data: VO.HistoryParsedType, createdAt: tools.TimestampType): Promise<void>;
6
+
7
+ clear(subject: VO.HistoryParsedType["subject"]): Promise<void>;
8
+ }
@@ -0,0 +1 @@
1
+ export * from "./history-projection";
@@ -0,0 +1,6 @@
1
+ import * as VO from "../value-objects";
2
+
3
+ export interface HistoryWriterPort {
4
+ populate(history: Omit<VO.HistoryType, "id">): Promise<void>;
5
+ clear(subject: VO.HistorySubjectType): Promise<void>;
6
+ }
@@ -0,0 +1 @@
1
+ export * from "./history-writer";
@@ -0,0 +1,3 @@
1
+ import { UUID } from "../../../uuid.vo";
2
+
3
+ export const HistoryId = UUID;
@@ -0,0 +1,3 @@
1
+ import { z } from "zod/v4";
2
+
3
+ export const HistoryOperation = z.string().min(1).max(128).trim();
@@ -0,0 +1,12 @@
1
+ import { z } from "zod/v4";
2
+
3
+ export const HistoryPayload = z.record(z.string(), z.any());
4
+
5
+ export const HistoryPayloadParsed = HistoryPayload.refine((value) => {
6
+ try {
7
+ JSON.parse(JSON.stringify(value));
8
+ return true;
9
+ } catch (error) {
10
+ return false;
11
+ }
12
+ }).transform((value) => JSON.stringify(value));
@@ -0,0 +1,4 @@
1
+ import { z } from "zod/v4";
2
+
3
+ export const HistorySubject = z.string().min(1).max(128).trim();
4
+ export type HistorySubjectType = z.infer<typeof HistorySubject>;
@@ -0,0 +1,23 @@
1
+ import { z } from "zod/v4";
2
+ import { HistoryId } from "./history-id";
3
+ import { HistoryOperation } from "./history-operation";
4
+ import { HistoryPayload, HistoryPayloadParsed } from "./history-payload";
5
+ import { HistorySubject } from "./history-subject";
6
+
7
+ const History = z.object({
8
+ id: HistoryId,
9
+ operation: HistoryOperation,
10
+ payload: HistoryPayload,
11
+ subject: HistorySubject,
12
+ });
13
+
14
+ export type HistoryType = z.infer<typeof History>;
15
+
16
+ export const HistoryParsed = z.object({
17
+ id: HistoryId,
18
+ operation: HistoryOperation,
19
+ payload: HistoryPayloadParsed,
20
+ subject: HistorySubject,
21
+ });
22
+
23
+ export type HistoryParsedType = z.infer<typeof HistoryParsed>;
@@ -0,0 +1,5 @@
1
+ export * from "./history";
2
+ export * from "./history-id";
3
+ export * from "./history-operation";
4
+ export * from "./history-payload";
5
+ export * from "./history-subject";