Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose findAllByQuery method in modules and services #1044

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export * from './storage/BaseRecord'
export { InMemoryMessageRepository } from './storage/InMemoryMessageRepository'
export { Repository } from './storage/Repository'
export * from './storage/RepositoryEvents'
export { StorageService } from './storage/StorageService'
export { StorageService, Query } from './storage/StorageService'
export { getDirFromFilePath } from './utils/path'
export { InjectionSymbols } from './constants'
export type { Wallet } from './wallet/Wallet'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'
import type { Logger } from '../../../logger'
import type { Query } from '../../../storage/StorageService'
import type { ActionMenuStateChangedEvent } from '../ActionMenuEvents'
import type { ActionMenuProblemReportMessage } from '../messages'
import type {
Expand Down Expand Up @@ -346,6 +347,10 @@ export class ActionMenuService {
})
}

public async findAllByQuery(options: Query<ActionMenuRecord>) {
return await this.actionMenuRepository.findByQuery(options)
}

private emitStateChangedEvent(actionMenuRecord: ActionMenuRecord, previousState: ActionMenuState | null) {
const clonedRecord = JsonTransformer.clone(actionMenuRecord)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { DependencyManager } from '../../plugins'
import type { BasicMessageTags } from './repository/BasicMessageRecord'
import type { Query } from '../../storage/StorageService'
import type { BasicMessageRecord } from './repository/BasicMessageRecord'

import { Dispatcher } from '../../agent/Dispatcher'
import { MessageSender } from '../../agent/MessageSender'
Expand Down Expand Up @@ -59,7 +60,7 @@ export class BasicMessagesModule {
* @param query The query
* @returns array containing all matching records
*/
public async findAllByQuery(query: Partial<BasicMessageTags>) {
public async findAllByQuery(query: Query<BasicMessageRecord>) {
return this.basicMessageService.findAllByQuery(query)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'
import type { Query } from '../../../storage/StorageService'
import type { ConnectionRecord } from '../../connections/repository/ConnectionRecord'
import type { BasicMessageStateChangedEvent } from '../BasicMessageEvents'
import type { BasicMessageTags } from '../repository'

import { EventEmitter } from '../../../agent/EventEmitter'
import { injectable } from '../../../plugins'
Expand Down Expand Up @@ -61,7 +61,7 @@ export class BasicMessageService {
})
}

public async findAllByQuery(query: Partial<BasicMessageTags>) {
public async findAllByQuery(query: Query<BasicMessageRecord>) {
return this.basicMessageRepository.findByQuery(query)
}

Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/modules/connections/ConnectionsModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DependencyManager } from '../../plugins'
import type { Query } from '../../storage/StorageService'
import type { Key } from '../dids'
import type { OutOfBandRecord } from '../oob/repository'
import type { ConnectionType } from './models'
Expand Down Expand Up @@ -198,6 +199,15 @@ export class ConnectionsModule {
return this.connectionService.getAll()
}

/**
* Retrieve all connections records by specified query params
*
* @returns List containing all connection records matching specified query paramaters
*/
public findAllByQuery(query: Query<ConnectionRecord>) {
return this.connectionService.findAllByQuery(query)
}

/**
* Allows for the addition of connectionType to the record.
* Either updates or creates an array of string conection types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,5 +897,15 @@ describe('ConnectionService', () => {

expect(result).toEqual(expect.arrayContaining(expected))
})

it('findAllByQuery should return value from connectionRepository.findByQuery', async () => {
const expected = [getMockConnection(), getMockConnection()]

mockFunction(connectionRepository.findByQuery).mockReturnValue(Promise.resolve(expected))
const result = await connectionService.findAllByQuery({ state: DidExchangeState.InvitationReceived })
expect(connectionRepository.findByQuery).toBeCalledWith({ state: DidExchangeState.InvitationReceived })

expect(result).toEqual(expect.arrayContaining(expected))
})
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AgentMessage } from '../../../agent/AgentMessage'
import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'
import type { Logger } from '../../../logger'
import type { Query } from '../../../storage/StorageService'
import type { AckMessage } from '../../common'
import type { OutOfBandDidCommService } from '../../oob/domain/OutOfBandDidCommService'
import type { OutOfBandRecord } from '../../oob/repository'
Expand Down Expand Up @@ -592,6 +593,10 @@ export class ConnectionService {
return this.connectionRepository.findByQuery({ invitationDid })
}

public async findAllByQuery(query: Query<ConnectionRecord>): Promise<ConnectionRecord[]> {
return this.connectionRepository.findByQuery(query)
}

public async createConnection(options: ConnectionRecordProps): Promise<ConnectionRecord> {
const connectionRecord = new ConnectionRecord(options)
await this.connectionRepository.save(connectionRecord)
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/modules/credentials/CredentialsModule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AgentMessage } from '../../agent/AgentMessage'
import type { Logger } from '../../logger'
import type { DependencyManager } from '../../plugins'
import type { Query } from '../../storage/StorageService'
import type { DeleteCredentialOptions } from './CredentialServiceOptions'
import type {
AcceptCredentialOptions,
Expand Down Expand Up @@ -73,6 +74,7 @@ export interface CredentialsModule<CFs extends CredentialFormat[], CSs extends C

// Record Methods
getAll(): Promise<CredentialExchangeRecord[]>
findAllByQuery(query: Query<CredentialExchangeRecord>): Promise<CredentialExchangeRecord[]>
getById(credentialRecordId: string): Promise<CredentialExchangeRecord>
findById(credentialRecordId: string): Promise<CredentialExchangeRecord | null>
deleteById(credentialRecordId: string, options?: DeleteCredentialOptions): Promise<void>
Expand Down Expand Up @@ -573,6 +575,15 @@ export class CredentialsModule<
return this.credentialRepository.getAll()
}

/**
* Retrieve all credential records by specified query params
*
* @returns List containing all credential records matching specified query paramaters
*/
public findAllByQuery(query: Query<CredentialExchangeRecord>) {
return this.credentialRepository.findByQuery(query)
}

/**
* Find a credential record by id
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,16 @@ describe('V1CredentialService', () => {

expect(result).toEqual(expect.arrayContaining(expected))
})

it('findAllByQuery should return value from credentialRepository.findByQuery', async () => {
const expected = [mockCredentialRecord(), mockCredentialRecord()]

mockFunction(credentialRepository.findByQuery).mockReturnValue(Promise.resolve(expected))
const result = await credentialService.findAllByQuery({ state: CredentialState.OfferSent })
expect(credentialRepository.findByQuery).toBeCalledWith({ state: CredentialState.OfferSent })

expect(result).toEqual(expect.arrayContaining(expected))
})
})

describe('deleteCredential', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,16 @@ describe('CredentialService', () => {

expect(result).toEqual(expect.arrayContaining(expected))
})

it('findAllByQuery should return value from credentialRepository.findByQuery', async () => {
const expected = [mockCredentialRecord(), mockCredentialRecord()]

mockFunction(credentialRepository.findByQuery).mockReturnValue(Promise.resolve(expected))
const result = await credentialService.findAllByQuery({ state: CredentialState.OfferSent })
expect(credentialRepository.findByQuery).toBeCalledWith({ state: CredentialState.OfferSent })

expect(result).toEqual(expect.arrayContaining(expected))
})
})

describe('deleteCredential', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { EventEmitter } from '../../../agent/EventEmitter'
import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'
import type { Logger } from '../../../logger'
import type { DidCommMessageRepository } from '../../../storage'
import type { Query } from '../../../storage/StorageService'
import type { ProblemReportMessage } from '../../problem-reports'
import type { CredentialStateChangedEvent } from '../CredentialEvents'
import type {
Expand Down Expand Up @@ -185,6 +186,10 @@ export abstract class CredentialService<CFs extends CredentialFormat[] = Credent
return this.credentialRepository.getAll()
}

public async findAllByQuery(query: Query<CredentialExchangeRecord>): Promise<CredentialExchangeRecord[]> {
return this.credentialRepository.findByQuery(query)
}

/**
* Find a credential record by id
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Logger } from '../../logger'
import type { DependencyManager } from '../../plugins'
import type { GenericRecord, GenericRecordTags, SaveGenericRecordOption } from './repository/GenericRecord'
import type { Query } from '../../storage/StorageService'
import type { GenericRecord, SaveGenericRecordOption } from './repository/GenericRecord'

import { AgentConfig } from '../../agent/AgentConfig'
import { injectable, module } from '../../plugins'
Expand Down Expand Up @@ -74,7 +75,7 @@ export class GenericRecordsModule {
return this.genericRecordsService.findById(id)
}

public async findAllByQuery(query: Partial<GenericRecordTags>): Promise<GenericRecord[]> {
public async findAllByQuery(query: Query<GenericRecord>): Promise<GenericRecord[]> {
return this.genericRecordsService.findAllByQuery(query)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { GenericRecordTags, SaveGenericRecordOption } from '../repository/GenericRecord'
import type { Query } from '../../../storage/StorageService'
import type { SaveGenericRecordOption } from '../repository/GenericRecord'

import { AriesFrameworkError } from '../../../error'
import { injectable } from '../../../plugins'
Expand Down Expand Up @@ -50,7 +51,7 @@ export class GenericRecordService {
}
}

public async findAllByQuery(query: Partial<GenericRecordTags>) {
public async findAllByQuery(query: Query<GenericRecord>) {
return this.genericRecordsRepository.findByQuery(query)
}

Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/modules/oob/OutOfBandModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Attachment } from '../../decorators/attachment/Attachment'
import type { Logger } from '../../logger'
import type { ConnectionRecord, Routing, ConnectionInvitationMessage } from '../../modules/connections'
import type { DependencyManager } from '../../plugins'
import type { Query } from '../../storage/StorageService'
import type { PlaintextMessage } from '../../types'
import type { Key } from '../dids'
import type { HandshakeReusedEvent } from './domain/OutOfBandEvents'
Expand Down Expand Up @@ -533,6 +534,15 @@ export class OutOfBandModule {
return this.outOfBandService.getAll()
}

/**
* Retrieve all out of bands records by specified query param
*
* @returns List containing all out of band records matching specified query params
*/
public findAllByQuery(query: Query<OutOfBandRecord>) {
return this.outOfBandService.findAllByQuery(query)
}

/**
* Retrieve a out of band record by id
*
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/modules/oob/OutOfBandService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { InboundMessageContext } from '../../agent/models/InboundMessageContext'
import type { Query } from '../../storage/StorageService'
import type { ConnectionRecord } from '../connections'
import type { Key } from '../dids/domain/Key'
import type { HandshakeReusedEvent, OutOfBandStateChangedEvent } from './domain/OutOfBandEvents'
Expand Down Expand Up @@ -167,6 +168,10 @@ export class OutOfBandService {
return this.outOfBandRepository.getAll()
}

public async findAllByQuery(query: Query<OutOfBandRecord>) {
return this.outOfBandRepository.findByQuery(query)
}

public async deleteById(outOfBandId: string) {
const outOfBandRecord = await this.getById(outOfBandId)
return this.outOfBandRepository.delete(outOfBandRecord)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,5 +495,15 @@ describe('OutOfBandService', () => {

expect(result).toEqual(expect.arrayContaining(expected))
})

it('findAllByQuery should return value from outOfBandRepository.findByQuery', async () => {
const expected = [getMockOutOfBand(), getMockOutOfBand()]

mockFunction(outOfBandRepository.findByQuery).mockReturnValue(Promise.resolve(expected))
const result = await outOfBandService.findAllByQuery({ state: OutOfBandState.Initial })
expect(outOfBandRepository.findByQuery).toBeCalledWith({ state: OutOfBandState.Initial })

expect(result).toEqual(expect.arrayContaining(expected))
})
})
})
10 changes: 10 additions & 0 deletions packages/core/src/modules/proofs/ProofsModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DependencyManager } from '../../plugins'
import type { Query } from '../../storage/StorageService'
import type { AutoAcceptProof } from './ProofAutoAcceptType'
import type { PresentationPreview, RequestPresentationMessage } from './messages'
import type { RequestedCredentials, RetrievedCredentials } from './models'
Expand Down Expand Up @@ -414,6 +415,15 @@ export class ProofsModule {
return this.proofService.getAll()
}

/**
* Retrieve all proof records by specified query params
*
* @returns List containing all proof records matching specified params
*/
public findAllByQuery(query: Query<ProofRecord>): Promise<ProofRecord[]> {
return this.proofService.findAllByQuery(query)
}

/**
* Retrieve a proof record by id
*
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/modules/proofs/services/ProofService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AgentMessage } from '../../../agent/AgentMessage'
import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'
import type { Logger } from '../../../logger'
import type { Query } from '../../../storage/StorageService'
import type { ConnectionRecord } from '../../connections'
import type { AutoAcceptProof } from '../ProofAutoAcceptType'
import type { ProofStateChangedEvent } from '../ProofEvents'
Expand Down Expand Up @@ -938,6 +939,15 @@ export class ProofService {
return this.proofRepository.getAll()
}

/**
* Retrieve all proof records
*
* @returns List containing all proof records
*/
public async findAllByQuery(query: Query<ProofRecord>): Promise<ProofRecord[]> {
return this.proofRepository.findByQuery(query)
}

/**
* Retrieve a proof record by id
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { DependencyManager } from '../../plugins'
import type { Query } from '../../storage/StorageService'
import type { QuestionAnswerRecord } from './repository'

import { Dispatcher } from '../../agent/Dispatcher'
import { MessageSender } from '../../agent/MessageSender'
Expand Down Expand Up @@ -92,6 +94,15 @@ export class QuestionAnswerModule {
return this.questionAnswerService.getAll()
}

/**
* Get all QuestionAnswer records by specified query params
*
* @returns list containing all QuestionAnswer records matching specified query params
*/
public findAllByQuery(query: Query<QuestionAnswerRecord>) {
return this.questionAnswerService.findAllByQuery(query)
}

/**
* Retrieve a question answer record by id
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'
import type { Logger } from '../../../logger'
import type { Query } from '../../../storage/StorageService'
import type { QuestionAnswerStateChangedEvent } from '../QuestionAnswerEvents'
import type { ValidResponse } from '../models'
import type { QuestionAnswerTags } from '../repository'

import { AgentConfig } from '../../../agent/AgentConfig'
import { EventEmitter } from '../../../agent/EventEmitter'
Expand Down Expand Up @@ -269,7 +269,7 @@ export class QuestionAnswerService {
return this.questionAnswerRepository.getAll()
}

public async findAllByQuery(query: Partial<QuestionAnswerTags>) {
public async findAllByQuery(query: Query<QuestionAnswerRecord>) {
return this.questionAnswerRepository.findByQuery(query)
}
}
Loading