@@ -10,7 +10,7 @@ function generateGenericEventType(fileName) {
|
||||
const program = ts.createProgram([fileName], {})
|
||||
const sourceFile = program.getSourceFile(fileName)
|
||||
|
||||
let genericEventType = 'export type GenericEvent =\n'
|
||||
let genericEventType = '// Auto Generaged type.\nexport type GenericEvent =\n'
|
||||
|
||||
ts.forEachChild(sourceFile, (node) => {
|
||||
if (
|
||||
@@ -22,11 +22,16 @@ function generateGenericEventType(fileName) {
|
||||
const key = member.name
|
||||
let eventType = ''
|
||||
let isLiteralType = false
|
||||
|
||||
if (
|
||||
ts.isComputedPropertyName(key) &&
|
||||
ts.isPropertyAccessExpression(key.expression)
|
||||
) {
|
||||
eventType = key.expression.name.text
|
||||
} else if (ts.isIdentifier(key) && key.escapedText) {
|
||||
// Handle string key like 'health_check'
|
||||
eventType = key.escapedText
|
||||
isLiteralType = true
|
||||
} else if (ts.isStringLiteral(key)) {
|
||||
// Handle string literal types like 'health-check'
|
||||
eventType = key.text
|
||||
|
||||
@@ -36,6 +36,9 @@ export interface EventPayloadMapping {
|
||||
[BusinessEvents.PAGE_DELETE]: PayloadOnlyId
|
||||
|
||||
[BusinessEvents.SAY_CREATE]: SayModel
|
||||
[BusinessEvents.SAY_UPDATE]: SayModel
|
||||
[BusinessEvents.SAY_DELETE]: PayloadOnlyId
|
||||
|
||||
[BusinessEvents.RECENTLY_CREATE]: RecentlyModel
|
||||
|
||||
[BusinessEvents.ACTIVITY_LIKE]: IActivityLike
|
||||
@@ -58,6 +61,7 @@ export interface IActivityLike {
|
||||
}
|
||||
}
|
||||
|
||||
// Auto Generaged type.
|
||||
export type GenericEvent =
|
||||
| { type: BusinessEvents.POST_CREATE; payload: NormalizedPost }
|
||||
| { type: BusinessEvents.POST_UPDATE; payload: NormalizedPost }
|
||||
@@ -69,6 +73,8 @@ export type GenericEvent =
|
||||
| { type: BusinessEvents.PAGE_UPDATE; payload: PageModel }
|
||||
| { type: BusinessEvents.PAGE_DELETE; payload: PayloadOnlyId }
|
||||
| { type: BusinessEvents.SAY_CREATE; payload: SayModel }
|
||||
| { type: BusinessEvents.SAY_UPDATE; payload: SayModel }
|
||||
| { type: BusinessEvents.SAY_DELETE; payload: PayloadOnlyId }
|
||||
| { type: BusinessEvents.RECENTLY_CREATE; payload: RecentlyModel }
|
||||
| { type: BusinessEvents.ACTIVITY_LIKE; payload: IActivityLike }
|
||||
| { type: BusinessEvents.LINK_APPLY; payload: LinkModel }
|
||||
@@ -78,3 +84,4 @@ export type GenericEvent =
|
||||
ref: Id | PostModel | PageModel | NoteModel | RecentlyModel
|
||||
}
|
||||
}
|
||||
| { type: 'health_check'; payload: {} }
|
||||
|
||||
Reference in New Issue
Block a user