From 83e55c8eb29af78e5fa5e860668099742a606ec9 Mon Sep 17 00:00:00 2001 From: Gregor MacLennan Date: Fri, 18 Aug 2023 16:09:01 +0100 Subject: [PATCH] feat: Add updated `Role` data type Fixes #124 For details see https://github.com/digidem/mapeo-core-next/issues/189 --- proto/role/v1.proto | 14 ++------------ schema/role/v1.json | 29 ++++++----------------------- src/lib/decode-conversions.ts | 7 ++++--- src/lib/encode-converstions.ts | 3 +-- 4 files changed, 13 insertions(+), 40 deletions(-) diff --git a/proto/role/v1.proto b/proto/role/v1.proto index ab52936e..4f21a6e0 100644 --- a/proto/role/v1.proto +++ b/proto/role/v1.proto @@ -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; } diff --git a/schema/role/v1.json b/schema/role/v1.json index 278863a8..7716b2be 100644 --- a/schema/role/v1.json +++ b/schema/role/v1.json @@ -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 } diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index 62346c10..35bdde58 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -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'), } } diff --git a/src/lib/encode-converstions.ts b/src/lib/encode-converstions.ts index ff88cf3f..a4a24877 100644 --- a/src/lib/encode-converstions.ts +++ b/src/lib/encode-converstions.ts @@ -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'), } }