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

Fix: pass doc to data type delete #417

Closed
wants to merge 6 commits into from

Conversation

tomasciccola
Copy link
Contributor

we werent passing the original doc to delete, so when encoding the protobuf it would fail (since there were a bunch of missing fields)

Tomás Ciccola added 5 commits December 5, 2023 13:36
@tomasciccola tomasciccola requested a review from achou11 December 13, 2023 17:50
@tomasciccola tomasciccola self-assigned this Dec 13, 2023
*/
async delete(versionId) {
async delete(versionId, value) {
Copy link
Member

@achou11 achou11 Dec 13, 2023

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

Copy link
Contributor Author

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).

@tomasciccola tomasciccola mentioned this pull request Dec 13, 2023
3 tasks
@achou11
Copy link
Member

achou11 commented Dec 13, 2023

can you add a test for this? ideally one that failed prior to this but now passes with the change?

@tomasciccola tomasciccola changed the base branch from feat/importConfig to main December 13, 2023 19:08
@tomasciccola
Copy link
Contributor Author

I borked the branch when changing base, so here's the new PR #420 @achou11

@tomasciccola tomasciccola deleted the fix/passDocToDataTypeDelete branch December 14, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants