drimion 0.1.0 → 0.1.1
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/cli/index.js
CHANGED
|
@@ -8,7 +8,15 @@ import { DomainError } from "../helpers";
|
|
|
8
8
|
* @throws {DomainError} If the event name does not contain a colon separator.
|
|
9
9
|
*/
|
|
10
10
|
export const ValidateEventName = (eventName: string): void => {
|
|
11
|
-
if (
|
|
11
|
+
if (typeof eventName !== "string") {
|
|
12
|
+
throw new DomainError(`Invalid event name. Expected a string.`, {
|
|
13
|
+
context: "DomainEvent",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const parts = eventName.split(":");
|
|
18
|
+
|
|
19
|
+
if (parts.length !== 2 || parts[0]?.length === 0 || parts[1]?.length === 0) {
|
|
12
20
|
throw new DomainError(
|
|
13
21
|
`Invalid event name "${eventName}". ` +
|
|
14
22
|
'Event names must follow the pattern "context:EventName" ' +
|
|
@@ -16,4 +24,14 @@ export const ValidateEventName = (eventName: string): void => {
|
|
|
16
24
|
{ context: "DomainEvent" },
|
|
17
25
|
);
|
|
18
26
|
}
|
|
27
|
+
|
|
28
|
+
const validPattern = /^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$/;
|
|
29
|
+
if (!validPattern.test(eventName)) {
|
|
30
|
+
throw new DomainError(
|
|
31
|
+
`Invalid event name "${eventName}". ` +
|
|
32
|
+
"Context and event name must only contain lowercase letters, numbers, and hyphens " +
|
|
33
|
+
'(e.g., "order:placed", "user:email-changed").',
|
|
34
|
+
{ context: "DomainEvent" },
|
|
35
|
+
);
|
|
36
|
+
}
|
|
19
37
|
};
|