Skip to content

Commit

Permalink
fix(migrate): fix error asserting transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Jan 30, 2024
1 parent 5d9a556 commit df310cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 1 addition & 2 deletions packages/@sanity/migrate/src/mutations/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function transaction(
const [id, mutations] =
typeof idOrMutations === 'string'
? [idOrMutations, _mutations as Mutation[]]
: [undefined, _mutations as Mutation[]]

: [undefined, idOrMutations as Mutation[]]
return {type: 'transaction', id, mutations}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function isRawMutation(
mutation: Transaction | Mutation | NodePatch | Operation | RawMutation,
): mutation is RawMutation {
return (
'mutations' in mutation ||
'createIfNotExists' in mutation ||
'createOrReplace' in mutation ||
'create' in mutation ||
Expand Down
15 changes: 9 additions & 6 deletions packages/@sanity/migrate/src/runner/utils/toSanityMutations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Mutation as SanityMutation} from '@sanity/client'
import {SanityEncoder} from '@bjoerge/mutiny'
import arrify from 'arrify'
import {Mutation, Transaction} from '../../mutations'
import {isTransaction} from '../../mutations/asserters'

Expand All @@ -12,13 +13,15 @@ export async function* toSanityMutations(
it: AsyncIterableIterator<Mutation | Transaction | (Mutation | Transaction)[]>,
): AsyncIterableIterator<SanityMutation[] | TransactionPayload> {
for await (const mutation of it) {
if (isTransaction(mutation)) {
yield {
id: mutation.id,
mutations: SanityEncoder.encode(mutation.mutations as any) as SanityMutation[],
for (const mut of arrify(mutation)) {
if (isTransaction(mut)) {
yield {
id: mut.id,
mutations: SanityEncoder.encode(mut.mutations as any) as SanityMutation[],
}
continue
}
continue
yield SanityEncoder.encode(mutation as any[]) as SanityMutation[]
}
yield SanityEncoder.encode(mutation as any[]) as SanityMutation[]
}
}

0 comments on commit df310cf

Please sign in to comment.