-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix: pass doc to data type delete #417
Conversation
we werent passing the original doc to delete, so when encoding the protobuf it would fail (since there were a bunch of missing fields)
src/datatype/index.js
Outdated
*/ | ||
async delete(versionId) { | ||
async delete(versionId, value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't need to update the signature here (also this is prone to several issues around value integrity). Internally, this method should be getting the existing doc via getByVersionId()
and using that as the base value. Something along the lines of:
async delete(versionId) {
await this.#dataStore.indexer.idle()
const links = Array.isArray(versionId) ? versionId : [versionId]
const { docId, createdAt, createdBy } = await this.#validateLinks(links)
const existingDoc = await this.getByVersionId(links[links.length - 1])
/** @type {any} */
const doc = {
// Using valueOf is not strictly necessary, but makes it clearer that we're updating non-value fields in this new object
...valueOf(existingDoc),
docId,
createdAt,
updatedAt: new Date().toISOString(),
createdBy,
links,
schemaName: this.#schemaName,
deleted: true,
}
await this.#dataStore.write(doc)
return this.getByDocId(docId)
}
technically could update #validateLinks
to return the existing doc in its entirety to avoid doing repeat work, but not sure if i'd suggest that given that it mixes concerns a bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah getting the doc by versionId
makes sense (I was just passing the value to match dataType.update
).
can you add a test for this? ideally one that failed prior to this but now passes with the change? |
we werent passing the original doc to delete, so when encoding the protobuf it would fail (since there were a bunch of missing fields)