Skip to content

Commit

Permalink
add presetRef to observation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomás Ciccola committed Aug 5, 2024
1 parent 1662480 commit f81da9a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
9 changes: 9 additions & 0 deletions proto/observation/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "google/protobuf/struct.proto";
import "tags/v1.proto";
import "common/v1.proto";
import "options.proto";
import "versionId/v1.proto";

message Observation_1 {
// **DO NOT CHANGE dataTypeId** generated with `openssl rand -hex 6`
Expand Down Expand Up @@ -66,4 +67,12 @@ message Observation_1 {
optional PositionProvider positionProvider = 5;
}
optional Metadata metadata = 9;

PresetRef presetRef = 10;

message PresetRef {
bytes docId = 1;
VersionId_1 versionId = 2;
}

}
17 changes: 16 additions & 1 deletion schema/observation/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,23 @@
}
},
"additionalProperties": false
},
"presetRef": {
"type": "object",
"description": "References to the preset that this observation is related to.",
"properties": {
"docId": {
"description": "hex-encoded id of the element that this observation references",
"type": "string"
},
"versionId": {
"description": "core discovery id (hex-encoded 32-byte buffer) and core index number, separated by '/'",
"type": "string"
}
},
"required": ["docId", "versionId"]
}
},
"required": ["schemaName", "tags", "attachments", "metadata"],
"required": ["schemaName", "tags", "attachments", "metadata", "presetRef"],
"additionalProperties": false
}
13 changes: 13 additions & 0 deletions src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,26 @@ export const convertObservation: ConvertFunction<'observation'> = (
) => {
const { common, schemaVersion, ...rest } = message
const jsonSchemaCommon = convertCommon(common, versionObj)
let presetRef

if (!rest.presetRef) {
throw new Error('missing presetRef on observation')
}
if (!rest.presetRef.versionId) {
throw new Error('found presetRef on observation but is missing versionId')
}
presetRef = {
docId: rest.presetRef.docId.toString('hex'),
versionId: getVersionId(rest.presetRef.versionId),
}

const obs: Observation = {
...jsonSchemaCommon,
...rest,
attachments: message.attachments.map(convertAttachment),
tags: convertTags(message.tags),
metadata: message.metadata || {},
presetRef,
}
return obs
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/encode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export const convertObservation: ConvertFunction<'observation'> = (
attachments,
tags: convertTags(mapeoDoc.tags),
metadata,
presetRef: {
docId: Buffer.from(mapeoDoc.presetRef?.docId, 'hex'),
versionId: parseVersionId(mapeoDoc.presetRef?.versionId),
},
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/good-docs-completed.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export const goodDocsCompleted = [
networkAvailable: false,
},
},
presetRef: {
docId: cachedValues.refs.docId,
versionId: cachedValues.refs.versionId,
},
deleted: false,
},
expected: {},
Expand Down Expand Up @@ -149,6 +153,10 @@ export const goodDocsCompleted = [
versionId: cachedValues.refs.versionId,
},
],
iconRef: {
docId: cachedValues.refs.docId,
versionId: cachedValues.refs.versionId,
},
color: '#ff00ff',
terms: ['imastring'],
deleted: false,
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/good-docs-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const goodDocsMinimal = [
attachments: [],
tags: {},
metadata: {},
presetRef: {
docId: cachedValues.refs.docId,
versionId: cachedValues.refs.versionId,
},
deleted: false,
},
expected: {},
Expand Down

0 comments on commit f81da9a

Please sign in to comment.