Skip to content

Commit

Permalink
refactor: further removing of keri naming
Browse files Browse the repository at this point in the history
  • Loading branch information
iFergal committed Apr 29, 2024
1 parent 915e499 commit efc6e0f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 36 deletions.
4 changes: 1 addition & 3 deletions src/core/agent/services/connectionService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ describe("Connection service of agent", () => {
},
});
expect(
await connectionService.getConnectionKeriShortDetailById(
keriContacts[0].id
)
await connectionService.getConnectionShortDetailById(keriContacts[0].id)
).toMatchObject({
id: keriContacts[0].id,
connectionDate: nowISO,
Expand Down
45 changes: 21 additions & 24 deletions src/core/agent/services/connectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ConnectionService extends AgentService {
"Invalid connectionless OOBI - does not contain d_m parameter";
static readonly CONNECTION_NOTE_RECORD_NOT_FOUND =
"Connection note record not found";
static readonly CONNECTION_KERI_METADATA_RECORD_NOT_FOUND =
"Connection keri metadata record not found";
static readonly CONNECTION_METADATA_RECORD_NOT_FOUND =
"Connection metadata record not found";
static readonly DEFAULT_ROLE = "agent";

static readonly FAILED_TO_RESOLVE_OOBI =
Expand Down Expand Up @@ -54,7 +54,7 @@ class ConnectionService extends AgentService {
});
const operation = await this.resolveOobi(url);
const connectionId = operation.response.i;
await this.createConnectionKeriMetadata(connectionId, {
await this.createConnectionMetadata(connectionId, {
alias: operation.alias,
oobi: url,
});
Expand Down Expand Up @@ -115,14 +115,14 @@ class ConnectionService extends AgentService {

async getConnections(): Promise<ConnectionShortDetails[]> {
const connectionsDetails: ConnectionShortDetails[] = [];
const connectionKeriMetadatas = await this.getAllConnectionKeriMetadata();
connectionKeriMetadatas.forEach(async (connection) => {
connectionsDetails.push(this.getConnectionKeriShortDetails(connection));
const metadatas = await this.getAllConnectionMetadata();
metadatas.forEach(async (connection) => {
connectionsDetails.push(this.getConnectionShortDetails(connection));
});
return connectionsDetails;
}

private getConnectionKeriShortDetails(
private getConnectionShortDetails(
record: BasicRecord
): ConnectionShortDetails {
return {
Expand All @@ -141,7 +141,7 @@ class ConnectionService extends AgentService {
id: connection.id,
status: ConnectionStatus.CONFIRMED,
connectionDate: (
await this.getConnectionKeriMetadataById(connection.id)
await this.getConnectionMetadataById(connection.id)
).createdAt.toISOString(),
serviceEndpoints: [connection.oobi],
notes: await this.getConnectNotesByConnectionId(connection.id),
Expand All @@ -157,11 +157,11 @@ class ConnectionService extends AgentService {
}
}

async getConnectionKeriShortDetailById(
async getConnectionShortDetailById(
id: string
): Promise<ConnectionShortDetails> {
const metadata = await this.getConnectionKeriMetadataById(id);
return this.getConnectionKeriShortDetails(metadata);
const metadata = await this.getConnectionMetadataById(id);
return this.getConnectionShortDetails(metadata);
}

async createConnectionNote(
Expand Down Expand Up @@ -202,7 +202,7 @@ class ConnectionService extends AgentService {
return alias ? `${oobi}?name=${encodeURIComponent(alias)}` : oobi;
}

private async createConnectionKeriMetadata(
private async createConnectionMetadata(
connectionId: string,
metadata?: Record<string, unknown>
): Promise<void> {
Expand All @@ -215,23 +215,20 @@ class ConnectionService extends AgentService {
});
}

private async getConnectionKeriMetadataById(
private async getConnectionMetadataById(
connectionId: string
): Promise<BasicRecord> {
const connectionKeri = await this.basicStorage.findById(connectionId);
if (!connectionKeri) {
throw new Error(
ConnectionService.CONNECTION_KERI_METADATA_RECORD_NOT_FOUND
);
const connection = await this.basicStorage.findById(connectionId);
if (!connection) {
throw new Error(ConnectionService.CONNECTION_METADATA_RECORD_NOT_FOUND);
}
return connectionKeri;
return connection;
}

async getAllConnectionKeriMetadata(): Promise<BasicRecord[]> {
const connectionKeris = await this.basicStorage.findAllByQuery({
async getAllConnectionMetadata(): Promise<BasicRecord[]> {
return this.basicStorage.findAllByQuery({
type: RecordType.KERIA_CONNECTION_METADATA,
});
return connectionKeris;
}

async getConnectionHistoryById(
Expand All @@ -256,15 +253,15 @@ class ConnectionService extends AgentService {

async syncKeriaContacts() {
const signifyContacts = await this.signifyClient.contacts().list();
const storageContacts = await this.getAllConnectionKeriMetadata();
const storageContacts = await this.getAllConnectionMetadata();
const unSyncedData = signifyContacts.filter(
(contact: KeriaContact) =>
!storageContacts.find((item: BasicRecord) => contact.id == item.id)
);
if (unSyncedData.length) {
//sync the storage with the signify data
for (const contact of unSyncedData) {
await this.createConnectionKeriMetadata(contact.id, {
await this.createConnectionMetadata(contact.id, {
alias: contact.alias,
oobi: contact.oobi,
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/agent/services/identifierService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jest.mock("../../../core/agent/agent", () => ({
Agent: {
agent: {
connections: {
getConnectionKeriShortDetailById: jest.fn(),
getConnectionShortDetailById: jest.fn(),
getConnections: jest.fn(),
},
},
Expand Down
12 changes: 6 additions & 6 deletions src/core/agent/services/multiSigService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jest.mock("../../../core/agent/agent", () => ({
Agent: {
agent: {
connections: {
getConnectionKeriShortDetailById: jest.fn(),
getConnectionShortDetailById: jest.fn(),
resolveOobi: () => mockResolveOobi(),
},
identifiers: { getIdentifiers: () => mockGetIdentifiers() },
Expand Down Expand Up @@ -768,7 +768,7 @@ describe("Multisig sig service of agent", () => {
},
]);
mockGetIdentifiers = jest.fn().mockResolvedValue([identifierMetadata]);
Agent.agent.connections.getConnectionKeriShortDetailById = jest
Agent.agent.connections.getConnectionShortDetailById = jest
.fn()
.mockResolvedValue(senderData);
Agent.agent.connections.getConnections = jest.fn().mockResolvedValue([]);
Expand Down Expand Up @@ -814,7 +814,7 @@ describe("Multisig sig service of agent", () => {
},
]);
mockGetIdentifiers = jest.fn().mockResolvedValue([identifierMetadata]);
Agent.agent.connections.getConnectionKeriShortDetailById = jest
Agent.agent.connections.getConnectionShortDetailById = jest
.fn()
.mockResolvedValue(senderData);
Agent.agent.connections.getConnections = jest.fn().mockResolvedValue([
Expand Down Expand Up @@ -878,7 +878,7 @@ describe("Multisig sig service of agent", () => {
},
]);
mockGetIdentifiers = jest.fn().mockResolvedValue([identifierMetadata]);
Agent.agent.connections.getConnectionKeriShortDetailById = jest
Agent.agent.connections.getConnectionShortDetailById = jest
.fn()
.mockResolvedValue(senderData);
Agent.agent.connections.getConnections = jest.fn().mockResolvedValue([
Expand Down Expand Up @@ -936,7 +936,7 @@ describe("Multisig sig service of agent", () => {
]);
mockGetIdentifiers = jest.fn().mockResolvedValue([identifierMetadata]);
jest
.spyOn(Agent.agent.connections, "getConnectionKeriShortDetailById")
.spyOn(Agent.agent.connections, "getConnectionShortDetailById")
.mockResolvedValue(senderData);
jest.spyOn(Agent.agent.connections, "getConnections").mockResolvedValue([
{
Expand Down Expand Up @@ -982,7 +982,7 @@ describe("Multisig sig service of agent", () => {
]);
// @TODO - foconnor: This is not ideal as our identifier service is getting tightly coupled with the connection service.
// Re-work this later.
Agent.agent.connections.getConnectionKeriShortDetailById = jest
Agent.agent.connections.getConnectionShortDetailById = jest
.fn()
.mockImplementation(() => {
throw new Error("Some error from connection service");
Expand Down
2 changes: 1 addition & 1 deletion src/core/agent/services/multiSigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class MultiSigService extends AgentService {
const senderAid = icpMsg[0].exn.i;
// @TODO - foconnor: This cross service call should be handled better.
const senderContact =
await Agent.agent.connections.getConnectionKeriShortDetailById(
await Agent.agent.connections.getConnectionShortDetailById(
icpMsg[0].exn.i
);

Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/AppWrapper/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const connectionStateChangedHandler = async (
} else {
const connectionRecordId = event.payload.connectionId!;
const connectionDetails =
await Agent.agent.connections.getConnectionKeriShortDetailById(
await Agent.agent.connections.getConnectionShortDetailById(
connectionRecordId
);
dispatch(updateOrAddConnectionCache(connectionDetails));
Expand Down

0 comments on commit efc6e0f

Please sign in to comment.