Skip to content

Commit

Permalink
feat: add optional deleted field to common (proto and schema) (#138)
Browse files Browse the repository at this point in the history
* feat: add optional `deleted` field to common (proto and schema)

* add description to common/deleted

* add tests for `deleted` field and {enc,dec} conversions

* make `deleted` required, fix tests

* test for `deleted: true`, add [require=true] to proto

---------

Co-authored-by: Tomás Ciccola <tciccola@digital-democracy.com>
  • Loading branch information
tomasciccola and Tomás Ciccola authored Sep 27, 2023
1 parent 73c6d15 commit 116db1a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions proto/common/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ message Common_1 {
google.protobuf.Timestamp updatedAt = 4 [(required) = true];
// 32-byte hash of the discovery key of a core
bytes createdBy = 5 [(required) = true];
bool deleted = 6 [(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 @@ -38,6 +38,10 @@
"items": {
"type": "string"
}
},
"deleted": {
"description": "Indicates whether the document has been deleted",
"type": "boolean"
}
},
"required": [
Expand All @@ -47,6 +51,7 @@
"updatedAt",
"links",
"versionId",
"createdBy"
"createdBy",
"deleted"
]
}
8 changes: 7 additions & 1 deletion src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export const convertObservation: ConvertFunction<'observation'> = (
...rest,
refs: message.refs?.map(({ id }) => ({ id: id.toString('hex') })),
attachments: message.attachments?.map(({ driveId, name, type, hash }) => {
return { driveId: driveId.toString('hex'), name, type, hash: hash.toString('hex') }
return {
driveId: driveId.toString('hex'),
name,
type,
hash: hash.toString('hex'),
}
}),
tags: convertTags(message.tags),
metadata: message.metadata || {},
Expand Down Expand Up @@ -251,5 +256,6 @@ function convertCommon(
createdAt: common.createdAt,
updatedAt: common.updatedAt,
createdBy: common.createdBy.toString('hex'),
deleted: common.deleted,
}
}
1 change: 1 addition & 0 deletions src/lib/encode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function convertCommon(
updatedAt: common.updatedAt,
createdBy: Buffer.from(common.createdBy, 'hex'),
links: common.links.map((link) => parseVersionId(link)),
deleted: common.deleted,
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/bad-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export const badDocs = [
schemaName: 'observOtion',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
refs: [],
attachments: [],
tags: {},
metadata: {},
deleted: false,
},
},
{
Expand All @@ -32,9 +34,11 @@ export const badDocs = [
schemaName: 'role',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
roleId: '',
fromIndex: 4,
deleted: false,
},
},
]
7 changes: 7 additions & 0 deletions test/fixtures/good-docs-completed.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const goodDocsCompleted = [
networkAvailable: false,
},
},
deleted: false,
},
expected: {},
},
Expand All @@ -86,6 +87,7 @@ export const goodDocsCompleted = [
relation: cachedValues.defaultPresets.point,
},
name: 'myProject',
deleted: false,
},
expected: {},
},
Expand All @@ -110,6 +112,7 @@ export const goodDocsCompleted = [
value: 'somePrimitiveTagValue',
},
],
deleted: false,
},
expected: {},
},
Expand Down Expand Up @@ -137,6 +140,7 @@ export const goodDocsCompleted = [
fieldIds: cachedValues.fieldIds,
iconId: cachedValues.iconId,
terms: ['imastring'],
deleted: false,
},
expected: {},
},
Expand All @@ -151,6 +155,7 @@ export const goodDocsCompleted = [
links: [],
roleId: '6fd029a78243',
fromIndex: 5,
deleted: false,
},
expected: {},
},
Expand All @@ -164,6 +169,7 @@ export const goodDocsCompleted = [
createdBy: cachedValues.createdBy,
links: [],
name: 'my device name',
deleted: true,
},
expected: {},
},
Expand All @@ -189,6 +195,7 @@ export const goodDocsCompleted = [
blobIndex: Buffer.from('blobIndex'),
},
identitySignature: Buffer.from('identity'),
deleted: true,
},
expected: {},
},
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 @@ -24,6 +24,7 @@ export const goodDocsMinimal = [
attachments: [],
tags: {},
metadata: {},
deleted: false,
},
expected: {},
},
Expand All @@ -36,6 +37,7 @@ export const goodDocsMinimal = [
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
deleted: false,
},
expected: {},
},
Expand All @@ -51,6 +53,7 @@ export const goodDocsMinimal = [
tagKey: 'myTagKey',
label: 'my label',
type: 'text',
deleted: false,
},
expected: {},
},
Expand All @@ -70,6 +73,7 @@ export const goodDocsMinimal = [
removeTags: {},
fieldIds: [],
terms: [],
deleted: false,
},
expected: {},
},
Expand All @@ -84,6 +88,7 @@ export const goodDocsMinimal = [
links: [],
roleId: '3b0104e370f9',
fromIndex: 5,
deleted: false,
},
expected: {},
},
Expand All @@ -97,6 +102,7 @@ export const goodDocsMinimal = [
createdBy: cachedValues.createdBy,
links: [],
name: 'my device name',
deleted: false,
},
expected: {},
},
Expand All @@ -122,6 +128,7 @@ export const goodDocsMinimal = [
blobIndex: Buffer.from('blobIndex'),
},
identitySignature: Buffer.from('identity'),
deleted: true,
},
expected: {},
},
Expand Down

0 comments on commit 116db1a

Please sign in to comment.