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!: replace createdBy with originalVersionId #191

Merged
merged 5 commits into from
Aug 24, 2024
Merged

Conversation

EvanHahn
Copy link
Contributor

See digidem/comapeo-core#371 for details.

EvanHahn referenced this pull request in digidem/comapeo-core Jul 10, 2024
This patch:

- Removes `createdBy` from documents. Removes
  `MapeoProject.prototype.$createdByToDeviceId` as a side-effect.

- Returns `originalVersionId` on all documents.

Closes <#371>. Depends
on <https://github.com/digidem/mapeo-schema/pull/191> and
<digidem/mapeo-mock-data#7>.
@EvanHahn EvanHahn marked this pull request as ready for review July 10, 2024 20:03
@EvanHahn EvanHahn requested a review from gmaclennan July 10, 2024 20:03
Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I think we should encode this like we do the versionIds for Links. Also some questions about the typing of docs with originalVersionId and making sure we're not loosing type safety, particularly on writes.

proto/common/v1.proto Outdated Show resolved Hide resolved
@@ -51,7 +51,7 @@
"updatedAt",
"links",
"versionId",
"createdBy",
"originalVersionId",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does get confusing, because is this required or not? It seems from digidem/comapeo-core#715 that we are not storing this on creation, so reads will not include this/

Trying to fully represent the type in JSONSchema might be difficult, it might be easier to do in the TypeScript defs in this repo, maybe something like:

type CommonNew = (Omit<Common, 'links' | 'originalVersionId'> & { links: [] }) | SetRequired<Common, 'originalVersionId'>

e.g. you originalVersionId can be missing if link is an empty array, but otherwise it is required.

src/encode.ts Outdated Show resolved Hide resolved
Comment on lines 349 to 359
const versionId = getVersionId(versionObj)

/** @type {string} */ let originalVersionId
if (common.originalVersionId) {
originalVersionId = common.originalVersionId
} else if (common.links.length === 0) {
originalVersionId = versionId
} else {
throw new Error('Cannot determine original version ID; data is malformed')
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see re. my comment above about it being required in JSON Schema is maybe ok given you are always appending it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But maybe the encode function could benefit from the stricter typing and this same check when writing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I addressed this in d1b0975.

@@ -28,7 +29,7 @@ import {
* schema name, and returning the most recent JSONSchema type */
type ConvertFunction<TSchemaName extends SchemaName> = (
mapeoDoc: Extract<
OmitUnion<MapeoDocInternal, 'versionId'>,
OmitUnion<MapeoDocInternal, 'versionId' | 'originalVersionId'>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're loosing some type safety where you are doing this, but it's late so maybe I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I did this in d1b0975, but maybe you were imagining something else.

@EvanHahn EvanHahn requested a review from gmaclennan August 15, 2024 14:48
Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to merge.

@EvanHahn EvanHahn merged commit 1f239c9 into main Aug 24, 2024
6 checks passed
@EvanHahn EvanHahn deleted the originalVersionId branch August 24, 2024 15:47
EvanHahn referenced this pull request in digidem/comapeo-core Aug 27, 2024
This patch:

- Removes `createdBy` from documents. Removes
  `MapeoProject.prototype.$createdByToDeviceId` as a side-effect.

- Returns `originalVersionId` on all documents.

- Updates `@mapeo/schema` to the latest version, which requires a bunch
  of other changes.

Closes [#371](#371).

See <https://github.com/digidem/mapeo-schema/pull/191> and
<digidem/mapeo-mock-data#7>.

Co-Authored-By: Tomás Ciccola <[email protected]>
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