-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: module to api and module config
Signed-off-by: Timo Glastra <timo@animo.id>
- Loading branch information
1 parent
c8e6e53
commit 5141660
Showing
58 changed files
with
820 additions
and
504 deletions.
There are no files selected for viewing
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
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
49 changes: 49 additions & 0 deletions
49
packages/core/src/modules/basic-messages/BasicMessagesApi.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,49 @@ | ||
import type { BasicMessageTags } from './repository/BasicMessageRecord' | ||
|
||
import { AgentContext } from '../../agent' | ||
import { Dispatcher } from '../../agent/Dispatcher' | ||
import { MessageSender } from '../../agent/MessageSender' | ||
import { createOutboundMessage } from '../../agent/helpers' | ||
import { injectable } from '../../plugins' | ||
import { ConnectionService } from '../connections' | ||
|
||
import { BasicMessageHandler } from './handlers' | ||
import { BasicMessageService } from './services' | ||
|
||
@injectable() | ||
export class BasicMessagesApi { | ||
private basicMessageService: BasicMessageService | ||
private messageSender: MessageSender | ||
private connectionService: ConnectionService | ||
private agentContext: AgentContext | ||
|
||
public constructor( | ||
dispatcher: Dispatcher, | ||
basicMessageService: BasicMessageService, | ||
messageSender: MessageSender, | ||
connectionService: ConnectionService, | ||
agentContext: AgentContext | ||
) { | ||
this.basicMessageService = basicMessageService | ||
this.messageSender = messageSender | ||
this.connectionService = connectionService | ||
this.agentContext = agentContext | ||
this.registerHandlers(dispatcher) | ||
} | ||
|
||
public async sendMessage(connectionId: string, message: string) { | ||
const connection = await this.connectionService.getById(this.agentContext, connectionId) | ||
|
||
const basicMessage = await this.basicMessageService.createMessage(this.agentContext, message, connection) | ||
const outboundMessage = createOutboundMessage(connection, basicMessage) | ||
await this.messageSender.sendMessage(this.agentContext, outboundMessage) | ||
} | ||
|
||
public async findAllByQuery(query: Partial<BasicMessageTags>) { | ||
return this.basicMessageService.findAllByQuery(this.agentContext, query) | ||
} | ||
|
||
private registerHandlers(dispatcher: Dispatcher) { | ||
dispatcher.registerHandler(new BasicMessageHandler(this.basicMessageService)) | ||
} | ||
} |
50 changes: 4 additions & 46 deletions
50
packages/core/src/modules/basic-messages/BasicMessagesModule.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
23 changes: 23 additions & 0 deletions
23
packages/core/src/modules/basic-messages/__tests__/BasicMessagesModule.test.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,23 @@ | ||
import { DependencyManager } from '../../../plugins/DependencyManager' | ||
import { BasicMessagesApi } from '../BasicMessagesApi' | ||
import { BasicMessagesModule } from '../BasicMessagesModule' | ||
import { BasicMessageRepository } from '../repository' | ||
import { BasicMessageService } from '../services' | ||
|
||
jest.mock('../../../plugins/DependencyManager') | ||
const DependencyManagerMock = DependencyManager as jest.Mock<DependencyManager> | ||
|
||
const dependencyManager = new DependencyManagerMock() | ||
|
||
describe('BasicMessagesModule', () => { | ||
test('registers dependencies on the dependency manager', () => { | ||
new BasicMessagesModule().register(dependencyManager) | ||
|
||
expect(dependencyManager.registerContextScoped).toHaveBeenCalledTimes(1) | ||
expect(dependencyManager.registerContextScoped).toHaveBeenCalledWith(BasicMessagesApi) | ||
|
||
expect(dependencyManager.registerSingleton).toHaveBeenCalledTimes(2) | ||
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(BasicMessageService) | ||
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(BasicMessageRepository) | ||
}) | ||
}) |
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
Oops, something went wrong.