Skip to content

Commit

Permalink
chore: move type out of docRef and call it docRefType (#208)
Browse files Browse the repository at this point in the history
* 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 <tciccola@digital-democracy.com>
  • Loading branch information
tomasciccola and Tomás Ciccola authored Aug 5, 2024
1 parent 1662480 commit 46353a9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
12 changes: 11 additions & 1 deletion proto/translation/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
22 changes: 17 additions & 5 deletions schema/translation/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -47,6 +58,7 @@
"required": [
"schemaName",
"docRef",
"docRefType",
"propertyRef",
"languageCode",
"regionCode",
Expand Down
1 change: 0 additions & 1 deletion src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand Down
1 change: 0 additions & 1 deletion src/lib/encode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/good-docs-completed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/good-docs-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 46353a9

Please sign in to comment.