From ce528d5fc6178a80f770cdff4f70e9b38be8f274 Mon Sep 17 00:00:00 2001 From: Gregor MacLennan Date: Mon, 19 Feb 2024 13:01:42 +0000 Subject: [PATCH] chore!: rename role -> membership BREAKING: Fixes Suggestion: rename `role` to `membership` #163 --- proto/{role => membership}/v1.proto | 4 ++-- schema/{role => membership}/v1.json | 8 ++++---- src/decode.ts | 6 +++--- src/encode.ts | 6 +++--- src/lib/decode-conversions.ts | 5 ++++- src/lib/encode-conversions.ts | 2 +- src/types.ts | 2 +- test/fixtures/bad-docs.js | 6 +++--- test/fixtures/good-docs-completed.js | 2 +- test/fixtures/good-docs-minimal.js | 2 +- 10 files changed, 23 insertions(+), 20 deletions(-) rename proto/{role => membership}/v1.proto (85%) rename schema/{role => membership}/v1.json (63%) diff --git a/proto/role/v1.proto b/proto/membership/v1.proto similarity index 85% rename from proto/role/v1.proto rename to proto/membership/v1.proto index fe39ded..18fc758 100644 --- a/proto/role/v1.proto +++ b/proto/membership/v1.proto @@ -6,10 +6,10 @@ import "google/protobuf/timestamp.proto"; import "common/v1.proto"; import "options.proto"; -message Role_1 { +message Membership_1 { // **DO NOT CHANGE dataTypeId** generated with `openssl rand -hex 6` option (dataTypeId) = "69acce0ea09b"; - option (schemaName) = "role"; + option (schemaName) = "membership"; Common_1 common = 1; diff --git a/schema/role/v1.json b/schema/membership/v1.json similarity index 63% rename from schema/role/v1.json rename to schema/membership/v1.json index ab9e4a8..b23f6ce 100644 --- a/schema/role/v1.json +++ b/schema/membership/v1.json @@ -1,12 +1,12 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "http://mapeo.world/schemas/role/v1.json", - "title": "Role", + "$id": "http://mapeo.world/schemas/membership/v1.json", + "title": "Membership", "type": "object", "properties": { "schemaName": { "type": "string", - "const": "role" + "const": "membership" }, "roleId": { "type": "string", @@ -15,7 +15,7 @@ "fromIndex": { "type": "integer", "minimum": 0, - "description": "This is the index of the auth core that this role applies to (identified by the `docId`) to apply this role from. E.g. documents in the auth core assigned this role from this index will be evaluated according to this role." + "description": "This is the index of the auth core that this membership applies to (identified by the `docId`) to apply the role from. E.g. documents in the auth core assigned this membership from this index will be evaluated according to the assigned roleId." } }, "required": ["schemaName", "roleId", "fromIndex"], diff --git a/src/decode.ts b/src/decode.ts index 75bd9ad..c8a41f3 100644 --- a/src/decode.ts +++ b/src/decode.ts @@ -14,7 +14,7 @@ import { convertField, convertObservation, convertPreset, - convertRole, + convertMembership, convertDeviceInfo, convertCoreOwnership, convertIcon, @@ -64,8 +64,8 @@ export function decode( return convertField(message, versionObj) case 'preset': return convertPreset(message, versionObj) - case 'role': - return convertRole(message, versionObj) + case 'membership': + return convertMembership(message, versionObj) case 'deviceInfo': return convertDeviceInfo(message, versionObj) case 'coreOwnership': diff --git a/src/encode.ts b/src/encode.ts index 583aabd..3866c8e 100644 --- a/src/encode.ts +++ b/src/encode.ts @@ -14,7 +14,7 @@ import { convertObservation, convertPreset, convertProjectSettings, - convertRole, + convertMembership, convertDeviceInfo, convertCoreOwnership, convertIcon, @@ -59,8 +59,8 @@ export function encode( protobuf = Encode[mapeoDoc.schemaName](message).finish() break } - case 'role': { - const message = convertRole(mapeoDoc) + case 'membership': { + const message = convertMembership(mapeoDoc) protobuf = Encode[mapeoDoc.schemaName](message).finish() break } diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index 55e6398..38a2246 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -139,7 +139,10 @@ export const convertPreset: ConvertFunction<'preset'> = ( } } -export const convertRole: ConvertFunction<'role'> = (message, versionObj) => { +export const convertMembership: ConvertFunction<'membership'> = ( + message, + versionObj +) => { if (message.roleId.length === 0) { throw new Error('Invalid roleId') } diff --git a/src/lib/encode-conversions.ts b/src/lib/encode-conversions.ts index 6d4de83..8dfb27c 100644 --- a/src/lib/encode-conversions.ts +++ b/src/lib/encode-conversions.ts @@ -101,7 +101,7 @@ export const convertObservation: ConvertFunction<'observation'> = ( } } -export const convertRole: ConvertFunction<'role'> = (mapeoDoc) => { +export const convertMembership: ConvertFunction<'membership'> = (mapeoDoc) => { const roleId = Buffer.from(mapeoDoc.roleId, 'hex') if (roleId.length === 0) { throw new Error('Invalid roleId') diff --git a/src/types.ts b/src/types.ts index cdac98c..c1619ca 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,7 +14,7 @@ type SupportedSchemaNames = | 'observation' | 'field' | 'preset' - | 'role' + | 'membership' | 'icon' | 'deviceInfo' | 'coreOwnership' diff --git a/test/fixtures/bad-docs.js b/test/fixtures/bad-docs.js index a3bb41f..c478f27 100644 --- a/test/fixtures/bad-docs.js +++ b/test/fixtures/bad-docs.js @@ -26,12 +26,12 @@ export const badDocs = [ }, }, { - text: 'role doc with empty roleId', - /** @type {import('../../dist/index.js').Role} */ + text: 'membership doc with empty roleId', + /** @type {import('../../dist/index.js').Membership} */ doc: { docId: cachedValues.docId, versionId: cachedValues.versionId, - schemaName: 'role', + schemaName: 'membership', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, createdBy: cachedValues.createdBy, diff --git a/test/fixtures/good-docs-completed.js b/test/fixtures/good-docs-completed.js index 7497a6d..2f6ba19 100644 --- a/test/fixtures/good-docs-completed.js +++ b/test/fixtures/good-docs-completed.js @@ -149,7 +149,7 @@ export const goodDocsCompleted = [ doc: { docId: cachedValues.docId, versionId: cachedValues.versionId, - schemaName: 'role', + schemaName: 'membership', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, createdBy: cachedValues.createdBy, diff --git a/test/fixtures/good-docs-minimal.js b/test/fixtures/good-docs-minimal.js index b4c1bb3..57c8e39 100644 --- a/test/fixtures/good-docs-minimal.js +++ b/test/fixtures/good-docs-minimal.js @@ -82,7 +82,7 @@ export const goodDocsMinimal = [ doc: { docId: cachedValues.docId, versionId: cachedValues.versionId, - schemaName: 'role', + schemaName: 'membership', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, createdBy: cachedValues.createdBy,