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

chore(migrations)!: connections 0.3.0 migration script and tests #1177

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3b5fd0c
Adds custom rxjs operator to filter record events by record type, to …
amanji Jun 9, 2022
d4e1c86
Merge remote-tracking branch 'upstream/main' into main
amanji Jun 27, 2022
9f0a85d
Merge remote-tracking branch 'upstream/main' into main
amanji Nov 3, 2022
1c772b1
Merge remote-tracking branch 'upstream/main' into main
amanji Dec 14, 2022
f8af37d
Merge branch 'hyperledger:main' into main
amanji Dec 16, 2022
0601dfe
Merge branch 'hyperledger:main' into main
amanji Dec 19, 2022
5629ccd
chore(migraton): add connections migration script for AFJ 0.3.0
amanji Dec 15, 2022
5c67e9c
chore(migration): add tests for 0.2.0-0.3.0 connection records migration
amanji Dec 15, 2022
477effc
Merge branch 'main' into connections-0.3.0-migration
amanji Dec 19, 2022
08dcc0e
Revert "Adds custom rxjs operator to filter record events by record t…
amanji Dec 19, 2022
ff8702b
Merge branch 'main' into connections-0.3.0-migration
amanji Dec 21, 2022
c0be64e
feat(connections): add internal metadata keys
amanji Dec 21, 2022
dd289ae
chore(connections): rename type property for `DefaultConnectionTags`
amanji Dec 21, 2022
c5bfbea
feat(connections): add connection type field to connection record
amanji Dec 21, 2022
1ba6abc
refactor(connections): update methods to store connection types direc…
amanji Dec 21, 2022
884e9ac
refactor(connections): migration scripts add tags directly to records…
amanji Dec 21, 2022
df0b3c9
Merge branch 'main' into connections-0.3.0-migration
amanji Dec 21, 2022
206d8ec
refactor(connection): remove metadata connection types
amanji Dec 21, 2022
4fd018a
Merge branch 'connections-0.3.0-migration' of https://github.com/petr…
amanji Dec 21, 2022
c6eb743
refactor(connection) get tags method gets value from record field
amanji Dec 21, 2022
c332309
Update packages/core/src/modules/connections/repository/ConnectionRec…
amanji Dec 21, 2022
cd13696
Update packages/core/src/modules/connections/services/ConnectionServi…
amanji Dec 21, 2022
6d3317a
refactor(connections): address PR comments
amanji Dec 21, 2022
d0929df
Merge branch 'connections-0.3.0-migration' of https://github.com/petr…
amanji Dec 21, 2022
d258cff
refactor(connections) address PR comments
amanji Dec 21, 2022
18e4b9b
chore(connections): fix failing tests
amanji Dec 21, 2022
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
6 changes: 3 additions & 3 deletions packages/core/src/modules/connections/ConnectionsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class ConnectionsApi {

/**
* Allows for the addition of connectionType to the record.
* Either updates or creates an array of string conection types
* Either updates or creates an array of string connection types
* @param connectionId
* @param type
* @throws {RecordNotFoundError} If no record is found
Expand Down Expand Up @@ -295,8 +295,8 @@ export class ConnectionsApi {
* @param connectionTypes An array of connection types to query for a match for
* @returns a promise of ab array of connection records
*/
public async findAllByConnectionType(connectionTypes: Array<ConnectionType | string>) {
return this.connectionService.findAllByConnectionType(this.agentContext, connectionTypes)
public async findAllByConnectionTypes(connectionTypes: Array<ConnectionType | string>) {
return this.connectionService.findAllByConnectionTypes(this.agentContext, connectionTypes)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,10 +986,9 @@ describe('ConnectionService', () => {

it('removeConnectionType - existing type', async () => {
const connection = getMockConnection()

connection.setTag('connectionType', ['type-1', 'type-2', 'type-3'])
connection.connectionTypes = ['type-1', 'type-2', 'type-3']
let connectionTypes = await connectionService.getConnectionTypes(connection)
expect(connectionTypes).toMatchObject(['type-1', 'type-2', 'type-3'])
expect(connectionTypes.sort()).toMatchObject(['type-1', 'type-2', 'type-3'].sort())

await connectionService.removeConnectionType(agentContext, connection, 'type-2')
connectionTypes = await connectionService.getConnectionTypes(connection)
Expand All @@ -998,8 +997,7 @@ describe('ConnectionService', () => {

it('removeConnectionType - type not existent', async () => {
const connection = getMockConnection()

connection.setTag('connectionType', ['type-1', 'type-2', 'type-3'])
connection.connectionTypes = ['type-1', 'type-2', 'type-3']
let connectionTypes = await connectionService.getConnectionTypes(connection)
expect(connectionTypes).toMatchObject(['type-1', 'type-2', 'type-3'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface ConnectionRecordProps {
protocol?: HandshakeProtocol
outOfBandId?: string
invitationDid?: string
connectionTypes?: Array<ConnectionType | string>
}

export type CustomConnectionTags = TagsBase
Expand All @@ -38,7 +39,7 @@ export type DefaultConnectionTags = {
theirDid?: string
outOfBandId?: string
invitationDid?: string
connectionType?: Array<ConnectionType | string>
connectionTypes?: Array<ConnectionType | string>
amanji marked this conversation as resolved.
Show resolved Hide resolved
}

export class ConnectionRecord
Expand All @@ -64,6 +65,8 @@ export class ConnectionRecord
public outOfBandId?: string
public invitationDid?: string

public connectionTypes: string[] = []

public static readonly type = 'ConnectionRecord'
public readonly type = ConnectionRecord.type

Expand All @@ -88,6 +91,7 @@ export class ConnectionRecord
this.errorMessage = props.errorMessage
this.protocol = props.protocol
this.outOfBandId = props.outOfBandId
this.connectionTypes = props.connectionTypes ?? []
}
}

Expand All @@ -102,6 +106,7 @@ export class ConnectionRecord
theirDid: this.theirDid,
outOfBandId: this.outOfBandId,
invitationDid: this.invitationDid,
connectionTypes: this.connectionTypes,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('ConnectionRecord', () => {
theirDid: 'a-their-did',
outOfBandId: 'a-out-of-band-id',
invitationDid: 'a-invitation-did',
connectionTypes: [],
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ export class ConnectionService {
return this.connectionRepository.findByQuery(agentContext, { outOfBandId })
}

public async findAllByConnectionType(agentContext: AgentContext, connectionTypes: Array<ConnectionType | string>) {
return this.connectionRepository.findByQuery(agentContext, { connectionType: connectionTypes })
public async findAllByConnectionTypes(agentContext: AgentContext, connectionTypes: Array<ConnectionType | string>) {
return this.connectionRepository.findByQuery(agentContext, { connectionTypes })
}

public async findByInvitationDid(agentContext: AgentContext, invitationDid: string) {
Expand Down Expand Up @@ -652,23 +652,18 @@ export class ConnectionService {
}

public async addConnectionType(agentContext: AgentContext, connectionRecord: ConnectionRecord, type: string) {
const tags = connectionRecord.getTags().connectionType || []
connectionRecord.setTag('connectionType', [type, ...tags])
const connectionTypes = connectionRecord.connectionTypes || []
connectionRecord.connectionTypes = [type, ...connectionTypes]
await this.update(agentContext, connectionRecord)
}

public async removeConnectionType(agentContext: AgentContext, connectionRecord: ConnectionRecord, type: string) {
const tags = connectionRecord.getTags().connectionType || []

const newTags = tags.filter((value: string) => value !== type)
connectionRecord.setTag('connectionType', [...newTags])

connectionRecord.connectionTypes = connectionRecord.connectionTypes.filter((value) => value !== type)
await this.update(agentContext, connectionRecord)
}

public async getConnectionTypes(connectionRecord: ConnectionRecord) {
const tags = connectionRecord.getTags().connectionType
return tags || []
return connectionRecord.connectionTypes || []
}

private async createDid(agentContext: AgentContext, { role, didDoc }: { role: DidDocumentRole; didDoc: DidDoc }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ Object {
"7781341d-be29-441b-9b79-4a957d8c6d37": Object {
"id": "7781341d-be29-441b-9b79-4a957d8c6d37",
"tags": Object {
"connectionTypes": Array [],
"did": "did:peer:1zQmSMBVNMDrh7fyE8bkAmk1ZatshjinpsEqPA3nx8JYjuKb",
"invitationDid": "did:peer:2.SeyJzIjoicnhqczphbGljZSIsInQiOiJkaWQtY29tbXVuaWNhdGlvbiIsInByaW9yaXR5IjowLCJyZWNpcGllbnRLZXlzIjpbImRpZDprZXk6ejZNa3QxdHNwMTVjbkREN3dCQ0ZnZWhpUjJTeEhYMWFQeHQ0c3VlRTI0dHdIOUJkI3o2TWt0MXRzcDE1Y25ERDd3QkNGZ2VoaVIyU3hIWDFhUHh0NHN1ZUUyNHR3SDlCZCJdLCJyIjpbXX0",
"invitationKey": "EZdqDkqBSfiepgMZ15jsZvtxTwjiz5diBtjJBnvvMvQF",
Expand All @@ -1231,6 +1232,7 @@ Object {
"type": "ConnectionRecord",
"value": Object {
"autoAcceptConnection": false,
"connectionTypes": Array [],
"createdAt": "2022-04-30T13:02:21.628Z",
"did": "did:peer:1zQmSMBVNMDrh7fyE8bkAmk1ZatshjinpsEqPA3nx8JYjuKb",
"id": "7781341d-be29-441b-9b79-4a957d8c6d37",
Expand All @@ -1247,6 +1249,7 @@ Object {
"8f4908ee-15ad-4058-9106-eda26eae735c": Object {
"id": "8f4908ee-15ad-4058-9106-eda26eae735c",
"tags": Object {
"connectionTypes": Array [],
"did": "did:peer:1zQmRAfQ6J5qk4qcbHyoStFVkhusazLT9xQcFhdC9dhhQ1cJ",
"invitationDid": "did:peer:2.SeyJzIjoicnhqczpmYWJlciIsInQiOiJkaWQtY29tbXVuaWNhdGlvbiIsInByaW9yaXR5IjowLCJyZWNpcGllbnRLZXlzIjpbImRpZDprZXk6ejZNa2ZpUE1QeENRZVNEWkdNa0N2bTFZMnJCb1BzbXc0WkhNdjcxalh0Y1dSUmlNI3o2TWtmaVBNUHhDUWVTRFpHTWtDdm0xWTJyQm9Qc213NFpITXY3MWpYdGNXUlJpTSJdLCJyIjpbXX0",
"invitationKey": "2G8JohwyJtj69ruWFC3hBkdoaJW5eg31E66ohceVWCvy",
Expand All @@ -1262,6 +1265,7 @@ Object {
"type": "ConnectionRecord",
"value": Object {
"alias": "connection alias",
"connectionTypes": Array [],
"createdAt": "2022-04-30T13:02:21.577Z",
"did": "did:peer:1zQmRAfQ6J5qk4qcbHyoStFVkhusazLT9xQcFhdC9dhhQ1cJ",
"id": "8f4908ee-15ad-4058-9106-eda26eae735c",
Expand All @@ -1278,6 +1282,7 @@ Object {
"9383d8e5-c002-4aae-8300-4a21384c919e": Object {
"id": "9383d8e5-c002-4aae-8300-4a21384c919e",
"tags": Object {
"connectionTypes": Array [],
"did": "did:peer:1zQmP96nW6vbNjzwPt19z1NYqhnAfgnAFqfLHcktkmdUFzhT",
"invitationDid": "did:peer:2.SeyJzIjoicnhqczphbGljZSIsInQiOiJkaWQtY29tbXVuaWNhdGlvbiIsInByaW9yaXR5IjowLCJyZWNpcGllbnRLZXlzIjpbImRpZDprZXk6ejZNa3RDWkFRTkd2V2I0V0hBandCcVB0WGhaZERZb3JiU0prR1c5dmoxdWh3MUhEI3o2TWt0Q1pBUU5HdldiNFdIQWp3QnFQdFhoWmREWW9yYlNKa0dXOXZqMXVodzFIRCJdLCJyIjpbXX0",
"invitationKey": "EkJ7p82VB3a3AfuEWGS3gc1dPyY1BZ4PaVEztjwh1nVq",
Expand All @@ -1292,6 +1297,7 @@ Object {
},
"type": "ConnectionRecord",
"value": Object {
"connectionTypes": Array [],
"createdAt": "2022-04-30T13:02:21.608Z",
"did": "did:peer:1zQmP96nW6vbNjzwPt19z1NYqhnAfgnAFqfLHcktkmdUFzhT",
"id": "9383d8e5-c002-4aae-8300-4a21384c919e",
Expand Down Expand Up @@ -1319,6 +1325,7 @@ Object {
"b65c2ccd-277c-4140-9d87-c8dd30e7a98c": Object {
"id": "b65c2ccd-277c-4140-9d87-c8dd30e7a98c",
"tags": Object {
"connectionTypes": Array [],
"did": "did:peer:1zQmfDAtfDZcK4trJBsvVTXrBx9uaLCHSUZH9X2LFaAd3JKv",
"invitationDid": "did:peer:2.SeyJzIjoicnhqczphbGljZSIsInQiOiJkaWQtY29tbXVuaWNhdGlvbiIsInByaW9yaXR5IjowLCJyZWNpcGllbnRLZXlzIjpbImRpZDprZXk6ejZNa3VXVEVtSDFtVW82Vzk2elNXeUg2MTJoRkhvd1J6TkVzY1BZQkwyQ0NNeUMyI3o2TWt1V1RFbUgxbVVvNlc5NnpTV3lINjEyaEZIb3dSek5Fc2NQWUJMMkNDTXlDMiJdLCJyIjpbXX0",
"invitationKey": "G4CCB2mL9Fc32c9jqQKF9w9FUEfaaUzWvNdFVkEBSkQe",
Expand All @@ -1333,6 +1340,7 @@ Object {
"type": "ConnectionRecord",
"value": Object {
"autoAcceptConnection": true,
"connectionTypes": Array [],
"createdAt": "2022-04-30T13:02:21.653Z",
"did": "did:peer:1zQmfDAtfDZcK4trJBsvVTXrBx9uaLCHSUZH9X2LFaAd3JKv",
"id": "b65c2ccd-277c-4140-9d87-c8dd30e7a98c",
Expand All @@ -1346,6 +1354,7 @@ Object {
"da518433-0e55-4b74-a05b-aa75c1095a99": Object {
"id": "da518433-0e55-4b74-a05b-aa75c1095a99",
"tags": Object {
"connectionTypes": Array [],
"did": "did:peer:1zQmPbGa8KDwyjcw9UgwCCgJMV7jU5kKCyvBuwFVc88WxA56",
"invitationDid": "did:peer:2.SeyJzIjoicnhqczphbGljZSIsInQiOiJkaWQtY29tbXVuaWNhdGlvbiIsInByaW9yaXR5IjowLCJyZWNpcGllbnRLZXlzIjpbImRpZDprZXk6ejZNa28zMURORTNncU1SWmoxSk5odjJCSGIxY2FRc2hjZDluamdLa0VRWHNnRlJwI3o2TWtvMzFETkUzZ3FNUlpqMUpOaHYyQkhiMWNhUXNoY2Q5bmpnS2tFUVhzZ0ZScCJdLCJyIjpbXX0",
"invitationKey": "9akAmyoFVow6cWTg2M4LSVTckqbrCjuS3fQpQ8Zrm2eS",
Expand All @@ -1361,6 +1370,7 @@ Object {
"type": "ConnectionRecord",
"value": Object {
"autoAcceptConnection": true,
"connectionTypes": Array [],
"createdAt": "2022-04-30T13:02:21.646Z",
"did": "did:peer:1zQmPbGa8KDwyjcw9UgwCCgJMV7jU5kKCyvBuwFVc88WxA56",
"id": "da518433-0e55-4b74-a05b-aa75c1095a99",
Expand Down Expand Up @@ -2326,6 +2336,7 @@ Object {
"e3f9bc2b-f0a1-4a2c-ab81-2f0a3488c199": Object {
"id": "e3f9bc2b-f0a1-4a2c-ab81-2f0a3488c199",
"tags": Object {
"connectionTypes": Array [],
"did": "did:peer:1zQma8LpnJ22GxQdyASV5jP6psacAGtJ6ytk4pVayYp4erRf",
"invitationDid": "did:peer:2.SeyJzIjoicnhqczpmYWJlciIsInQiOiJkaWQtY29tbXVuaWNhdGlvbiIsInByaW9yaXR5IjowLCJyZWNpcGllbnRLZXlzIjpbImRpZDprZXk6ejZNa2pESkw0WDdZR29INmdqYW1oWlIyTnpvd1BacXRKZlg1a1B1TnVXaVZkak1yI3o2TWtqREpMNFg3WUdvSDZnamFtaFpSMk56b3dQWnF0SmZYNWtQdU51V2lWZGpNciJdLCJyIjpbXX0",
"invitationKey": "5m3HUGs6wFndaEk51zTBXuFwZza2tnGj4NzT5EkUiWaU",
Expand All @@ -2341,6 +2352,7 @@ Object {
"type": "ConnectionRecord",
"value": Object {
"autoAcceptConnection": false,
"connectionTypes": Array [],
"createdAt": "2022-04-30T13:02:21.641Z",
"did": "did:peer:1zQma8LpnJ22GxQdyASV5jP6psacAGtJ6ytk4pVayYp4erRf",
"id": "e3f9bc2b-f0a1-4a2c-ab81-2f0a3488c199",
Expand All @@ -2357,6 +2369,7 @@ Object {
"ee88e2e1-e27e-46a6-a910-f87690109e32": Object {
"id": "ee88e2e1-e27e-46a6-a910-f87690109e32",
"tags": Object {
"connectionTypes": Array [],
"did": "did:peer:1zQmduuYkxRKJuVyvDqttdd9eDfBwDnF1DAU5FFQo4whx7Uw",
"invitationDid": "did:peer:2.SeyJzIjoicnhqczpmYWJlciIsInQiOiJkaWQtY29tbXVuaWNhdGlvbiIsInByaW9yaXR5IjowLCJyZWNpcGllbnRLZXlzIjpbImRpZDprZXk6ejZNa21vZDh2cDJuVVJWa3RWQzVjZVFleXIyVlV6MjZpdTJaQU5MTlZnOXBNYXdhI3o2TWttb2Q4dnAyblVSVmt0VkM1Y2VRZXlyMlZVejI2aXUyWkFOTE5WZzlwTWF3YSJdLCJyIjpbXX0",
"invitationKey": "8MN6LZnM8t1HmzMNw5Sp8kUVfQkFK1nCUMRSfQBoSNAC",
Expand All @@ -2370,6 +2383,7 @@ Object {
},
"type": "ConnectionRecord",
"value": Object {
"connectionTypes": Array [],
"createdAt": "2022-04-30T13:02:21.635Z",
"did": "did:peer:1zQmduuYkxRKJuVyvDqttdd9eDfBwDnF1DAU5FFQo4whx7Uw",
"id": "ee88e2e1-e27e-46a6-a910-f87690109e32",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ describe('0.1-0.2 | Connection', () => {
'did:peer:2.SeyJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbSIsInQiOiJkaWQtY29tbXVuaWNhdGlvbiIsInByaW9yaXR5IjowLCJyZWNpcGllbnRLZXlzIjpbImRpZDprZXk6ejZNa3NZVTRNSHRmbU5oTm0xdUdNdkFOcjlqNENCdjJGeW1qaUp0UmdBMzZiU1ZII3o2TWtzWVU0TUh0Zm1OaE5tMXVHTXZBTnI5ajRDQnYyRnltamlKdFJnQTM2YlNWSCJdfQ',
theirDid: didPeer4kgVt6CidfKgo1MoWMqsQX.id,
outOfBandId: expect.any(String),
connectionTypes: [],
})
})
})
Expand Down Expand Up @@ -171,6 +172,7 @@ describe('0.1-0.2 | Connection', () => {
serviceEndpoint: 'https://example.com',
label: 'test',
},
connectionTypes: [],
})
})
})
Expand Down Expand Up @@ -199,6 +201,7 @@ describe('0.1-0.2 | Connection', () => {
serviceEndpoint: 'https://example.com',
label: 'test',
},
connectionTypes: [],
})
})

Expand Down Expand Up @@ -271,6 +274,7 @@ describe('0.1-0.2 | Connection', () => {
theirDidDoc: undefined,
metadata: {},
_tags: {},
connectionTypes: [],
})
})

Expand Down Expand Up @@ -341,6 +345,7 @@ describe('0.1-0.2 | Connection', () => {
serviceEndpoint: 'https://example.com',
label: 'test',
},
connectionTypes: [],
})
})
})
Expand All @@ -367,6 +372,7 @@ describe('0.1-0.2 | Connection', () => {
outOfBandId: expect.any(String),
autoAcceptConnection: true,
mediatorId: 'a-mediator-id',
connectionTypes: [],
})
})

Expand Down Expand Up @@ -492,6 +498,7 @@ describe('0.1-0.2 | Connection', () => {
autoAcceptConnection: true,
mediatorId: 'a-mediator-id',
outOfBandId: outOfBandRecord.id,
connectionTypes: [],
})
})

Expand Down
Loading