Skip to content

Commit

Permalink
feat: add getMany method to member api
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 committed Sep 12, 2023
1 parent dbcb134 commit ab83390
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/mapeo-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ export class MapeoProject {
getDeviceInfo: async (deviceId) => {
return this.#dataTypes.deviceInfo.getByDocId(deviceId)
},
getManyDeviceInfo: async () => {
return this.#dataTypes.deviceInfo.getMany()
},
},
})

Expand Down
9 changes: 9 additions & 0 deletions src/member-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class MemberApi extends TypedEmitter {
* @param {Object} opts.queries
* @param {() => Promise<import('./generated/rpc.js').Invite_ProjectInfo>} opts.queries.getProjectInfo
* @param {(deviceId: string) => Promise<import('@mapeo/schema').DeviceInfo>} opts.queries.getDeviceInfo
* @param {() => Promise<Array<import('@mapeo/schema').DeviceInfo>>} opts.queries.getManyDeviceInfo
*
*/
constructor({ capabilities, encryptionKeys, projectKey, rpc, queries }) {
Expand Down Expand Up @@ -64,4 +65,12 @@ export class MemberApi extends TypedEmitter {
const deviceInfo = await this.#queries.getDeviceInfo(deviceId)
return { deviceId, name: deviceInfo.name }
}

/**
* @returns {Promise<Array<MemberInfo>>}
*/
async getMany() {
const devices = await this.#queries.getManyDeviceInfo()
return devices.map(({ docId, name }) => ({ deviceId: docId, name }))
}
}

0 comments on commit ab83390

Please sign in to comment.