Skip to content

Commit

Permalink
feat: add createdBy field for all records
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 committed Sep 12, 2023
1 parent 0a0a988 commit ed25c83
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions proto/common/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ message Common_1 {
repeated Link links = 2;
google.protobuf.Timestamp createdAt = 3 [(required) = true];
google.protobuf.Timestamp updatedAt = 4 [(required) = true];
// 32-byte hash of the discovery key of a core
bytes createdBy = 5 [(required) = true];
}
/* ignored fields and differences from common.json jsonSchema
* id is a byte buffer here and a string in jsonSchema
Expand Down
7 changes: 6 additions & 1 deletion schema/common/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"type": "string",
"format": "date-time"
},
"createdBy": {
"description": "id (hex-encoded 32-byte buffer) of the discovery key for the core that created the first version of this element",
"type": "string"
},
"updatedAt": {
"description": "RFC3339-formatted datetime of when this version of the element was created",
"type": "string",
Expand All @@ -42,6 +46,7 @@
"schemaName",
"updatedAt",
"links",
"versionId"
"versionId",
"createdBy"
]
}
1 change: 1 addition & 0 deletions src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,6 @@ function convertCommon(
links: common.links.map((link) => getVersionId(link)),
createdAt: common.createdAt,
updatedAt: common.updatedAt,
createdBy: common.createdBy.toString('hex'),
}
}
1 change: 1 addition & 0 deletions src/lib/encode-converstions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function convertCommon(
docId: Buffer.from(common.docId, 'hex'),
createdAt: common.createdAt,
updatedAt: common.updatedAt,
createdBy: Buffer.from(common.createdBy, 'hex'),
links: common.links.map((link) => parseVersionId(link)),
}
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/cached.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const cachedValues = {
projectId: randomBytes(32).toString('hex'),
authorId: randomBytes(32).toString('hex'),
coreId: randomBytes(32).toString('hex'),
createdBy: randomBytes(32).toString('hex'),
createdAt: date,
updatedAt: date,
attachments: { driveId: randomBytes(32).toString('hex') },
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/good-docs-completed.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const goodDocsCompleted = [
schemaName: 'observation',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
lat: 24.0424,
lon: 21.0214,
Expand Down Expand Up @@ -74,6 +75,7 @@ export const goodDocsCompleted = [
schemaName: 'projectSettings',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
defaultPresets: {
point: cachedValues.defaultPresets.point,
Expand All @@ -93,6 +95,7 @@ export const goodDocsCompleted = [
schemaName: 'field',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
tagKey: 'otherTagKey',
type: 'number',
Expand All @@ -116,6 +119,7 @@ export const goodDocsCompleted = [
schemaName: 'preset',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
name: 'myPreset',
geometry: ['point', 'vertex', 'line'],
Expand All @@ -142,6 +146,7 @@ export const goodDocsCompleted = [
schemaName: 'role',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
roleId: '6fd029a78243',
fromIndex: 5,
Expand All @@ -155,6 +160,7 @@ export const goodDocsCompleted = [
schemaName: 'deviceInfo',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
name: 'my device name',
},
Expand All @@ -167,6 +173,7 @@ export const goodDocsCompleted = [
schemaName: 'coreOwnership',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
authCoreId: Buffer.from('authCoreId').toString('hex'),
configCoreId: Buffer.from('configCoreId').toString('hex'),
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/good-docs-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const goodDocsMinimal = [
schemaName: 'observation',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
refs: [],
attachments: [],
Expand All @@ -33,6 +34,7 @@ export const goodDocsMinimal = [
schemaName: 'projectSettings',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
},
expected: {},
Expand All @@ -44,6 +46,7 @@ export const goodDocsMinimal = [
schemaName: 'field',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
tagKey: 'myTagKey',
label: 'my label',
Expand All @@ -58,6 +61,7 @@ export const goodDocsMinimal = [
schemaName: 'preset',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
name: 'myPreset',
geometry: ['point'],
Expand All @@ -76,6 +80,7 @@ export const goodDocsMinimal = [
schemaName: 'role',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
roleId: '3b0104e370f9',
fromIndex: 5,
Expand All @@ -89,6 +94,7 @@ export const goodDocsMinimal = [
schemaName: 'deviceInfo',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
name: 'my device name',
},
Expand All @@ -101,6 +107,7 @@ export const goodDocsMinimal = [
schemaName: 'coreOwnership',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
authCoreId: Buffer.from('authCoreId').toString('hex'),
configCoreId: Buffer.from('configCoreId').toString('hex'),
Expand Down

0 comments on commit ed25c83

Please sign in to comment.