From 46353a976b6d570502a8915be413da46a6209dd7 Mon Sep 17 00:00:00 2001 From: tomasciccola <117094913+tomasciccola@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:39:04 -0300 Subject: [PATCH] chore: move type out of `docRef` and call it `docRefType` (#208) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * move type out of `docRef` and call it `refType` * rename `refType` to `docRefType`, make it an enum valid types are every schema except `coreOwnership`, `icon` and `translation` --------- Co-authored-by: Tomás Ciccola --- proto/translation/v1.proto | 12 +++++++++++- schema/translation/v1.json | 22 +++++++++++++++++----- src/lib/decode-conversions.ts | 1 - src/lib/encode-conversions.ts | 1 - test/fixtures/good-docs-completed.js | 2 +- test/fixtures/good-docs-minimal.js | 2 +- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/proto/translation/v1.proto b/proto/translation/v1.proto index be2108c..24a2c69 100644 --- a/proto/translation/v1.proto +++ b/proto/translation/v1.proto @@ -21,7 +21,17 @@ message Translation_1 { message DocRef { bytes docId = 1; VersionId_1 versionId = 2; - string type = 3; } + enum DocRefType { + type_unspecified = 0; + deviceInfo = 1; + preset = 2; + field = 3; + observation = 4; + projectSettings = 5; + role = 6; + track = 7; + } + DocRefType docRefType = 7; } diff --git a/schema/translation/v1.json b/schema/translation/v1.json index df83d13..b25d456 100644 --- a/schema/translation/v1.json +++ b/schema/translation/v1.json @@ -19,13 +19,24 @@ "versionId": { "description": "core discovery id (hex-encoded 32-byte buffer) and core index number, separated by '/'", "type": "string" - }, - "type": { - "description": "type of the element that this translation references", - "type": "string" } }, - "required": ["docId", "versionId", "type"] + "required": ["docId", "versionId"] + }, + "docRefType": { + "description": "type of the element that this translation references", + "type": "string", + "enum": [ + "type_unspecified", + "deviceInfo", + "preset", + "field", + "observation", + "projectSettings", + "role", + "track", + "UNRECOGNIZED" + ] }, "propertyRef": { "type": "string", @@ -47,6 +58,7 @@ "required": [ "schemaName", "docRef", + "docRefType", "propertyRef", "languageCode", "regionCode", diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index eed2685..33a8f50 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -245,7 +245,6 @@ export const convertTranslation: ConvertFunction<'translation'> = ( docRef: { docId: message.docRef.docId.toString('hex'), versionId: getVersionId(message.docRef.versionId), - type: message.docRef.type, }, } } diff --git a/src/lib/encode-conversions.ts b/src/lib/encode-conversions.ts index ebf39c7..e874fcc 100644 --- a/src/lib/encode-conversions.ts +++ b/src/lib/encode-conversions.ts @@ -207,7 +207,6 @@ export const convertTranslation: ConvertFunction<'translation'> = ( docRef: { docId: Buffer.from(mapeoDoc.docRef.docId, 'hex'), versionId: parseVersionId(mapeoDoc.docRef.versionId), - type: mapeoDoc.docRef.type, }, } } diff --git a/test/fixtures/good-docs-completed.js b/test/fixtures/good-docs-completed.js index 73324eb..9b59187 100644 --- a/test/fixtures/good-docs-completed.js +++ b/test/fixtures/good-docs-completed.js @@ -269,8 +269,8 @@ export const goodDocsCompleted = [ docRef: { docId: cachedValues.refs.docId, versionId: cachedValues.refs.versionId, - type: 'preset', }, + docRefType: 'preset', propertyRef: 'terms[0]', languageCode: 'es', regionCode: 'AR', diff --git a/test/fixtures/good-docs-minimal.js b/test/fixtures/good-docs-minimal.js index c5708bf..24b50f6 100644 --- a/test/fixtures/good-docs-minimal.js +++ b/test/fixtures/good-docs-minimal.js @@ -174,8 +174,8 @@ export const goodDocsMinimal = [ docRef: { docId: cachedValues.refs.docId, versionId: cachedValues.refs.versionId, - type: 'field', }, + docRefType: 'field', propertyRef: 'label', languageCode: 'qu', regionCode: 'PE',