Skip to content

Commit

Permalink
feat: Add updated Role data type
Browse files Browse the repository at this point in the history
Fixes #124
For details see digidem/comapeo-core#189
  • Loading branch information
gmaclennan committed Aug 18, 2023
1 parent 9a13d68 commit 83e55c8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 40 deletions.
14 changes: 2 additions & 12 deletions proto/role/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ message Role_1 {

Common_1 common = 1;

string role = 5;
bytes projectId = 6;
enum Action {
role_set = 0;
role_unset = 1;
};
Action action = 7;
string signature = 8;
int32 authorIndex = 9;
int32 deviceIndex = 10;
bytes authorId = 11;
string capabilityType = 12;
bytes roleId = 5;
int32 fromIndex = 6;
}
29 changes: 6 additions & 23 deletions schema/role/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,15 @@
"type": "string",
"const": "role"
},
"role": {
"type": "string"
},
"projectId": {
"type": "string"
},
"action": {
"roleId": {
"type": "string",
"enum": ["role_set", "role_unset", "UNRECOGNIZED"]
},
"signature": {
"type": "string"
},
"authorIndex": {
"type": "integer"
},
"deviceIndex": {
"type": "integer"
},
"authorId": {
"type": "string"
"description": "Unique identifier for role assigned to device with auth core ID equal to `docId` of this record"
},
"capabilityType": {
"type": "string"
"fromIndex": {
"type": "number",
"description": "From what index of the core that this role applies to (identified by the `docId`) does this roleId apply?"
}
},
"required": ["schemaName", "role", "projectId", "action", "signature", "authorIndex", "deviceIndex", "authorId", "capabilityType"],
"required": ["schemaName", "roleId", "fromIndex"],
"additionalProperties": false
}
7 changes: 4 additions & 3 deletions src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ export const convertPreset: ConvertFunction<'preset'> = (
}

export const convertRole: ConvertFunction<'role'> = (message, versionObj) => {
if (message.roleId.length === 0) {
throw new Error('Invalid roleId')
}
const { common, schemaVersion, ...rest } = message
const jsonSchemaCommon = convertCommon(common, versionObj)
return {
...jsonSchemaCommon,
...rest,
role: rest.role,
projectId: message.projectId.toString('hex'),
authorId: message.authorId.toString('hex'),
roleId: message.roleId.toString('hex'),
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/lib/encode-converstions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ export const convertRole: ConvertFunction<'role'> = (mapeoDoc) => {
return {
common: convertCommon(mapeoDoc),
...mapeoDoc,
projectId: Buffer.from(mapeoDoc.projectId, 'hex'),
authorId: Buffer.from(mapeoDoc.authorId, 'hex'),
roleId: Buffer.from(mapeoDoc.roleId, 'hex'),
}
}

Expand Down

0 comments on commit 83e55c8

Please sign in to comment.