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(migrate): use safe JSON parser when streaming from Export HTTP API #5542

Merged
merged 8 commits into from
Jan 24, 2024

Conversation

juice49
Copy link
Contributor

@juice49 juice49 commented Jan 22, 2024

Description

When streaming from the Export HTTP API, NDJSON lines may be interrupted by an error object. Handling for this scenario was already implemented in #1787, exclusively for the exporter CLI. I've moved the safe JSON parser to @sanity/util so that it can be used by both @sanity/export and @sanity/migrate.

What to review

  • Exporting datasets using the CLI works correctly.
  • Running migrations using the CLI works correctly.

Testing

Build the project, run the dataset export and migration run CLI commands.

I've added tests for the JSON parser:

yarn test packages/@sanity/util/test/createSafeJsonParser.test.ts

Copy link

vercel bot commented Jan 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Jan 24, 2024 1:19pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 24, 2024 1:19pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Jan 24, 2024 1:19pm

Copy link
Contributor

github-actions bot commented Jan 22, 2024

Package Documentation Change
sanity -3%
Full Report
@sanity/migrate
This branch Next branch
1 documented 0 documented
32 not documented 0 not documented
@sanity/diff
This branch Next branch
13 documented 13 documented
16 not documented 16 not documented
@sanity/block-tools
This branch Next branch
4 documented 4 documented
9 not documented 9 not documented
@sanity/types
This branch Next branch
55 documented 55 documented
239 not documented 239 not documented
sanity/desk
This branch Next branch
84 documented 84 documented
64 not documented 64 not documented
@sanity/portable-text-editor
This branch Next branch
21 documented 21 documented
44 not documented 44 not documented
@sanity/mutator
This branch Next branch
7 documented 7 documented
4 not documented 4 not documented
@sanity/cli
This branch Next branch
1 documented 1 documented
31 not documented 31 not documented
@sanity/schema/_internal
This branch Next branch
0 documented 0 documented
12 not documented 12 not documented
@sanity/util/paths
This branch Next branch
1 documented 1 documented
15 not documented 15 not documented
sanity/router
This branch Next branch
17 documented 17 documented
26 not documented 26 not documented
@sanity/util/legacyDateFormat
This branch Next branch
0 documented 0 documented
3 not documented 3 not documented
@sanity/schema
This branch Next branch
0 documented 0 documented
2 not documented 2 not documented
sanity/structure
This branch Next branch
2 documented 2 documented
6 not documented 6 not documented
sanity/cli
This branch Next branch
2 documented 2 documented
0 not documented 0 not documented
@sanity/vision
This branch Next branch
0 documented 0 documented
3 not documented 3 not documented
@sanity/util/fs
This branch Next branch
0 documented 0 documented
3 not documented 3 not documented
sanity/_internal
This branch Next branch
0 documented 0 documented
1 not documented 1 not documented
@sanity/util/createSafeJsonParser
This branch Next branch
1 documented 0 documented
0 not documented 0 not documented
sanity/_internalBrowser
This branch Next branch
0 documented 0 documented
3 not documented 3 not documented
@sanity/util/content
This branch Next branch
1 documented 1 documented
5 not documented 5 not documented
sanity
This branch Next branch
177 documented 183 documented
843 not documented 846 not documented

Copy link
Contributor

github-actions bot commented Jan 22, 2024

Component Testing Report Updated Jan 24, 2024 1:21 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 35s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 13s 3 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 13s 4 2 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 13s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 34s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 19s 9 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 0s 18 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 15s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 6s 3 0 0

