Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add migration metadata to observation schema #280

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions proto/observation/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,16 @@ message Observation_1 {
bytes docId = 1;
VersionId_1 versionId = 2;
}

message MigrationMetadata {
bytes originalDocument = 1;
message HypercoreMetadata {
optional string rootHashChecksum = 1;
optional string signature = 2;
optional string coreKey = 3;
optional uint32 blockIndex = 4;
}
optional HypercoreMetadata hypercore = 2;
}
optional MigrationMetadata migrationMetadata = 11;
}
34 changes: 34 additions & 0 deletions schema/observation/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,40 @@
}
},
"required": ["docId", "versionId"]
},
"migrationMetadata": {
"description": "Metadata about the migration of this observation from Mapeo Legacy",
"type": "object",
"properties": {
"originalDocument": {
"description": "Hex-encoded raw observation from Mapeo Legacy",
"type": "string"
},
"hypercore": {
"type": "object",
"properties": {
"rootHashChecksum": {
"description": "Checksum of the root hash of the old Hypercore",
"type": "string",
"minLength": 1
},
"signature": {
"description": "Signature of the old Hypercore",
"type": "string",
"minLength": 1
},
"coreKey": {
"description": "Core key of the old Hypercore",
"type": "string",
"minLength": 1
},
"blockIndex": {
"description": "Block index of the document",
"type": "number"
}
}
}
}
}
},
"required": ["schemaName", "tags", "attachments"],
Expand Down
9 changes: 9 additions & 0 deletions src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const convertObservation: ConvertFunction<'observation'> = (
const {
common,
metadata,
migrationMetadata,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
schemaVersion,
...rest
Expand Down Expand Up @@ -139,6 +140,14 @@ export const convertObservation: ConvertFunction<'observation'> = (
tags: convertTags(message.tags),
metadata: metadata ? removeInvalidPositionMetadata(metadata) : {},
presetRef,
migrationMetadata: migrationMetadata
? {
...migrationMetadata,
originalDocument: migrationMetadata.originalDocument
? JSON.stringify(migrationMetadata.originalDocument)
: undefined,
}
: undefined,
}
return obs
}
Expand Down
12 changes: 12 additions & 0 deletions src/lib/encode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,24 @@ export const convertObservation: ConvertFunction<'observation'> = (
}
}

let migrationMetadata
if (mapeoDoc.migrationMetadata) {
migrationMetadata = {
...mapeoDoc.migrationMetadata,
originalDocument: Buffer.from(
mapeoDoc.migrationMetadata.originalDocument || '',
'hex'
),
}
}

return {
common: convertCommon(mapeoDoc),
...mapeoDoc,
attachments,
tags: convertTags(mapeoDoc.tags),
presetRef,
migrationMetadata,
}
}

Expand Down
Loading