Skip to content

Commit

Permalink
feat: add createdBy field for all records (#142)
Browse files Browse the repository at this point in the history
Co-authored-by: Gregor MacLennan <gmaclennan@digital-democracy.org>
  • Loading branch information
achou11 and gmaclennan committed Sep 13, 2023
1 parent 050174c commit f1d4789
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": "discovery id (hex-encoded 32-byte buffer) of the hypercore where the first version of this document is written",
"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-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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: {
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 @@ -75,6 +76,7 @@ export const goodDocsCompleted = [
schemaName: 'projectSettings',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
defaultPresets: {
point: cachedValues.defaultPresets.point,
Expand All @@ -94,6 +96,7 @@ export const goodDocsCompleted = [
schemaName: 'field',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
tagKey: 'otherTagKey',
type: 'number',
Expand All @@ -117,6 +120,7 @@ export const goodDocsCompleted = [
schemaName: 'preset',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
name: 'myPreset',
geometry: ['point', 'vertex', 'line'],
Expand All @@ -143,6 +147,7 @@ export const goodDocsCompleted = [
schemaName: 'role',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
roleId: '6fd029a78243',
fromIndex: 5,
Expand All @@ -156,6 +161,7 @@ export const goodDocsCompleted = [
schemaName: 'deviceInfo',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
name: 'my device name',
},
Expand All @@ -168,6 +174,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 f1d4789

Please sign in to comment.