Skip to content

Commit

Permalink
fix(mutate): reflect support for providing transaction id in typings (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars authored Apr 3, 2023
1 parent f6f010a commit b7ad302
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/data/dataMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function _mutate<R extends Record<string, Any>>(
}

const muts = Array.isArray(mut) ? mut : [mut]
const transactionId = options && (options as Any).transactionId
const transactionId = (options && options.transactionId) || undefined
return _dataRequest(client, httpRequest, 'mutate', {mutations: muts, transactionId}, options)
}

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ export type BaseMutationOptions = RequestOptions & {
dryRun?: boolean
autoGenerateArrayKeys?: boolean
skipCrossDatasetReferenceValidation?: boolean
transactionId?: string
}

/** @internal */
Expand Down
18 changes: 18 additions & 0 deletions test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,24 @@ describe('client', async () => {
await expect(getClient().mutate(mutations, {tag: 'foobar'})).resolves.not.toThrow()
})

test.skipIf(isEdge)('mutate() accepts transaction id', async () => {
const mutations = [{delete: {id: 'abc123'}}]

nock(projectHost())
.post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true&visibility=sync', {
mutations,
transactionId: 'spec-ific',
})
.reply(200, {
transactionId: 'spec-ific',
results: [{id: 'abc123', operation: 'delete', document: {_id: 'abc123'}}],
})

await expect(
getClient().mutate(mutations, {transactionId: 'spec-ific'})
).resolves.not.toThrow()
})

test.skipIf(isEdge)('mutate() accepts `autoGenerateArrayKeys`', async () => {
const mutations = [
{
Expand Down

0 comments on commit b7ad302

Please sign in to comment.