Skip to content

Commit

Permalink
feat(question-answer)!: separate logic to a new module (#1040)
Browse files Browse the repository at this point in the history
Signed-off-by: blu3beri <[email protected]>

BREAKING CHANGE: question-answer module has been removed from the core and moved to a separate package. To integrate it in an Agent instance, it can be injected in constructor like this:
```ts
const agent = new Agent({
  config: { /* config */ },
  dependencies: agentDependencies,
  modules: {
    questionAnswer: new QuestionAnswerModule(),
    /* other custom modules */
   }
})
```

Then, module API can be accessed in `agent.modules.questionAnswer`.
  • Loading branch information
berendsliedrecht authored Oct 11, 2022
1 parent 34658b0 commit 97d3073
Show file tree
Hide file tree
Showing 38 changed files with 332 additions and 150 deletions.
2 changes: 0 additions & 2 deletions packages/core/src/agent/AgentModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { IndyModule } from '../modules/indy'
import { LedgerModule } from '../modules/ledger'
import { OutOfBandModule } from '../modules/oob'
import { ProofsModule } from '../modules/proofs'
import { QuestionAnswerModule } from '../modules/question-answer'
import { MediatorModule, RecipientModule } from '../modules/routing'
import { W3cVcModule } from '../modules/vc'
import { WalletModule } from '../wallet'
Expand Down Expand Up @@ -118,7 +117,6 @@ function getDefaultAgentModules(agentConfig: AgentConfig) {
mediatorPollingInterval: agentConfig.mediatorPollingInterval,
}),
basicMessages: () => new BasicMessagesModule(),
questionAnswer: () => new QuestionAnswerModule(),
actionMenu: () => new ActionMenuModule(),
genericRecords: () => new GenericRecordsModule(),
ledger: () =>
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/agent/BaseAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { GenericRecordsApi } from '../modules/generic-records'
import { LedgerApi } from '../modules/ledger'
import { OutOfBandApi } from '../modules/oob'
import { ProofsApi } from '../modules/proofs/ProofsApi'
import { QuestionAnswerApi } from '../modules/question-answer'
import { MediatorApi, RecipientApi } from '../modules/routing'
import { StorageUpdateService } from '../storage'
import { UpdateAssistant } from '../storage/migration/UpdateAssistant'
Expand Down Expand Up @@ -50,7 +49,6 @@ export abstract class BaseAgent<AgentModules extends ModulesMap = EmptyModuleMap
public readonly mediationRecipient: RecipientApi
public readonly basicMessages: BasicMessagesApi
public readonly actionMenu: ActionMenuApi
public readonly questionAnswer: QuestionAnswerApi
public readonly genericRecords: GenericRecordsApi
public readonly ledger: LedgerApi
public readonly discovery: DiscoverFeaturesApi
Expand Down Expand Up @@ -93,7 +91,6 @@ export abstract class BaseAgent<AgentModules extends ModulesMap = EmptyModuleMap
this.mediationRecipient = this.dependencyManager.resolve(RecipientApi)
this.basicMessages = this.dependencyManager.resolve(BasicMessagesApi)
this.actionMenu = this.dependencyManager.resolve(ActionMenuApi)
this.questionAnswer = this.dependencyManager.resolve(QuestionAnswerApi)
this.genericRecords = this.dependencyManager.resolve(GenericRecordsApi)
this.ledger = this.dependencyManager.resolve(LedgerApi)
this.discovery = this.dependencyManager.resolve(DiscoverFeaturesApi)
Expand All @@ -109,7 +106,6 @@ export abstract class BaseAgent<AgentModules extends ModulesMap = EmptyModuleMap
this.mediationRecipient,
this.basicMessages,
this.actionMenu,
this.questionAnswer,
this.genericRecords,
this.ledger,
this.discovery,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/agent/__tests__/Agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ describe('Agent', () => {
'https://didcomm.org/present-proof/1.0',
'https://didcomm.org/revocation_notification/1.0',
'https://didcomm.org/revocation_notification/2.0',
'https://didcomm.org/questionanswer/1.0',
])
)
expect(protocols.length).toEqual(16)
expect(protocols.length).toEqual(15)
})
})
25 changes: 9 additions & 16 deletions packages/core/src/agent/__tests__/AgentModules.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import type { Module } from '../../plugins'

