-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: hxtree <[email protected]>
- Loading branch information
Showing
17 changed files
with
146 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. | ||
{ | ||
"pnpmShrinkwrapHash": "ce36f6df36614b70a396c456d4d1b8847dbed82b", | ||
"pnpmShrinkwrapHash": "35dba17277aaf467f308553d1ab16371c6243f4b", | ||
"preferredVersionsHash": "8ae0ba5bd02ec9c5763773a15e27aee08a6567f6" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
libraries/messaging-schemas/src/dto/events/character-joined-party.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IsUuidV4 } from '@cats-cradle/validation-schemas'; | ||
import { BaseEventDto } from './base-event.dto'; | ||
|
||
export class CharacterJoinedParty extends BaseEventDto { | ||
@IsUuidV4() | ||
public instanceId: string; | ||
|
||
@IsUuidV4() | ||
public characterId: string; | ||
} |
10 changes: 10 additions & 0 deletions
10
libraries/messaging-schemas/src/dto/events/character-left-party.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IsUuidV4 } from '@cats-cradle/validation-schemas'; | ||
import { BaseEventDto } from './base-event.dto'; | ||
|
||
export class CharacterLeftPartyEvent extends BaseEventDto { | ||
@IsUuidV4() | ||
public instanceId: string; | ||
|
||
@IsUuidV4() | ||
public characterId: string; | ||
} |
7 changes: 5 additions & 2 deletions
7
libraries/messaging-schemas/src/dto/events/character-level-up.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
libraries/messaging-schemas/src/dto/queries/character-level-reply.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IsInt, IsUuidV4 } from '@cats-cradle/validation-schemas'; | ||
import { BaseRequestDto } from './base-request.dto'; | ||
|
||
export class CharacterLevelReply extends BaseRequestDto { | ||
@IsUuidV4() | ||
public instanceId: string; | ||
|
||
@IsUuidV4() | ||
public characterId: string; | ||
|
||
@IsInt() | ||
public level: string; | ||
} |
10 changes: 10 additions & 0 deletions
10
libraries/messaging-schemas/src/dto/queries/character-level-request.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IsUuidV4 } from '@cats-cradle/validation-schemas'; | ||
import { BaseRequestDto } from './base-request.dto'; | ||
|
||
export class CharacterLevelRequest extends BaseRequestDto { | ||
@IsUuidV4() | ||
public instanceId: string; | ||
|
||
@IsUuidV4() | ||
public characterId: string; | ||
} |
3 changes: 0 additions & 3 deletions
3
libraries/messaging-schemas/src/dto/responses/base-response.dto.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from './dto/messages'; | ||
export * from './dto/commands'; | ||
export * from './dto/events'; | ||
export * from './dto/responses'; | ||
export { messageRegistry } from './registry/message-registry'; | ||
export { MessageFactory } from './message-factory'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { BaseMessageDto } from './dto/messages'; | ||
import { MessageFactory } from './message-factory'; | ||
import { CharacterLevelUpEvent } from './dto/events/character-level-up.event'; | ||
|
||
describe('MessageFactory', () => { | ||
let message: CharacterLevelUpEvent; | ||
|
||
beforeAll(async () => { | ||
process.env.AWS_ACCOUNT_ID = '123456789012'; | ||
process.env.AWS_REGION = 'us-east-2'; | ||
process.env.STAGE_NAME = 'default'; | ||
process.env.APP_NAME = 'message-broker'; | ||
|
||
message = await MessageFactory.create<CharacterLevelUpEvent>( | ||
CharacterLevelUpEvent, | ||
{ level: 3 }, | ||
); | ||
}); | ||
|
||
it('should populate messageId with uuid', async () => { | ||
expect(message.messageId).toHaveLength(36); | ||
}); | ||
|
||
it('should populate time', async () => { | ||
expect(message.timestamp).toHaveLength(24); | ||
}); | ||
|
||
it('should populate partial info', async () => { | ||
expect(message.level).toBe(3); | ||
}); | ||
|
||
it('should populate queueName', async () => { | ||
expect(message.queueName).toBe( | ||
'default-message-broker-character-level-up-event-queue', | ||
); | ||
}); | ||
|
||
it('should populate topicArn', async () => { | ||
expect(message.topicArn).toBe( | ||
'arn:aws:sns:us-east-2:123456789012:default-character-level-up-event-topic', | ||
); | ||
}); | ||
|
||
it('should not leave fields undefined if not defined', async () => { | ||
expect(message.characterId).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ClassConstructor, plainToInstance } from 'class-transformer'; | ||
import { v4 } from 'uuid'; | ||
|
||
export class MessageFactory { | ||
public static create<T>( | ||
constructor: ClassConstructor<unknown>, | ||
partial: Partial<T> = {}, | ||
): Promise<T> { | ||
return new MessageFactory().create(constructor, partial); | ||
} | ||
|
||
public async create<T>( | ||
constructor: ClassConstructor<unknown>, | ||
partial: Partial<T> = {}, | ||
): Promise<T> { | ||
const now = new Date(); | ||
const auto = { | ||
messageId: v4(), | ||
timestamp: now.toISOString(), | ||
}; | ||
const objectInstance = plainToInstance(constructor, { | ||
...partial, | ||
...auto, | ||
}); | ||
|
||
return objectInstance as T; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters