(
variants: EventVariant[],
packageName: string,
packageDir: string
)
| 756 | } |
| 757 | |
| 758 | async function generateSessionEventBaseClass( |
| 759 | variants: EventVariant[], |
| 760 | packageName: string, |
| 761 | packageDir: string |
| 762 | ): Promise<void> { |
| 763 | const lines: string[] = []; |
| 764 | lines.push(COPYRIGHT); |
| 765 | lines.push(""); |
| 766 | lines.push(AUTO_GENERATED_HEADER); |
| 767 | lines.push(GENERATED_FROM_SESSION_EVENTS); |
| 768 | lines.push(""); |
| 769 | lines.push(`package ${packageName};`); |
| 770 | lines.push(""); |
| 771 | lines.push(`import com.fasterxml.jackson.annotation.JsonIgnoreProperties;`); |
| 772 | lines.push(`import com.fasterxml.jackson.annotation.JsonInclude;`); |
| 773 | lines.push(`import com.fasterxml.jackson.annotation.JsonProperty;`); |
| 774 | lines.push(`import com.fasterxml.jackson.annotation.JsonSubTypes;`); |
| 775 | lines.push(`import com.fasterxml.jackson.annotation.JsonTypeInfo;`); |
| 776 | lines.push(`import java.time.OffsetDateTime;`); |
| 777 | lines.push(`import java.util.UUID;`); |
| 778 | lines.push(`import javax.annotation.processing.Generated;`); |
| 779 | lines.push(""); |
| 780 | lines.push(`/**`); |
| 781 | lines.push(` * Base class for all generated session events.`); |
| 782 | lines.push(` *`); |
| 783 | lines.push(` * @since 1.0.0`); |
| 784 | lines.push(` */`); |
| 785 | lines.push(`@JsonIgnoreProperties(ignoreUnknown = true)`); |
| 786 | lines.push(`@JsonInclude(JsonInclude.Include.NON_NULL)`); |
| 787 | lines.push(`@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = UnknownSessionEvent.class)`); |
| 788 | lines.push(`@JsonSubTypes({`); |
| 789 | for (let i = 0; i < variants.length; i++) { |
| 790 | const v = variants[i]; |
| 791 | const comma = i < variants.length - 1 ? "," : ""; |
| 792 | lines.push(` @JsonSubTypes.Type(value = ${v.className}.class, name = "${v.typeName}")${comma}`); |
| 793 | } |
| 794 | lines.push(`})`); |
| 795 | lines.push(GENERATED_ANNOTATION); |
| 796 | |
| 797 | // Build the permits clause (all variant classes + UnknownSessionEvent last) |
| 798 | const allPermitted = [...variants.map((v) => v.className), "UnknownSessionEvent"]; |
| 799 | lines.push(`public abstract sealed class SessionEvent permits`); |
| 800 | for (let i = 0; i < allPermitted.length; i++) { |
| 801 | const comma = i < allPermitted.length - 1 ? "," : " {"; |
| 802 | lines.push(` ${allPermitted[i]}${comma}`); |
| 803 | } |
| 804 | lines.push(""); |
| 805 | lines.push(` /** Unique event identifier (UUID v4), generated when the event is emitted. */`); |
| 806 | lines.push(` @JsonProperty("id")`); |
| 807 | lines.push(` private UUID id;`); |
| 808 | lines.push(""); |
| 809 | lines.push(` /** ISO 8601 timestamp when the event was created. */`); |
| 810 | lines.push(` @JsonProperty("timestamp")`); |
| 811 | lines.push(` private OffsetDateTime timestamp;`); |
| 812 | lines.push(""); |
| 813 | lines.push(` /** ID of the chronologically preceding event in the session. Null for the first event. */`); |
| 814 | lines.push(` @JsonProperty("parentId")`); |
| 815 | lines.push(` private UUID parentId;`); |
no test coverage detected
searching dependent graphs…