import {
ActionMenuModule,
ConnectionsModule,
CredentialsModule,
ProofsModule,
MediatorModule,
RecipientModule,
BasicMessagesModule,
QuestionAnswerModule,
LedgerModule,
DidsModule,
OutOfBandModule,
} from '../..'
import { getAgentConfig } from '../../../tests/helpers'
import { ActionMenuModule } from '../../modules/action-menu'
import { BasicMessagesModule } from '../../modules/basic-messages'
import { ConnectionsModule } from '../../modules/connections'
import { CredentialsModule } from '../../modules/credentials'
import { DidsModule } from '../../modules/dids'
import { DiscoverFeaturesModule } from '../../modules/discover-features'
import { GenericRecordsModule } from '../../modules/generic-records'
import { IndyModule } from '../../modules/indy'
import { LedgerModule } from '../../modules/ledger'
import { OutOfBandModule } from '../../modules/oob'
import { ProofsModule } from '../../modules/proofs'
import { MediatorModule, RecipientModule } from '../../modules/routing'
import { W3cVcModule } from '../../modules/vc'
import { DependencyManager, injectable } from '../../plugins'
import { WalletModule } from '../../wallet'
Expand Down Expand Up @@ -70,7 +66,6 @@ describe('AgentModules', () => {
mediationRecipient: expect.any(RecipientModule),
basicMessages: expect.any(BasicMessagesModule),
actionMenu: expect.any(ActionMenuModule),
questionAnswer: expect.any(QuestionAnswerModule),
genericRecords: expect.any(GenericRecordsModule),
ledger: expect.any(LedgerModule),
discovery: expect.any(DiscoverFeaturesModule),
Expand All @@ -96,7 +91,6 @@ describe('AgentModules', () => {
mediationRecipient: expect.any(RecipientModule),
basicMessages: expect.any(BasicMessagesModule),
actionMenu: expect.any(ActionMenuModule),
questionAnswer: expect.any(QuestionAnswerModule),
genericRecords: expect.any(GenericRecordsModule),
ledger: expect.any(LedgerModule),
discovery: expect.any(DiscoverFeaturesModule),
Expand Down Expand Up @@ -125,7 +119,6 @@ describe('AgentModules', () => {
mediationRecipient: expect.any(RecipientModule),
basicMessages: expect.any(BasicMessagesModule),
actionMenu: expect.any(ActionMenuModule),
questionAnswer: expect.any(QuestionAnswerModule),
genericRecords: expect.any(GenericRecordsModule),
ledger: expect.any(LedgerModule),
discovery: expect.any(DiscoverFeaturesModule),
Expand Down
11 changes: 5 additions & 6 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export { EventEmitter } from './agent/EventEmitter'
export { FeatureRegistry } from './agent/FeatureRegistry'
export { Handler, HandlerInboundMessage } from './agent/Handler'
export * from './agent/models'
export * from './agent/helpers'
export { AgentConfig } from './agent/AgentConfig'
export { AgentMessage } from './agent/AgentMessage'
export { Dispatcher } from './agent/Dispatcher'
Expand Down Expand Up @@ -38,9 +39,6 @@ export type { TransportSession } from './agent/TransportService'
export { TransportService } from './agent/TransportService'
export { Attachment } from './decorators/attachment/Attachment'

import { parseInvitationUrl } from './utils/parseInvitation'
import { uuid } from './utils/uuid'

export * from './plugins'
export * from './transport'
export * from './modules/action-menu'
Expand All @@ -52,19 +50,20 @@ export * from './modules/proofs'
export * from './modules/connections'
export * from './modules/ledger'
export * from './modules/routing'
export * from './modules/question-answer'
export * from './modules/oob'
export * from './modules/dids'
export * from './modules/vc'
export { JsonEncoder, JsonTransformer, isJsonObject, isValidJweStructure, TypedArrayEncoder, Buffer } from './utils'
export * from './logger'
export * from './error'
export * from './wallet/error'
export * from './crypto'
export { parseMessageType, IsValidMessageType } from './utils/messageType'
export type { Constructor } from './utils/mixins'

export * from './agent/Events'
export * from './crypto/'

import { parseInvitationUrl } from './utils/parseInvitation'
import { uuid } from './utils/uuid'

const utils = {
uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import type { Wallet } from '../../../wallet'
import { convertPublicKeyToX25519 } from '@stablelib/ed25519'

import { getAgentOptions } from '../../../../tests/helpers'
import { Agent } from '../../../agent/Agent'
import { InjectionSymbols } from '../../../constants'
import { Key, KeyType } from '../../../crypto'
import { JsonTransformer } from '../../../utils'
import { sleep } from '../../../utils/sleep'

import { InjectionSymbols, Key, KeyType, JsonTransformer, Agent } from '@aries-framework/core'

describe('dids', () => {
let agent: Agent

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/wallet/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './Wallet'
export * from './IndyWallet'
export * from './WalletApi'
export * from './WalletModule'
export * from './IndyWallet'
9 changes: 7 additions & 2 deletions packages/core/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
SchemaTemplate,
Wallet,
} from '../src'
import type { AgentModulesInput } from '../src/agent/AgentModules'
import type { IndyOfferCredentialFormat } from '../src/modules/credentials/formats/indy/IndyCredentialFormat'
import type { RequestProofOptions } from '../src/modules/proofs/ProofsApiOptions'
import type { ProofAttributeInfo, ProofPredicateInfo } from '../src/modules/proofs/formats/indy/models'
Expand Down Expand Up @@ -73,7 +74,11 @@ export const genesisPath = process.env.GENESIS_TXN_PATH
export const publicDidSeed = process.env.TEST_AGENT_PUBLIC_DID_SEED ?? '000000000000000000000000Trustee9'
export { agentDependencies }

export function getAgentOptions(name: string, extraConfig: Partial<InitConfig> = {}) {
export function getAgentOptions<AgentModules extends AgentModulesInput>(
name: string,
extraConfig: Partial<InitConfig> = {},
modules?: AgentModules
) {
const config: InitConfig = {
label: `Agent: ${name}`,
walletConfig: {
Expand All @@ -98,7 +103,7 @@ export function getAgentOptions(name: string, extraConfig: Partial<InitConfig> =
...extraConfig,
}

return { config, dependencies: agentDependencies } as const
return { config, modules, dependencies: agentDependencies } as const
}

export function getPostgresAgentOptions(name: string, extraConfig: Partial<InitConfig> = {}) {
Expand Down
31 changes: 31 additions & 0 deletions packages/question-answer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<p align="center">
<br />
<img
alt="Hyperledger Aries logo"
src="https://raw.githubusercontent.com/hyperledger/aries-framework-javascript/aa31131825e3331dc93694bc58414d955dcb1129/images/aries-logo.png"
height="250px"
/>
</p>
<h1 align="center"><b>Aries Framework JavaScript - Question Answer</b></h1>
<p align="center">
<a
href="https://raw.githubusercontent.com/hyperledger/aries-framework-javascript/main/LICENSE"
><img
alt="License"
src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"
/></a>
<a href="https://www.typescriptlang.org/"
><img
alt="typescript"
src="https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg"
/></a>
<a href="https://www.npmjs.com/package/@aries-framework/question-answer"
><img
alt="@aries-framework/question-answer version"
src="https://img.shields.io/npm/v/@aries-framework/question-answer"
/></a>

</p>
<br />

TODO
13 changes: 13 additions & 0 deletions packages/question-answer/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Config } from '@jest/types'

import base from '../../jest.config.base'

import packageJson from './package.json'

const config: Config.InitialOptions = {
...base,
name: packageJson.name,
displayName: packageJson.name,
}

export default config
40 changes: 40 additions & 0 deletions packages/question-answer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@aries-framework/question-answer",
"main": "build/index",
"types": "build/index",
"version": "0.2.2",
"private": true,
"files": [
"build"
],
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/hyperledger/aries-framework-javascript/tree/main/packages/question-answer",
"repository": {
"type": "git",
"url": "https://github.com/hyperledger/aries-framework-javascript",
"directory": "packages/question-answer"
},
"scripts": {
"build": "yarn run clean && yarn run compile",
"clean": "rimraf -rf ./build",
"compile": "tsc -p tsconfig.build.json",
"prepublishOnly": "yarn run build",
"test": "jest"
},
"dependencies": {
"@aries-framework/core": "0.2.4",
"rxjs": "^7.2.0",
"class-transformer": "0.5.1",
"class-validator": "0.13.1"
},
"devDependencies": {
"@aries-framework/core": "0.2.4",
"@aries-framework/node": "0.2.4",
"reflect-metadata": "^0.1.13",
"rimraf": "~3.0.2",
"typescript": "~4.3.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { Query } from '../../storage/StorageService'
import type { QuestionAnswerRecord } from './repository'

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 type { Query } from '@aries-framework/core'

import {
AgentContext,
ConnectionService,
createOutboundMessage,
Dispatcher,
injectable,
MessageSender,
} from '@aries-framework/core'

import { AnswerMessageHandler, QuestionMessageHandler } from './handlers'
import { ValidResponse } from './models'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BaseEvent } from '../../agent/Events'
import type { QuestionAnswerState } from './models'
import type { QuestionAnswerRecord } from './repository'
import type { BaseEvent } from '@aries-framework/core'

export enum QuestionAnswerEventTypes {
QuestionAnswerStateChanged = 'QuestionAnswerStateChanged',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { FeatureRegistry } from '../../agent/FeatureRegistry'
import type { DependencyManager, Module } from '../../plugins'
import type { DependencyManager, FeatureRegistry, Module } from '@aries-framework/core'

import { Protocol } from '../../agent/models'
import { Protocol } from '@aries-framework/core'

import { QuestionAnswerApi } from './QuestionAnswerApi'
import { QuestionAnswerRole } from './QuestionAnswerRole'
Expand Down
Loading

0 comments on commit 97d3073

Please sign in to comment.