Skip to content

Commit

Permalink
fix: rename versionObj.coreKey to coreDiscoveryKey (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan authored Sep 21, 2023
1 parent 3090743 commit 73c6d15
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion proto/common/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ message Common_1 {
// 32-byte random generated number
optional bytes docId = 1 [(required) = true];
message Link {
bytes coreKey = 1;
bytes coreDiscoveryKey = 1;
int32 index = 2;
}
repeated Link links = 2;
Expand Down
2 changes: 1 addition & 1 deletion schema/common/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "string"
},
"versionId": {
"description": "core id (hex-encoded 32-byte buffer) and core index number, separated by '/'",
"description": "core discovery id (hex-encoded 32-byte buffer) and core index number, separated by '/'",
"type": "string"
},
"schemaName": {
Expand Down
12 changes: 6 additions & 6 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function capitalize<T extends string>(str: T): Capitalize<T> {
}

export type VersionIdObject = {
coreKey: Buffer
coreDiscoveryKey: Buffer
index: number
}

Expand All @@ -27,8 +27,8 @@ export type VersionIdObject = {
* @param versionIdObject
* @returns versionId string
*/
export function getVersionId({ coreKey, index }: VersionIdObject) {
return coreKey.toString('hex') + '/' + index
export function getVersionId({ coreDiscoveryKey, index }: VersionIdObject) {
return coreDiscoveryKey.toString('hex') + '/' + index
}

/**
Expand All @@ -41,9 +41,9 @@ export function getVersionId({ coreKey, index }: VersionIdObject) {
export function parseVersionId(versionId: string): VersionIdObject {
const items = versionId.split('/')
if (!items[0] || !items[1]) throw new Error('Invalid versionId')
const coreKey = Buffer.from(items[0], 'hex')
if (coreKey.length !== 32) throw new Error('Invalid versionId')
const coreDiscoveryKey = Buffer.from(items[0], 'hex')
if (coreDiscoveryKey.length !== 32) throw new Error('Invalid versionId')
const index = Number.parseInt(items[1])
if (isNaN(index)) throw new Error('Invalid versionId')
return { coreKey, index }
return { coreDiscoveryKey, index }
}

0 comments on commit 73c6d15

Please sign in to comment.