diff --git a/proto/common/v1.proto b/proto/common/v1.proto index 8a700ca7..5e085bef 100644 --- a/proto/common/v1.proto +++ b/proto/common/v1.proto @@ -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 diff --git a/schema/common/v1.json b/schema/common/v1.json index d86471d0..84e94e73 100644 --- a/schema/common/v1.json +++ b/schema/common/v1.json @@ -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", @@ -42,6 +46,7 @@ "schemaName", "updatedAt", "links", - "versionId" + "versionId", + "createdBy" ] } diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index 9bd50e65..52583d32 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -250,5 +250,6 @@ function convertCommon( links: common.links.map((link) => getVersionId(link)), createdAt: common.createdAt, updatedAt: common.updatedAt, + createdBy: common.createdBy.toString('hex'), } } diff --git a/src/lib/encode-converstions.ts b/src/lib/encode-converstions.ts index 15f85ad2..5f5ef2c7 100644 --- a/src/lib/encode-converstions.ts +++ b/src/lib/encode-converstions.ts @@ -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)), } } diff --git a/test/fixtures/cached.js b/test/fixtures/cached.js index 58c5b950..bd9fecee 100644 --- a/test/fixtures/cached.js +++ b/test/fixtures/cached.js @@ -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') }, diff --git a/test/fixtures/good-docs-completed.js b/test/fixtures/good-docs-completed.js index f48f1116..81df7e44 100644 --- a/test/fixtures/good-docs-completed.js +++ b/test/fixtures/good-docs-completed.js @@ -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, @@ -74,6 +75,7 @@ export const goodDocsCompleted = [ schemaName: 'projectSettings', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, + createdBy: cachedValues.createdBy, links: [], defaultPresets: { point: cachedValues.defaultPresets.point, @@ -93,6 +95,7 @@ export const goodDocsCompleted = [ schemaName: 'field', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, + createdBy: cachedValues.createdBy, links: [], tagKey: 'otherTagKey', type: 'number', @@ -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'], @@ -142,6 +146,7 @@ export const goodDocsCompleted = [ schemaName: 'role', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, + createdBy: cachedValues.createdBy, links: [], roleId: '6fd029a78243', fromIndex: 5, @@ -155,6 +160,7 @@ export const goodDocsCompleted = [ schemaName: 'deviceInfo', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, + createdBy: cachedValues.createdBy, links: [], name: 'my device name', }, @@ -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'), diff --git a/test/fixtures/good-docs-minimal.js b/test/fixtures/good-docs-minimal.js index 916ae0c3..1ea78da3 100644 --- a/test/fixtures/good-docs-minimal.js +++ b/test/fixtures/good-docs-minimal.js @@ -18,6 +18,7 @@ export const goodDocsMinimal = [ schemaName: 'observation', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, + createdBy: cachedValues.createdBy, links: [], refs: [], attachments: [], @@ -33,6 +34,7 @@ export const goodDocsMinimal = [ schemaName: 'projectSettings', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, + createdBy: cachedValues.createdBy, links: [], }, expected: {}, @@ -44,6 +46,7 @@ export const goodDocsMinimal = [ schemaName: 'field', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, + createdBy: cachedValues.createdBy, links: [], tagKey: 'myTagKey', label: 'my label', @@ -58,6 +61,7 @@ export const goodDocsMinimal = [ schemaName: 'preset', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, + createdBy: cachedValues.createdBy, links: [], name: 'myPreset', geometry: ['point'], @@ -76,6 +80,7 @@ export const goodDocsMinimal = [ schemaName: 'role', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, + createdBy: cachedValues.createdBy, links: [], roleId: '3b0104e370f9', fromIndex: 5, @@ -89,6 +94,7 @@ export const goodDocsMinimal = [ schemaName: 'deviceInfo', createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, + createdBy: cachedValues.createdBy, links: [], name: 'my device name', }, @@ -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'),