-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sanity): add exports for sanity/migrate + sanity/migrate/mutations
- Loading branch information
Showing
15 changed files
with
164 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
dev/test-studio/migrations/cleanup-empty/cleanup-empty-values.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
dev/test-studio/migrations/convert-string-to-pt/convert-string-to-pte.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# package specific | ||
# legacy package exports | ||
_internal.js | ||
cli.js | ||
desk.js | ||
form.js | ||
presentation.js | ||
router.js | ||
structure.js | ||
migrate.js | ||
/migrate/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '@sanity/migrate/mutations' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '@sanity/migrate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is here to support legacy bundlers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/sanity/src/_internal/cli/commands/migration/templates/clean-advanced.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const cleanAdvanced = ` | ||
import {mutations, defineMigration} from 'sanity/migrate' | ||
export default defineMigration({ | ||
name: '%migrationName%', | ||
documentType: '%type%', | ||
*migrate(documents) { | ||
for await (const document in documents) { | ||
yield mutations.createIfNotExists(document) | ||
} | ||
} | ||
}) | ||
` |
50 changes: 50 additions & 0 deletions
50
packages/sanity/src/_internal/cli/commands/migration/templates/clean-simple.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
export const cleanSimple = ` | ||
import {defineMigration} from 'sanity/migrate' | ||
export default defineMigration({ | ||
name: '%migrationName%', | ||
documentType: '%type%', | ||
migrate: { | ||
document(doc) { | ||
// this will be called for every document of the matching type | ||
// any patch returned will be applied to the document | ||
// you can also return mutations that touches other documents | ||
}, | ||
node(node, path, context) { | ||
// this will be called for every node in every document of the matching type | ||
// any patch returned will be applied to the document | ||
// you can also return mutations that touches other documents | ||
}, | ||
object(node, path, context) { | ||
// this will be called for every object node in every document of the matching type | ||
// any patch returned will be applied to the document | ||
// you can also return mutations that touches other documents | ||
}, | ||
array(node, path, context) { | ||
// this will be called for every array node in every document of the matching type | ||
// any patch returned will be applied to the document | ||
// you can also return mutations that touches other documents | ||
}, | ||
string(node, path, context) { | ||
// this will be called for every string node in every document of the matching type | ||
// any patch returned will be applied to the document | ||
// you can also return mutations that touches other documents | ||
}, | ||
number(node, path, context) { | ||
// this will be called for every number node in every document of the matching type | ||
// any patch returned will be applied to the document | ||
// you can also return mutations that touches other documents | ||
}, | ||
boolean(node, path, context) { | ||
// this will be called for every boolean node in every document of the matching type | ||
// any patch returned will be applied to the document | ||
// you can also return mutations that touches other documents | ||
}, | ||
null(node, path, context) { | ||
// this will be called for every null node in every document of the matching type | ||
// any patch returned will be applied to the document | ||
// you can also return mutations that touches other documents | ||
}, | ||
}, | ||
}) | ||
` |
16 changes: 6 additions & 10 deletions
16
packages/sanity/src/_internal/cli/commands/migration/templates/renameField.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
export const renameField = ` | ||
import {defineNodeMigration} from '@sanity/migrate' | ||
import {patch, at, set, unset} from '@sanity/migrate/mutations' | ||
import {mutations, defineMigration} from 'sanity/migrate' | ||
import {patch, at, set, unset} from 'sanity/migrate/mutations' | ||
export default defineNodeMigration({ | ||
export default defineMigration({ | ||
name: '%migrationName%', | ||
type: '%type%', | ||
document(doc) { | ||
return patch(doc._id, [ | ||
at('address', set(doc.location)), | ||
at('location', unset()) | ||
]) | ||
}, | ||
documentType: '%type%', | ||
migrate: { | ||
} | ||
}) | ||
` |
42 changes: 22 additions & 20 deletions
42
packages/sanity/src/_internal/cli/commands/migration/templates/stringToPTE.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
export const stringToPTE = ` | ||
import {defineNodeMigration} from '@sanity/migrate' | ||
import {patch, at, set, unset} from '@sanity/migrate/mutations' | ||
import {defineMigration} from 'sanity/migrate' | ||
import {patch, at, set, unset} from 'sanity/mutations' | ||
const targetPath = parsePath('%targetPath%') | ||
export default defineNodeMigration({ | ||
export default defineMigration({ | ||
name: '%migrationName%', | ||
type: '%type%', | ||
string(node, path, ctx) { | ||
if (isEqual(path, targetPath)) { | ||
return set([ | ||
{ | ||
style: 'normal', | ||
_type: 'block', | ||
children: [ | ||
{ | ||
_type: 'span', | ||
marks: [], | ||
text: node, | ||
}, | ||
], | ||
markDefs: [], | ||
}, | ||
]) | ||
} | ||
migrate: { | ||
string(node, path, ctx) { | ||
if (isEqual(path, targetPath)) { | ||
return set([ | ||
{ | ||
style: 'normal', | ||
_type: 'block', | ||
children: [ | ||
{ | ||
_type: 'span', | ||
marks: [], | ||
text: node, | ||
}, | ||
], | ||
markDefs: [], | ||
}, | ||
]) | ||
} | ||
}, | ||
}, | ||
}) | ||
` |