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 createMigration and createWriteClient #350

Merged
merged 63 commits into from
Sep 23, 2024
Merged

Conversation

lihbr
Copy link
Member

@lihbr lihbr commented Aug 23, 2024

Implements: https://www.notion.so/prismic/RFC-Migration-API-Client-7365f2cce2ac43178955287dbad82e9c

Description

This Pull Request implements a new WriteClient allowing users to communicate with Prismic write APIs, namely the Migration API with ease, thanks to a helper Migration class working in concert with the new client.

Reworked structure

Reworked constructor

New types

New internal helpers

  • New internal helpers (lib) have been added to support the new WriteClient, namely patchMigrationDocumentData which contains all the crawling logic for correctly patching fields from a migration document with final field values and their updated IDs.

New exports

  • WriteClient has two exposed methods, migrate() and getAssets(), the other ones are kept private. It is exported alongside its factory createWriteClient
  • WriteClient's migrate() methods supports a reporter option reporting various events happening during the migration process. Thoses event types are exported as MigrateReporterEvents
  • Migration is exported alongside its factory createMigration
  • Migration document and field types are also exported.

Tests

Todos

Checklist

  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

How to QA 1

Use the following zip as a starting point: https://prismic-team.slack.com/files/U014KACFM6K/F07LY4GDLRE/migration-client-demo.zip

Following the README.md gives you a basic flow.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

Co-authored-by: Angelo Ashmore <angeloashmore@users.noreply.github.com>
@lihbr
Copy link
Member Author

lihbr commented Sep 10, 2024

Thank you so much for this first batch of reviews! I addressed them all and replied where necessary. Let's have a quick sync chat tonight to close some topics if you're available 👌

lihbr and others added 2 commits September 10, 2024 16:19
Co-authored-by: Angelo Ashmore <angeloashmore@users.noreply.github.com>
Copy link
Member

@angeloashmore angeloashmore left a comment

Choose a reason for hiding this comment

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

New comments for the tests! Addressing these comments are less important than the ones made on the implementation.

Comment on lines +47 to +49
alt: "foo",
credits: "bar",
notes: "baz",
Copy link
Member

Choose a reason for hiding this comment

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

⚠️ #issue: Should the test check for alt, credits, and notes? Otherwise, we don't know if the data was passed through.

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue I had here is that it's passed as a FormData so I cannot read it on the mocked API side unless we manage to upgrade MSW (out of scope here).

I'll add a TODO comment to rework this test when we update MSW.

test/writeClient-getAssets.test.ts Outdated Show resolved Hide resolved
test/writeClient-getAssets.test.ts Outdated Show resolved Hide resolved
test/writeClient-migrate.test.ts Outdated Show resolved Hide resolved
test/writeClient-migrateCreateAssets.test.ts Outdated Show resolved Hide resolved
test/writeClient-migrateCreateAssets.test.ts Outdated Show resolved Hide resolved
test/writeClient.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@angeloashmore angeloashmore left a comment

Choose a reason for hiding this comment

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

This is excellent. The latest version is simpler and might be less prone to bugs.

I left a few comments, none of which are blocking.

src/WriteClient.ts Show resolved Hide resolved
src/types/migration/Asset.ts Outdated Show resolved Hide resolved
src/Migration.ts Outdated Show resolved Hide resolved
src/lib/resolveMigrationDocumentData.ts Outdated Show resolved Hide resolved
@lihbr
Copy link
Member Author

lihbr commented Sep 18, 2024

Thank you so much! Addressed the last comments, should be good to go now 🎉

I'll hold off on merging until we're ready on the documentation end of things.

@lihbr lihbr merged commit 7dc2950 into master Sep 23, 2024
13 checks passed
@lihbr lihbr deleted the lh/migration-client branch September 23, 2024 14:56
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