@bjoerge bjoerge force-pushed the feat/migration-runner branch from c08e78f to f49ec7f Compare January 23, 2024 10:25
@juice49 juice49 force-pushed the feat/migration-runner-json-parser branch from be60eca to 547a495 Compare January 23, 2024 10:29
@juice49 juice49 marked this pull request as ready for review January 23, 2024 10:30
@juice49 juice49 requested a review from a team as a code owner January 23, 2024 10:30
@juice49 juice49 requested review from ricokahler, bjoerge and a team and removed request for a team and ricokahler January 23, 2024 10:30
@juice49 juice49 changed the title refactor(util): create shared JSON parser for @sanity/export and @sanity/migrate feat(migrate): use safe JSON parser when using Export HTTP API Jan 23, 2024
@juice49 juice49 changed the title feat(migrate): use safe JSON parser when using Export HTTP API feat(migrate): use safe JSON parser when streaming from Export HTTP API Jan 23, 2024
@bjoerge bjoerge force-pushed the feat/migration-runner branch from f49ec7f to 707d6b7 Compare January 23, 2024 10:35
@juice49 juice49 force-pushed the feat/migration-runner-json-parser branch from 547a495 to 1bfcda7 Compare January 23, 2024 10:35
@bjoerge bjoerge force-pushed the feat/migration-runner branch from 707d6b7 to cd86097 Compare January 23, 2024 11:49
@juice49 juice49 force-pushed the feat/migration-runner-json-parser branch from 1bfcda7 to e1b7e7e Compare January 23, 2024 12:06
@bjoerge bjoerge force-pushed the feat/migration-runner-json-parser branch from d39ee19 to 0517de5 Compare January 24, 2024 13:13
@bjoerge bjoerge merged commit c21e9e4 into feat/migration-runner Jan 24, 2024
18 of 22 checks passed
@bjoerge bjoerge deleted the feat/migration-runner-json-parser branch January 24, 2024 13:14
bjoerge pushed a commit that referenced this pull request Jan 26, 2024
…PI (#5542)

* refactor(util): create shared JSON parser for `@sanity/export` and `@sanity/migrate`

* feat(migrate): add safe JSON parser

* chore(util): update comment

* chore(export): update comment

* feat(migrate): use safe JSON parser when streaming from Export HTTP API

* feat(migrate): add JSON options and type parameter to NDJSON utility

* refactor(migrate): use type parameter

* fix(migrate): add missing export
binoy14 pushed a commit that referenced this pull request Jan 26, 2024
…PI (#5542)

* refactor(util): create shared JSON parser for `@sanity/export` and `@sanity/migrate`

* feat(migrate): add safe JSON parser

* chore(util): update comment

* chore(export): update comment

* feat(migrate): use safe JSON parser when streaming from Export HTTP API

* feat(migrate): add JSON options and type parameter to NDJSON utility

* refactor(migrate): use type parameter

* fix(migrate): add missing export
bjoerge pushed a commit that referenced this pull request Jan 26, 2024
…PI (#5542)

* refactor(util): create shared JSON parser for `@sanity/export` and `@sanity/migrate`

* feat(migrate): add safe JSON parser

* chore(util): update comment

* chore(export): update comment

* feat(migrate): use safe JSON parser when streaming from Export HTTP API

* feat(migrate): add JSON options and type parameter to NDJSON utility

* refactor(migrate): use type parameter

* fix(migrate): add missing export
bjoerge pushed a commit that referenced this pull request Jan 26, 2024
…PI (#5542)

* refactor(util): create shared JSON parser for `@sanity/export` and `@sanity/migrate`

* feat(migrate): add safe JSON parser

* chore(util): update comment

* chore(export): update comment

* feat(migrate): use safe JSON parser when streaming from Export HTTP API

* feat(migrate): add JSON options and type parameter to NDJSON utility

* refactor(migrate): use type parameter

* fix(migrate): add missing export
bjoerge pushed a commit that referenced this pull request Jan 29, 2024
…PI (#5542)

* refactor(util): create shared JSON parser for `@sanity/export` and `@sanity/migrate`

* feat(migrate): add safe JSON parser

* chore(util): update comment

* chore(export): update comment

* feat(migrate): use safe JSON parser when streaming from Export HTTP API

* feat(migrate): add JSON options and type parameter to NDJSON utility

* refactor(migrate): use type parameter

* fix(migrate): add missing export
bjoerge pushed a commit that referenced this pull request Jan 29, 2024
…PI (#5542)

* refactor(util): create shared JSON parser for `@sanity/export` and `@sanity/migrate`

* feat(migrate): add safe JSON parser

* chore(util): update comment

* chore(export): update comment

* feat(migrate): use safe JSON parser when streaming from Export HTTP API

* feat(migrate): add JSON options and type parameter to NDJSON utility

* refactor(migrate): use type parameter

* fix(migrate): add missing export
bjoerge pushed a commit that referenced this pull request Jan 29, 2024
…PI (#5542)

* refactor(util): create shared JSON parser for `@sanity/export` and `@sanity/migrate`

* feat(migrate): add safe JSON parser

* chore(util): update comment

* chore(export): update comment

* feat(migrate): use safe JSON parser when streaming from Export HTTP API

* feat(migrate): add JSON options and type parameter to NDJSON utility

* refactor(migrate): use type parameter

* fix(migrate): add missing export
bjoerge pushed a commit that referenced this pull request Jan 30, 2024
…PI (#5542)

* refactor(util): create shared JSON parser for `@sanity/export` and `@sanity/migrate`

* feat(migrate): add safe JSON parser

* chore(util): update comment

* chore(export): update comment

* feat(migrate): use safe JSON parser when streaming from Export HTTP API

* feat(migrate): add JSON options and type parameter to NDJSON utility

* refactor(migrate): use type parameter

* fix(migrate): add missing export
github-merge-queue bot pushed a commit that referenced this pull request Jan 30, 2024
* feat(migrate): move into monorepo from poc

* test(migrate): make sure uint8array-extras package gets transpiled from esm

* feat(cli): scaffold create/run migration cli commands

* fix(migrate): inline functions from uint8array-extras for now

Can't be imported from package because of ESM

* feat: basic migration cli support

* feat: basic `migrations list` command

* feat: migration create command w/templates

* feat(sanity): add exports for sanity/migrate + sanity/migrate/mutations

* chore(migrate): add test script

* test(migrate): add tests for `parseJSON`

* feat(migrate): add customisable parser and iterator type to `parseJSON`

* feat(migrate): add JSON parser that can handle chunks interrupted by an error object

* refactor(migrate): rename targets => destinations

* feat(migrate): use safe JSON parser when streaming from Export HTTP API (#5542)

* refactor(util): create shared JSON parser for `@sanity/export` and `@sanity/migrate`

* feat(migrate): add safe JSON parser

* chore(util): update comment

* chore(export): update comment

* feat(migrate): use safe JSON parser when streaming from Export HTTP API

* feat(migrate): add JSON options and type parameter to NDJSON utility

* refactor(migrate): use type parameter

* fix(migrate): add missing export

* fix(util): fix package.json formatting

* feat(migrate): implement mutation batcher and use when submitting against mutate endpoint

* feat(migrate): limit request concurrency

* fix(migrate): workaround issue with p-map and ESM

* feat(cli): allow user provided concurrency

* feat(migration): improve progress as migration is running (#5550)

* feat(migration): add a prompt before runing a real migration (#5552)

### Description

<!--
What changes are introduced?
Why are these changes introduced?
What issue(s) does this solve? (with link, if possible)
-->

Adds a prompt before running a real migration with the projectId and dataset so the user is aware and intentionally selects running a real migration

### What to review

<!--
What steps should the reviewer take in order to review?
What parts/flows of the application/packages/tooling is affected?
-->

`sanity migration run <name-of-migration> --dry=false` should show a prompt like "This migration will run on the “test” dataset in “yajkdsl” project. Are you sure?"

### Testing

<!--
Did you add sufficient testing for this change?
If not, please explain how you tested this change and why it was not
possible/practical for writing an automated test
-->

### Notes for release

<!--
A description of the change(s) that should be used in the release notes.
-->

- N/A

* feat(migration): support passing an array of documentTypes to migration (#5566)

* chore(migration): add better error message when request fails (#5567)

* chore(migration): add better error message when request fails

* fix(migration): add error message if json parsing fails

* feat(migrate): add asyncIterableToStream util

* feat(migrate): add bufferThroughFile utility

* fix(migrate): buffer exports through file

* fix(cli): use dryRun from @sanity/migrate

* refactor(migrate): rename function

* refactor(migrate): add ndjson support for both parsing and stringifying in ndjson util

* refactor(sanity): remove mutiny dependency in favor of inlined creators

* fix(sanity): add --no-progress flag

* fix(migrate): simplify bufferThroughFile

* feat(migrate): unify contexts, add support for document lookup and query during a migration

* fix(dev): fix example migration script imports

* feat(migration): support async hooks in migration nodes (#5564)

* fix(sanity): use --no-dry instead of --dry=false

* feat(migrate): add support for yielding transactions

* fix(migrate): minor typing issue

* fix(sanity): polish cli and migration templates

* chore(deps): remove unused deps

* fix(sanity): fix quoting of documentTypes in migration templates

* fix(sanity): rename migration name => title

* fix(migrate): run migration against all documents if documentTypes is omitted

* fix(migration): fixes dry run not showing any information

* fix(migration): show proper error message when the file has code issues

* fix(migrate): various naming consistency fixes

* fix(sanity): add a few examples to help text for 'sanity migration create'

* fix(sanity): improve error handling on 'sanity migration run' without id

* fix(migrate): fix error asserting transaction

* fix(migrate): use transactionId instead of id on mutation payload

* feat(cli): add pretty mutation formatting to migration runner (#5573)

* feat(cli): add pretty mutation formatting to migration runner

* feat(cli): improve formatting

* feat(cli): add indent option to `prettyFormatMutation`

* feat(cli): support indentation when printing JSON

* feat(cli): support migrations for multiple document types

* feat(cli): improve dry run migration formatting

* refactor(cli): abstract tree reporter

* chore(cli): remove unused import

* fix(cli): add missing closing parenthesis

* feat(cli): add migration dry-run output

* feat(cli): underline document id when pretty formatting mutation

* feat(cli): add transaction support to pretty formatter

* feat(cli): add transaction support to pretty mutation formatter

* refactor(cli): reduce complexity

* feat(cli): pretty format mutations when committing migration

* chore(migrate): instrument with some debug logging

* refactor(migration): move filtered document methods to a separate `filtered`-context key, add a client with limited concurrency to migration context

* fix(migrate): add request tags and user agent

* fix(sanity): improve minimal example

---------

Co-authored-by: Ash <[email protected]>
Co-authored-by: Binoy Patel <[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