Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add optional deleted field to common (proto and schema) #138

Merged
merged 7 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
optional bool deleted = 6;
}
/* ignored fields and differences from common.json jsonSchema
* id is a byte buffer here and a string in jsonSchema
Expand Down
5 changes: 5 additions & 0 deletions schema/common/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
"items": {
"type": "string"
}
},
"deleted": {
"description": "Indicates whether the document has been deleted",
"type": "boolean",
"const": true
}
},
"required": [
Expand Down
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 || undefined,
}
}
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
19 changes: 19 additions & 0 deletions test/fixtures/bad-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const badDocs = [
schemaName: 'observOtion',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
refs: [],
attachments: [],
Expand All @@ -32,9 +33,27 @@ export const badDocs = [
schemaName: 'role',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
roleId: '',
fromIndex: 4,
},
},
{
text: 'doc with invalid value for `deleted` field',
doc: {
docId: cachedValues.docId,
versionId: cachedValues.versionId,
schemaName: 'observation',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
refs: [],
attachments: [],
tags: {},
metadata: {},
deleted: false,
},
},
]
Loading